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
8
votes
3 answers

Setting vertical align of truncated tails for NSAttributedString with NSTextAttachment

I'm using the following code to generate a NSAttributedString for UILabel in iOS 8. // a long long Chinese title NSString *title = @"这是一个很长很长很长很长很长很长的中文标题"; // setup icon attachment NSTextAttachment *iconAttachment = [[NSTextAttachment alloc]…
xi.lin
  • 3,049
  • 2
  • 26
  • 49
8
votes
2 answers

NSAttributedString with image attachment and NSTextTab, text not aligned

I'm trying to have a UIlabel with an image and title on the left and a list of descriptions with bullets on the right, to do that I'm using NSAttributedString like this : NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc]…
Mosbah
  • 1,442
  • 1
  • 13
  • 27
7
votes
2 answers

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

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…
nick28
  • 134
  • 2
  • 7
6
votes
1 answer

NSTextAttachmentCell is a mile high

I'm editing a subset of HTML in an NSTextView[1] and I want to simulate an
tag. I've figured out that the way to do it is with NSTextAttachment and a custom NSTextAttachmentCell, and have the code all written to insert the attachment and cell. …
Brent Royal-Gordon
  • 16,531
  • 6
  • 53
  • 86
6
votes
1 answer

Get mouse clicks on NSTokenField

I would like to implement a NSTokenField that will show Tokens that - when hovering over the token - show a removal icon. Subsequently when I click on the icon I want the token to be removed. After a lot of searching it seems that this is not…
Fred Appelman
  • 549
  • 3
  • 11
6
votes
2 answers

How to detect deletion of image in UITextView

If I add an image into a UITextView like this: NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; textAttachment.image = image; NSAttributedString *attrStringWithImage = [NSAttributedString…
soleil
  • 11,239
  • 29
  • 102
  • 172
6
votes
5 answers

Attributed string with text attachment and truncation

I've got an attributed string with an image attached (NSTextAttachment). This works alright, but I've got a problem with truncation that I can't seem to solve. In the example, suppose the string ## is the image. So my string looks something like…
DarkDust
  • 85,893
  • 19
  • 180
  • 214
6
votes
0 answers

NSTextAttachment doesn't show on CATextLayer

I tried it on UITextView it work. but the image left blank when i use CATextLayer. anyone tried before? here is the code i tried in UIView drawRect NSTextAttachment* attachment = [NSTextAttachment new]; attachment.image = [UIImage…
Elliot Yap
  • 966
  • 10
  • 18
5
votes
1 answer

Getting filename and path from nsfilewrapper / nstextattachment in NSAttributedString

I have a basic NSTextView with rich text and graphics enabled (in IB). What I'd like to get is the path and filename of any images dragged in so I can pass those to another class. I'm new to NSAttributedString but I've got a loop using…
5
votes
2 answers

Getting an image imbedded in an NSAttributedString (via NSTextAttachment) to be treated as a single character, so that it doesn't break lines?

I'm embedding an image in an NSAttributedString, and I want iOS to treat it as a character that is a part of the word before it, so that it doesn't get broken onto its own line. I read somewhere that is supposed to be the default behavior, but for…
milohoffman
  • 277
  • 1
  • 10
5
votes
0 answers

How to replace a text attachment with a custom drawing with NSLayoutManager?

My ultimate goal is to give the user the ability to split a text inside an NSTextView or UITextView into several sections, where two subsequent sections are visually separated by a custom view separator (possibly, but not necessarily a horizontal…
5
votes
3 answers

Load Image async for NSTextAttachment for UITableViewCell

Loading images dynamically in async thread or image cache library like SDwebimage. Below code is what I tried and it doesn't repaint after image fetched from network. let mutableAttributedString = NSMutableAttributedString() if let _img =…
com.iavian
  • 327
  • 1
  • 4
  • 12
5
votes
1 answer

NSTextAttachment custom view

Is it possible to display a custom view in the spot where an NSTextAttachment is to be displayed on iOS? I have custom text storage and layout manager subclasses, but I'm not sure where to put the code to actually add a subview. (The reason I want…
architectpianist
  • 2,522
  • 1
  • 17
  • 26
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,101
  • 2
  • 25
  • 42
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
  • 112,774
  • 126
  • 328
  • 461
1
2
3
8 9