use*_*721 12 iphone objective-c uitextview uiimageview ipad
在我的应用程序中,我UITextView
在文本视图下方有一个按钮,可以UITextView
在编辑时插入照片.
我的要求是用户用户能够在其中编辑文本,并在需要时插入图像.
与StackOverflow的应用程序类似UITextView
:
Mid*_* MP 18
您可以将图像视图添加为子视图UITextView
.
使用image创建imageView:
UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
[imageView setFrame:yourFrame];
[yourTextView addSubview:imageView];
Run Code Online (Sandbox Code Playgroud)
编辑:
为避免重叠使用(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];
Run Code Online (Sandbox Code Playgroud)
Ole*_*hko 10
如果仅将其添加为子视图,则某些文本可以在图像"后面".因此,添加将"告诉"文本的代码,图像的区域是不可访问的:
UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:CGRectMake(CGRectGetMinX(imageView.frame),
CGRectGetMinY(imageView.frame), CGRectGetWidth(imageView.frame),
CGRectGetHeight(imageView.frame))];
textView.textContainer.exclusionPaths = @[exclusionPath];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17924 次 |
最近记录: |