Add image on UITextView with custom spacing and text

有些话、适合烂在心里 提交于 2019-12-06 03:38:42

问题


I want to add Image on text view and want proper spacing as shown in screenshot.

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.


回答1:


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)



回答2:


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




回答3:


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




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/19451747/add-image-on-uitextview-with-custom-spacing-and-text

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