I've successfully been using NSTextAttachment
s 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 imageNamed:@"someImage"];
I'm interested to try using the initWithData:ofType:
, however I can't seem to find any documentation that describes what kind of NSData
the NSTextAttachment
class supports that can be rendered in a UITextView
.
For instance, can I pass data of an NSString
or some kind of UIView
? Or even a PDF? Or is it limited to actually be UIImage
data?
I guess that the data might be any arbitrary data that represents your attachment (to be saved for example in RTF format). The image property on the other side is used only to actually render the representation of the attachment. So for example when you attach a pdf file in the Mail app I think it creates an attachment object setting its data to the actual data of the pdf and setting the image to a UIImage object that holds the pdf icon and the file name. This later image might be generated directly by Mail app. So all in all, I don't think UITextView renders any attachment data neither it concerns the contents of the data property: you have to provide an image that you want to be visualized in the text view, and set that data to whatever you need.