0

I want to add image inline with text to UITextView just like below screenshot

enter image description here


I have try using NSTextAttachment and NSAttributedString but it put only one line before & after the image.

Please help me to sort this out.

Haresh Ghatala
  • 1,996
  • 17
  • 25
  • It may Helpful: > http://stackoverflow.com/questions/24010035/how-to-add-image-and-text-in-uitextview-in-ios – iOS Dev Jun 25 '15 at 12:48
  • I have tried this one before posting this question but it is not working for my requirement. And i have also mention about this in my question – Haresh Ghatala Jun 25 '15 at 12:52
  • That's a nice image. Can you post the text as well, just in case the image link dies? Also, can you edit the various things you've tried and why they don't work? – Justin Jun 25 '15 at 21:22

1 Answers1

2

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];
}
sanky009
  • 136
  • 1
  • 3