使用自定义间距和文本在UITextView上添加图像

Pus*_*raj 5 overlay uitextview uiimageview ios xcode4.5

我想在文本视图上添加图像,并希望有适当的间距,如屏幕截图所示. 根据设计我想要的截图:

我试图在textview上添加图像,但我在按要求放置文本时遇到问题.请给我一些帮助.

abh*_*bhi 9

在定义textView和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];
Run Code Online (Sandbox Code Playgroud)

对核心文本教程有一个清晰的想法,请参阅raywenderlich


Sha*_*dul 5

在 SWIFT 中:

var exclusionPath:UIBezierPath = UIBezierPath(rect: CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height))

textView.textContainer.exclusionPaths  = [exclusionPath]
textView.addSubview(imageView)
Run Code Online (Sandbox Code Playgroud)