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
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,326
  • 2
  • 31
  • 57
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,347
  • 1
  • 14
  • 28
7
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
  • 716
  • 5
  • 13
7
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
  • 377
  • 1
  • 5
  • 13
7
votes
2 answers

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,562
  • 1
  • 19
  • 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
7
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
  • 90,870
  • 19
  • 190
  • 224
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. …
Becca Royal-Gordon
  • 17,541
  • 7
  • 56
  • 91
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
  • 12,133
  • 33
  • 112
  • 183
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
  • 1,076
  • 1
  • 12
  • 20
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
  • 287
  • 1
  • 11
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…
Mischa
  • 15,816
  • 8
  • 59
  • 117
5
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
  • 3,049
  • 1
  • 34
  • 45
5
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
  • 12,319
  • 23
  • 93
  • 186
1
2
3
9 10