将图像添加到 UITextView [英] Adding Images to UITextView
本文介绍了将图像添加到 UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我有一个 UITextView
和一个按钮,用于在编辑时将照片插入到 UITextView
中.
In my app I have a UITextView
and a button just below the text view to insert a photo into the UITextView
while editing.
我的要求是用户用户能够编辑其中的文本,并在需要时插入图像.
My requirement is that the user user is able to edit the text within, and insert images when needed.
类似于 StackOverflow 的应用程序自己的 UITextView
:
Similar to StackOverflow's app's own UITextView
:
推荐答案
您可以将图像视图添加为 UITextView
的子视图.
You can add the image view as a subView of UITextView
.
用图像创建一个图像视图:
Create an imageView with image:
UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
[imageView setFrame:yourFrame];
[yourTextView addSubview:imageView];
为了避免重叠使用(感谢@chris):
For avoiding the overlapping use (Thanks @chris):
CGRect aRect = CGRectMake(156, 8, 16, 16);
[imageView setFrame:aRect];
UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:CGRectMake(CGRectGetMinX(imageView.frame), CGRectGetMinY(imageView.frame), CGRectGetWidth(yourTextView.frame), CGRectGetHeight(imageView.frame))];
yourTextView.textContainer.exclusionPaths = @[exclusionPath];
[yourTextView addSubview:imageView];
这篇关于将图像添加到 UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文