I've create a UITextView that I've added to a UIView, this TextView should display an image at the top right or left corner wrapped by some text.
Creating the TextView isn't the issue (obviously), I just can't wrap my head around the NSAttributedString.
As for the image, I've used a NSTextAttachment;
var image:UIImage = UIImage(named: "placeHolder.png")
var textAttachment:NSTextAttachment = NSTextAttachment(data: nil, ofType: nil)
textAttachment.image = image
Then we've got some text for the TextView;
var text:String = "Lorem ipsum"
Now the tricky part. I can create an NSAttributedString that can be set to the UITextView. It displays the image just fine, I just can't figure out how to set the text.
var s:NSAttributedString = NSAttributedString(attachment: textAttachment)
textView.attributedText = s
Any ideas?
Here's code that shows how to construct an NSAttributedString consisting of text and some NSTextAttachments:
However...
this TextView should display an image at the top right or left corner wrapped by some text.
Then what you want is not an NSTextAttachment, since that is an inline image without wrapping.
To get an image at a fixed position with wrapping, use an image subview and cause the wrapping by using an exclusion path.