将图像添加到UITextView [英] Adding Images to UITextView

查看:99
本文介绍了将图像添加到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.

创建带图像的imageView:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆