Add image on UITextView with custom spacing and text

旧巷老猫 提交于 2019-12-04 07:45:25

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)
abhi

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

Nitin Gohel

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

Duncan Groenewald

@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.

Fogmeister

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!