草庐IT

nstextattachment

全部标签

ios - 如何检测 UITextView 中的图像删除

如果我像这样将图像添加到UITextView中:NSTextAttachment*textAttachment=[[NSTextAttachmentalloc]init];textAttachment.image=image;NSAttributedString*attrStringWithImage=[NSAttributedStringattributedStringWithAttachment:textAttachment];[myStringappendAttributedString:attrStringWithImage];self.inputTextView.attrib

ios - ([NSAttributedString boundingRectWithSize :options:context:])method can not get the right size within NSTextAttachment

在我的代码中:NSMutableAttributedString*str=[[NSMutableAttributedStringalloc]initWithString:@"12123"];NSTextAttachment*attachment=[[NSTextAttachmentalloc]init];attachment.image=[UIImageimageNamed:@"002"];attachment.bounds=CGRectMake(0,0,20,20);[strinsertAttributedString:[NSAttributedStringattributedStr

ios - 使用属性文本在 UITextView 中重绘 NSTextAttachments

我有一个NSTextAttachment子类,它被覆盖了attachmentBoundsForTextContainer:proposedLineFragment:glyphPosition:characterIndex:imageForBounds:textContainer:characterIndex:。我需要在某个时候重新绘制附件。在UITextView上调用setNeedsDisplay无效。有什么想法吗?我想避免重新创建附件和/或属性字符串。 最佳答案 您需要使用textView.layoutManager的方法之一。i

ios - 如何禁用 NSTextAttachment 上的交互?

在editable=YES和selectable=NO的UITextView中,我想禁用NSTextAttachments上的交互。更具体地说,我不想长按NSTextAttachments来突出显示附件图像。我希望将这些长按手势作为普通文本选择手势传递给UITextView。我尝试过的:textView:shouldInteractWithTextAttachment:inRange:可以阻止操作表但不能阻止附件图像的临时高亮,也不能使这些长按作为文本选择手势处理。 最佳答案 UITextView有几个已安装的手势识别器。有一个是U

ios - 通过 NSAttributedStringKey 的附件不可见

可以通过largeTitleTextAttributes自定义新的大标题功能,(与任何其他属性一样)dictionarywithNSAttributedStringKey键。其中一个键是NSAttachmentAttributeName/attachment。考虑一下:letattachment=NSTextAttachment()attachment.image=UIImage(named:"foo")attachment.bounds=CGRect(x:0.0,y:0.0,width:20.0,height:20.0)varlargeTitleTextAttributes:[NSA

ios - TextView不显示文字

我用TextView显示照片,一切正常,但为什么在iPhone上,加上版本不显示带照片的文字,谁知道是什么原因?overridefuncviewDidLoad(){super.viewDidLoad()textView.attributedText=detail?.text?.html2AttributedStringtextView.attributedText.correctimage(textView:text,SV:view)}下载照片并处理html文本extensionString{varhtml2AttributedString:NSAttributedString?{do

ios - 如何检测 NSAttributedString 是否包含 NSTextAttachment 并将其删除?

我收到一个NSAttributedString作为输入,其中可能包含作为NSTextAttachment附加的图像。我需要检查是否确实附加了这样的图像,在这种情况下,将其删除。我一直在寻找相关帖子但没有成功,我该怎么做?编辑:我正在尝试:letmutableAttrStr=NSMutableAttributedString(attributedString:textView.attributedText)textView.attributedText.enumerateAttribute(NSAttachmentAttributeName,in:NSMakeRange(0,textVi

ios - 将嵌入 NSAttributedString(通过 NSTextAttachment)的图像视为单个字符,这样它就不会断行?

我在NSAttributedString中嵌入了一张图片,我希望iOS将它视为一个字符,该字符是它前面的单词的一部分,这样它就不会断成一行。我在某处读到应该是默认行为的地方,但对于我的生活我无法让它工作。这是我的代码(我插入这个属性字符串作为按钮的标题):vartitle="Thisisanexamplestring.Testtesttt"lettitleTextString=NSMutableAttributedString(string:title)letimageAttachment=NSTextAttachment()imageAttachment.image=UIImage(

cocoa-touch - 设置属性后 NSTextAttachment 图片消失

我在将属性应用于NSMutableAttributedString时遇到问题。如果他们有图像附件,则在添加属性时图像会消失。取一个包含文本附件的NSMutableAttributedString,如下所示:letmyString=NSMutableAttributedString(string:"Hello\n\n")letattachment=NSTextAttachment()attachment.image=image//someUIImageletattachmentString=NSAttributedString(attachment:attachment)myString

ios - 在 UILabel 中,是否可以强制一条线在某个地方不中断

我有一个应该有两行长的UILabel。文本已本地化为法语和英语。我正在设置标签的attributedText属性。文本由三个附加字符串构成,例如textFragment1、textFragment2和textFragment3。中间的字符串实际上是使用NSTextAttachment创建的图像。我想确保textFragment2和textFragment3在同一行。第一个字符串可能会也可能不会换行,具体取决于它的长度。问题是我的法语文本目前相当短,所以该行在textFragment2之后换行。我已通过在textFragment1的本地化法语文本中添加换行符来临时解决此问题。不过,我并不