Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add image on UITextView with custom spacing and text

I want to add Image on text view and want proper spacing as shown in screenshot. Its A screenshot as I want as per design:

I have tried to add image on textview but I m having problem in placing text as per requirement. Please provide me help regarding same.

like image 346
Pushkraj P. Lanjekar Avatar asked Oct 18 '13 14:10

Pushkraj P. Lanjekar


2 Answers

Add the below code after defining textView and imageView.

import CoreText.Framework

UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];

textView.textContainer.exclusionPaths  = @[exclusionPath];

[textView addSubview:imageView];

to have a clear idea on core text tutorial see raywenderlich

like image 138
abhi Avatar answered Sep 25 '22 00:09

abhi


In SWIFT:

var exclusionPath:UIBezierPath = UIBezierPath(rect: CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height))

textView.textContainer.exclusionPaths  = [exclusionPath]
textView.addSubview(imageView)
like image 39
Shardul Avatar answered Sep 26 '22 00:09

Shardul