Questions tagged [nstextattachment]

NSTextAttachment class is used for embedding images into attributed strings(NSAttributedString). Supported by iOS 7.0+, masOS 10.10+, tvOS 9.0+ and watchOS 2.0+

NSTextAttachmentobjects contain either anNSData object or anFileWrapper object, which in turn holds the contents of the attached file.

Docs: NSTextAttachment reference

141 questions
5
votes
2 answers

trouble saving NSAttributedString, with image, to an RTF file

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…
Dan Morrow
  • 4,433
  • 2
  • 31
  • 45
5
votes
0 answers

Animate NSTextAttachment

Is it possible to animate a NSTextAttachment in a UITextView? I tried modifying its bounds but it doesn't seem to produce any effect. NSAttributedString *attributedText = self.textView.attributedText; NSTextAttachment *textAttachment =…
hpique
  • 119,096
  • 131
  • 338
  • 476
4
votes
0 answers

Update attributedText on a dequeued cell UITextView make the app freeze

I'm currently stuck down a big wall... I'm using custom UITableViewCell containing UITextView containing custom NSTextAttachment images. Each NSTextAttachment overrides the - (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer…
4
votes
1 answer

How do you remove and replace an NSTextAttachment in an NSAttributedString

I have a mutable attributed string which I have added an image text attachment to. NSMutableAttributedString* attributedString = [_textField.attributedText mutableCopy]; NSMutableDictionary* dict =…
4
votes
1 answer

What kind of NSData can a UITextView display from an NSTextAttachment?

I've successfully been using NSTextAttachments in a UITextView for some time, however only ever using the image property, like so: NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil]; attachment.image = [UIImage…
4
votes
1 answer

iOS NSTextAttachment image not showing

NSTextAttachment lock image cut off at the edge but when the line does not breaks at the edge then the lock icon can be seen. I want the icon to move to the next line like a word move to the next line. Here are the example: NSTextAttachment…
shoujo_sm
  • 3,173
  • 4
  • 37
  • 60
4
votes
1 answer

Get frame of NSTextAttachmentCell in NSTextView

I have an NSTextView with images in it. I want to add tracking areas for those images. I need the frame of the cells holding the images in order to create tracking areas. So my question: how can I get the frame for the NSTextAttachments in the…
regulus6633
  • 18,848
  • 5
  • 41
  • 49
4
votes
1 answer

Saving NSAttributedString with NSTextAttachment into file. How to?

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]…
Akki
  • 1,487
  • 14
  • 25
3
votes
1 answer

NSTextAttachment image in attributed text with foreground colour

When I add an image attachment to an UITextView with a foreground colour set, the image is blanked out with the set colour: let attrString = NSMutableAttributedString(string: rawText, attributes: [.font: UIFont.systemFont(ofSize: 17),…
Fried Rice
  • 3,295
  • 3
  • 18
  • 27
3
votes
0 answers

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

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…
Mark
  • 6,647
  • 1
  • 45
  • 88
3
votes
0 answers

NSAttributedString drawRect doesn't draw images on-screen on Mojave

I have a working app that draws NSAttributedStrings into a custom view. The NSAttributedStrings can included embedded images. This works on versions of macOS prior to Mojave. The app can display the strings on screen, print them, and save them to…
3
votes
0 answers

Store and retrieve NSAttributed string with NSTextAttachment to/from Pasteboard

I have NSAttributedString with NSTextAttachment. I've created subclass of NSTextAttachment (with implemented encode/decode methods) and it has property attachedView so I can put any view as NSAttachment into attributed string. The problem that I…
landonandrey
  • 1,271
  • 1
  • 16
  • 26
3
votes
0 answers

Strange behaviour of UITextField / cursor with NSTextAttachment

I have quite straightforward code to add NSTextAttachment to UITextView: override func viewDidLoad() { super.viewDidLoad() //textView.textDragInteraction?.isEnabled = false textView.becomeFirstResponder() textView.isEditable = true …
wiskis
  • 131
  • 1
  • 2
  • 5
3
votes
0 answers

Making an image as a bullet in each new line in textview

I'm trying to make sth similar to bullet list in TextView but instead of bullets I have an image. The problem is that when I create the new line by normal "\n " sign the space before the image in the line is editable. And I want to make that image…
3
votes
1 answer

TextView does not display text

I use TextView to display a photo, everything works fine, but why, on iPhone, plus the version does not display text with photos, who knows what could be the reason? override func viewDidLoad() { super.viewDidLoad() …
Vasya2014
  • 203
  • 1
  • 5
  • 25
1 2
3
9 10