nstextattachment

Saving NSAttributedString with NSTextAttachment into file. How to?

人盡茶涼 提交于 2019-12-09 07:14:28
问题 I have a NSTextView , which may contains rich text or rich text with image as NSTextAttachment . There is how I adds attachment: NSImage *image = [NSImage imageNamed:@"image"]; NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image]; NSTextAttachment *attachment =[[NSTextAttachment alloc] init]; [attachment setAttachmentCell: attachmentCell ]; NSAttributedString *attributedString =[NSAttributedString attributedStringWithAttachment: attachment]; [[aTextView

TextKit: How is the editor placeholder feature implemented in Xcode?

时间秒杀一切 提交于 2019-12-09 07:03:34
问题 I took a deep dive into TextKit and wondered how the editor placeholders are implemented in the Xcode code editor: You can also try this yourself and type something along the lines of: <#Hello#> , which automatically turns into a placeholder. The Xcode editor is built with TextKit. After some research I came up with two possible strategies: Using NSTextAttachment : as soon as a string matching the placeholder pattern <#...#> is detected, that string is removed and replaced by a

iOS 7 UITextView: Size of nstextattachment getting 2x after reopening the application

白昼怎懂夜的黑 提交于 2019-12-05 05:15:43
I am building a note editor using the Text Kit in ios7. Earlier I had trouble in rendering of custom size NSTextAttachment's as it was slowing down the rendering to a great extent.I solved the issue by scaling the images and then adding them to textview.You can find my answer in iOS 7.0 UITextView gettings terribly slow after adding images to it After scaling the images the textview rendering runs fine without any lag.The attributed text of textview is stored in core data.During a running session of application the textview displays the images correctly.Even after saving the attributed text in

How to detect if a NSAttributedString contains a NSTextAttachment and remove it?

。_饼干妹妹 提交于 2019-12-05 02:10:24
问题 I receive as an input a NSAttributedString that may contain an image attached as NSTextAttachment . I need to check if actually such image is attached and, in such case, remove it. I've been looking for related posts with no success, how could I do this? EDIT: I'm trying this: let mutableAttrStr = NSMutableAttributedString(attributedString: textView.attributedText) textView.attributedText.enumerateAttribute(NSAttachmentAttributeName, in: NSMakeRange(0, textView.attributedText.length), options

How to set color of templated image in NSTextAttachment

大兔子大兔子 提交于 2019-12-04 15:26:46
问题 How can I set the color of a templated image that is an attachment on an attributed string? Background: I've got a UILabel and I'm setting its attributedText to an NSAttributedString. The NSAttributedString includes an NSTextAttachment with a small image. Now I want to make my image color match the text color and I can't figure out how to make it work. I would normally expect to color the image by setting its rendering mode to UIImageRenderingModeAlwaysTemplate and then setting the tintColor

How to detect if a NSAttributedString contains a NSTextAttachment and remove it?

五迷三道 提交于 2019-12-03 17:14:48
I receive as an input a NSAttributedString that may contain an image attached as NSTextAttachment . I need to check if actually such image is attached and, in such case, remove it. I've been looking for related posts with no success, how could I do this? EDIT: I'm trying this: let mutableAttrStr = NSMutableAttributedString(attributedString: textView.attributedText) textView.attributedText.enumerateAttribute(NSAttachmentAttributeName, in: NSMakeRange(0, textView.attributedText.length), options: NSAttributedString.EnumerationOptions(rawValue: 0)) { (value, range, stop) in if (value as?

trouble saving NSAttributedString, with image, to an RTF file

微笑、不失礼 提交于 2019-12-03 10:05:47
问题 I have some output that is a very simple RTF file. When I generate this document, the user can email it. All this works fine. The document looks good. Once I have the NSAttributedString, I make an NSData block, and write it to a file, like this: NSData* rtfData = [attrString dataFromRange:NSMakeRange(0, [attrString length]) documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType} error:&error]; This file can be emailed. When I check the email all is good. Now, I'm tasked

How to set color of templated image in NSTextAttachment

五迷三道 提交于 2019-12-03 09:37:05
How can I set the color of a templated image that is an attachment on an attributed string? Background: I've got a UILabel and I'm setting its attributedText to an NSAttributedString. The NSAttributedString includes an NSTextAttachment with a small image. Now I want to make my image color match the text color and I can't figure out how to make it work. I would normally expect to color the image by setting its rendering mode to UIImageRenderingModeAlwaysTemplate and then setting the tintColor on the containing UIView. I've tried setting the tintColor on my UILabel but that has no effect. Here's

Saving NSAttributedString with NSTextAttachment into file. How to?

不羁的心 提交于 2019-12-03 08:27:17
I have a NSTextView , which may contains rich text or rich text with image as NSTextAttachment . There is how I adds attachment: NSImage *image = [NSImage imageNamed:@"image"]; NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image]; NSTextAttachment *attachment =[[NSTextAttachment alloc] init]; [attachment setAttachmentCell: attachmentCell ]; NSAttributedString *attributedString =[NSAttributedString attributedStringWithAttachment: attachment]; [[aTextView textStorage] beginEditing]; if ([aTextView shouldChangeTextInRange:NSMakeRange([aTextView selectedRange]

Delete / Remove NSTextAttachment from UITextView

老子叫甜甜 提交于 2019-12-02 20:04:43
问题 I have a UITextView that will have a mixture of images (as NSTextAttachment ) and character strings. The UITextView is NOT selectable, so I can use: - (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange How do I delete the textAttachment in the method? 回答1: You can use replaceCharactersInRange:withString: of NSMutableAttributedString to remove the attachement (you got the range as parameter of the