- (void)insertImage:(UIImage *)image{
if (!image) {
return ;
}
self.editing = YES;
CGFloat width = image.size.width;
CGFloat height = image.size.height;
if (width > SCREEN_WIDTH - TextPaddingSpace*2 - 10) {
width = SCREEN_WIDTH - TextPaddingSpace*2 - 10;
height = height * width / image.size.width;
}
NSAttributedString* tmpAttributedString = [NSAttributedString rz_colorfulConfer:^(RZColorfulConferrer *confer) {
confer.text(@"\n").font(rz_font(TaskRichFont));
confer.appendImage(image).size(CGSizeMake(width, height),RZHorizontalAlignBottom, [UIFont systemFontOfSize:TaskRichFont]).paragraphStyle.alignment(NSTextAlignmentCenter);
confer.text(@"\n").font(rz_font(TaskRichFont)).textColor(kUIColorFromRGB(0x333333, 1.0)).paragraphStyle.alignment(NSTextAlignmentLeft);
//confer.text(@"\n").font(rz_font(TaskRichFont)).textColor(kUIColorFromRGB(0x333333, 1.0)).paragraphStyle.alignment(NSTextAlignmentLeft);
}];
NSMutableAttributedString * imageAttributrdString = tmpAttributedString.mutableCopy;
// NSMutableDictionary *tempAttrDict = [self rz_attributesAtSelectedRange].mutableCopy; // 只有在手动改变range时,才会去重置到当前的属性
// tempAttrDict[NSAttachmentAttributeName] = nil; // 如果有图片,则删除,否则图片会覆盖当前插入的图片
// if (tempAttrDict) {
// [imageAttributrdString addAttributes:tempAttrDict range:NSMakeRange(0, imageAttributrdString.length)];
// }
NSMutableAttributedString *attr = self.attributedText.mutableCopy;
NSRange selectedRange = self.selectedRange;
[attr replaceCharactersInRange:selectedRange withAttributedString:imageAttributrdString];
self.attributedText = attr;
self.selectedRange = NSMakeRange(selectedRange.location + imageAttributrdString.length, 0);
// [self becomeFirstResponder];
// [self textViewDidChange:self];
}
我这样插入图片之后,光标会停留在居中的位置,我怎么才可以,在插完图片后,光标停留在最左边,
请你在我看一下,谢谢
------------------ 原始邮件 ------------------
发件人: "rztime"
发送时间: 2020年2月21日(星期五) 上午10:11
收件人: "rztime/RZRichTextView"
抄送: "海阔天空"<1350587807@qq.com>; "Author"
主题: Re: [rztime/RZRichTextView] 解析html,后,如何设置 图片的尺寸大小 iOS (#13)
在文字改变(rz_didChangedText)之后,在去修改其属性,记得刷新工具条
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.