ios - 如何在 UITextview 中通过自动换行 NSTextAttachment 换行
问题描述
我使用 UITextview 并在其上插入 NSTextAttachment 作为图像。该 Textview 只有附件图像,没有任何普通文本。如何像普通文本一样通过自动换行来换行。我设置了 textContainer 的 lineBreakMode 属性但不起作用。我将不胜感激您的任何帮助。
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
return true
for data in arrDataModel {
if data.textDefaul == text {
let attachment = NSTextAttachment()
if let image = data.imageData {
let imageNew = UIImage(data: image)!
attachment.image = imageNew.colorImage(with: colorDefault)
}else{
return true
}
let attString = NSAttributedString(attachment: attachment)
var attributedString :NSMutableAttributedString!
attributedString = NSMutableAttributedString(attributedString:textView.attributedText)
attributedString.insert(attString, at: textView.selectedRange.location)
textView.attributedText = attributedString
textView.selectedRange.location += 1
return false
}
}
return true
}
解决方案
推荐阅读
- c# - 在不使用 C# 访问 Internet 的情况下检查 Internet 连接的最佳方法是什么?
- python - 使用 apply 函数来简化嵌套的 for 循环?
- django - 如何在 django viewfloe 中将任务分配给组
- sql - Postgres将多行列值作为字符串返回
- asp.net - ASP.NET Core 3.1 + Angular 9 部署到 IIS 的子域
- angular - 尝试从 Ionic / Angular 应用程序中的 firestore 检索集合时收到 401 Unauthorized 响应
- rxjs - spyOn 方法返回错误“方法不存在”
- c# - 如何使用 Windows UWP API 连接到配对的音频蓝牙设备?
- java - 如何在 Spring Boot 应用程序中获取 Instagram 提要?
- spring-boot - 添加 spring-boot-starter-data-jpa 缺少我的配置文件配置