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

135 questions
4
votes
1 answer

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

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…
AppsDev
  • 11,441
  • 20
  • 81
  • 163
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

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,477
  • 14
  • 23
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
  • 5,965
  • 1
  • 37
  • 77
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,091
  • 1
  • 14
  • 25
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
  • 91
  • 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
2 answers

Detect Tap On Image's Attached In NSAttributedString While UITextVIew Editing Is True

I'm using Below method for detecting taps on image in UITextView. `func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool` This method…
ZAFAR007
  • 2,545
  • 1
  • 26
  • 40
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
  • 333
  • 3
  • 20
3
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…
3
votes
1 answer

Add Carousel View inside Textview

I am adding data into TextView through sqlite database. I have around 30 to 35 images to be added in it after some Para or Line of data, which i have done through NSTextAttachment. Now what i want to do is wherever there are more that 2 images i…
iDeveloper
  • 740
  • 8
  • 42
3
votes
1 answer

Split NSAttributedString into Image + NSString

I have an NSAttributedString that can contain 3 different things : Just an image. (an attachment) Just Text An image followed by text (/!\ not the other way around, never). I'm trying to "scan" that object to know if I have an image or text, and…
Gil Sand
  • 5,333
  • 3
  • 29
  • 66
3
votes
0 answers

Clickable events in NSAttributedString in ios

i had inserted UIimage inside uitextview as NSTextAttachment using nsattributedstring. Now because of some default property for attrbutestring i am getting long press event on my image. i.e When i do long press in UIImage it got UIActionsheet giving…
ios developer
  • 3,057
  • 2
  • 43
  • 93
1 2
3
8 9