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
126
votes
10 answers

Center NSTextAttachment image next to single line UILabel

I'd like to append an NSTextAttachment image to my attributed string and have it centered vertically. I've used the following code to create my string: NSMutableAttributedString *str = [[NSMutableAttributedString alloc]…
Sean Danzeiser
  • 8,731
  • 12
  • 49
  • 84
33
votes
7 answers

How to set color of templated image in NSTextAttachment

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…
Ghazgkull
  • 934
  • 1
  • 6
  • 15
29
votes
5 answers

how to resize an image or done as a NSAttributedString NSTextAttachment (or set its initital size)

I have a NSAttributedString to which I am adding a NSTextAttachment. The image is 50w by 50h but I'd like it to scale down to reflect the line height of the attributed string. I thought this would be done automatically but I guess not. I have looked…
timpone
  • 17,029
  • 31
  • 103
  • 200
20
votes
1 answer

In a UILabel, is it possible to force a line NOT to break in a certain place

I have a UILabel that is supposed to be two lines long. The text is localized into French and English. I'm setting the attributedText property of the label. The text is constructed from three appended strings, say textFragment1, textFragment2 and…
Darren
  • 9,855
  • 18
  • 60
  • 106
20
votes
4 answers

Lines missing from tall UILabel when embedding NSTextAttachment

I can create a multi-line NSAttributedString by using escaped new-line characters (@"\n"). With iOS 7, I can now embed a UIImage inside attributed strings (via NSTextAttachment). I have noticed that whenever I set the attributedText of a UILabel to…
oo-di-lolly
  • 213
  • 3
  • 6
17
votes
7 answers

How to detect touch on NSTextAttachment

What is the best way to detect when user taps on NSTextAttachment on iOS? I think that one of the ways would be checking for the character on carret's position whether it is NSAttachmentCharacter, but it just doesn't seem right. I've also tried…
Michał Zygar
  • 3,974
  • 20
  • 35
14
votes
4 answers

How do I insert an image Inline UILabel in iOS 8 using swift

I followed the following post on how to use NSTextAttachment to add images inline with your UILabels. I followed the best I could and wrote my version in Swift. I am creating a chat application and the field that I'm inserting a beer icon into does…
mattwallace
  • 3,687
  • 4
  • 35
  • 69
13
votes
2 answers

How to subclass NSTextAttachment?

Here is my problem: I use Core Data to store rich text input from iOS and/or OS X apps and would like images pasted into the NSTextView or UITextView to: a) retain their original resolution, and b) on display to be scaled to fit the textView…
Duncan Groenewald
  • 6,956
  • 4
  • 31
  • 59
11
votes
2 answers

Spacing around NSTextAttachment

How do I make spacing around NSTextAttachments like in the example below? In the example No spacing is the default behaviour I get when I append a NSTextAttachment to a NSAttributedString.
10
votes
1 answer

How to disable interaction on NSTextAttachment?

In a UITextView with editable = YES and selectable = NO, I want to disable interaction on NSTextAttachments. To be more specific, I don't want long presses on NSTextAttachments to highlight the attachment images. I want these long press gestures to…
an0
  • 16,371
  • 11
  • 78
  • 132
9
votes
1 answer

Update image of NSTextAttachment once already rendered

I have an NSTextAttachment which I want to show a loading image until the image has downloaded and then once it has I want to update the image. I have all of the logic in place, except when I call textAttachment.image = image the second time nothing…
Jason Silberman
  • 2,352
  • 6
  • 26
  • 45
9
votes
3 answers

NSTextAttachment image alignment

I am following this cool tutorial Implementing Rich Text with Images on OS X and iOS by @Duncan Groenewald and was able to display images in my UITextView. However, these images are not centered they way I would like them to be. See image As you…
unspokenblabber
  • 1,537
  • 1
  • 11
  • 18
9
votes
3 answers

Redrawing NSTextAttachments in an UITextView with attributed text

I have a NSTextAttachment subclass with overridden attachmentBoundsForTextContainer:proposedLineFragment:glyphPosition:characterIndex: imageForBounds:textContainer:characterIndex:. I need to redraw the attachment(s) at some point. Calling…
unexpectedvalue
  • 6,019
  • 3
  • 35
  • 62
9
votes
1 answer

Position of NSTextAttachment inside UILabel?

I have a UILabel displaying an NSAttributedString. The string contains text and a UIImage as a NSTextAttachment. When rendered, is there a way to get the position of the NSTextAttachment in the UILabel? Edit Here is the end result I am trying to…
rdougan
  • 7,119
  • 2
  • 32
  • 61
9
votes
2 answers

Add attachment image to attributed string in iOS 6

I have spent 3 hours on this but just can't solve it, anybody knows why? please help me! The code below added an image as an attachment to an attributed string, UIImage *img = [UIImage imageNamed:imgName]; NSTextAttachment *textAttachment =…
Fuli
  • 263
  • 2
  • 4
  • 11
1
2 3
8 9