Reputation: 2006
I want to add image inline with text to UITextView just like below screenshot
I have try using NSTextAttachment
and NSAttributedString
but it put only one line before & after the image.
Please help me to sort this out.
Upvotes: 0
Views: 960
Reputation: 136
You need to just use 'UIBezierPath'
For example,
txtvHtmlString.text = @“your long text…….”;
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(120, 100, 152, 128)];
imgView.image = [UIImage imageNamed:@"smily.png"];
imgView.layer.cornerRadius = 10;
[txtvHtmlString addSubview:imgView];
Then don't forget to update bezierpath in viewDidLayoutSubviews if your text is updated.
- (void)viewDidLayoutSubviews {
UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:imgView.frame];
txtvHtmlString.textContainer.exclusionPaths = @[exclusionPath];
}
Upvotes: 2