【发布时间】:2016-09-29 09:46:38
【问题描述】:
【问题讨论】:
标签: ios uitextview swift3
【问题讨论】:
标签: ios uitextview swift3
添加CoreText框架
import CoreText
将imageView添加到UITextView后添加以下代码,
var exclusionPath = UIBezierPath(rect: CGRect(x: imageView.frame.orgin.x, y: imageView.frame.orgin.y, width: imageView.frame.size.width, height: imageView.frame.size.height))
textView.textContainer.exclusionPaths = [exclusionPath]
textView.addSubview(imageView)
【讨论】:
你应该使用NSLineBreakByCharWrapping,意思是这个词会在一个字符之后被剪切。
textview.textContainer.lineBreakMode = NSLineBreakByCharWrapping;
【讨论】:
您可以完全按照这种方式进行设计。虽然我没用过 Swift 3,但是你可以根据语法来格式化。
这里exclusionPath将负责启动图片后的文字,exclusionPath1负责启动图片下方的文字,根据您的要求。
我的代码:
let txtView = UITextView(frame: CGRectMake(0, 64, SCREEN_SIZE.width, 150));
self.view.addSubview(txtView);
let imageView = UIImageView(frame: CGRectMake(0, 0, 50, 50));
imageView.image = UIImage(named: "icon");
let exclusionPath = UIBezierPath(rect: CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height));
let exclusionPath1 = UIBezierPath(rect: CGRectMake(-50, 50, imageView.frame.size.width, imageView.frame.size.height));
txtView.textContainer.exclusionPaths = [exclusionPath, exclusionPath1];
txtView.addSubview(imageView);
输出:
希望对你有帮助
编码愉快...
【讨论】: