iphone - 将图像添加到 UITextView

标签 iphone objective-c ipad uiimageview uitextview

在我的应用程序中,我有一个 UITextView 和一个位于 TextView 正下方的按钮,用于在编辑时将照片插入 UITextView

我的要求是用户用户能够编辑其中的文本,并在需要时插入图像。

类似于StackOverflow的app自带的UITextView:

enter image description here

最佳答案

您可以将 ImageView 添加为 UITextView 的 subview 。

用图像创建一个 imageView:

UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
[imageView setFrame:yourFrame];
[yourTextView addSubview:imageView];

编辑:

为了避免重叠使用(感谢@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]; 

关于iphone - 将图像添加到 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13263808/

相关文章:

iphone - 为什么这个CALayer不显示图像?

iphone - iPhone 应用程序编译代码中包含的信息有多安全?

ios - 注释标记@code 不适用于属性

ios - iOS 上的 Firebase 崩溃报告不会在崩溃后发送报告

iphone - iOS 清除 UIWebView 的回溯历史

iphone - 什么时候使用存档: method of NSManagedObjectContext

ios - 检测首次启动时出错(Swift)

ios - 是否可以在 UITableView 的部分行中禁用 didSelectRowAtIndexPath?

iphone - iOS 陀螺仪 API

ios - iPad UIViewController 复杂界面最佳实践