How to add image and text in UITextView Swift?
This tutorial for Adding Image inside the TextView. This is for Swift and Objective C.
Swift Code:
Swift Code:
let attributedString = NSMutableAttributedString(string: "iOSdevCenters")
let textAttachment = NSTextAttachment()
textAttachment.image = UIImage(named: "iOSDevCenter.png")
let attrStringWithImage = NSAttributedString(attachment: textAttachment)
attributedString.replaceCharacters(in: NSMakeRange(2, 1), with: attrStringWithImage)
ObjectiveC Code: NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"iOSdevCenters"];NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"iOSDevCenter.png"];
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
[attributedString replaceCharactersInRange:NSMakeRange(2, 1) withAttributedString:attrStringWithImage];
Thanks.
How to add image and text in UITextView Swift?
Reviewed by KIRIT MODI
on
21:51:00
Rating:
No comments: