Question

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.

Was it helpful?

Solution 2

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)

OTHER TIPS

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

as par my suggestion you could use UIWebview instead of TextView for Doing this task use loadHTMLString here it is a example of loading local fines in UIWebview please take a look this and impliment as par you required

@Fogmeister is correct, however if you want to do something a bit less complicated by using the default RICH TEXT with IMAGE capabilities now available in iOS 7 using just NSAttributedString then take a look at this link.

You won't be able to support text wrapping - use Pages for that - but for simple note taking this might do.

The problem you're having is that the image you put in your question is not using a UITextView.

The way this is done is to use Text Kit and render the text manually onto a view.

By doing this you can (in iOS7) specify a CGPath that the text "wraps" around.

There is a 2013 WWDC video "Introducing Text Kit" that you can watch here.

That shows how to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top