swift - 如何在 UItextField 中添加不同字体的字符串?
问题描述
我正在尝试添加具有不同字体参数的两部分文本。但他们总是从第一个字符串中获得价值。还有一件奇怪的事情,字体颜色是独立设置的。
let descriptionTextView: UITextView = {
let view = UITextView()
let attributedText = NSMutableAttributedString(string: "Text", attributes:
[.font:UIFont.boldSystemFont(ofSize: 20),
.foregroundColor: UIColor.blue])
attributedText.append(NSAttributedString(string: "\n\n\n Other text", attributes:
[.font: UIFont.italicSystemFont(ofSize: 5),
.foregroundColor: UIColor.gray]))
view.attributedText = attributedText
view.translatesAutoresizingMaskIntoConstraints = false
view.textAlignment = .center
view.font = UIFont.boldSystemFont(ofSize: 20)
view.isEditable = false
view.isScrollEnabled = false
return view
}()
解决方案
消除
view.font = UIFont.boldSystemFont(ofSize: 20)
推荐阅读
- vagrant - 无法在 PATH 模式 040777 中解析不安全的世界可写目录 /mnt/c
- amazon-web-services - ec2 上没有更多磁盘空间
- mongodb - 在 MongoDB 中的记录中取消嵌套值
- bash - 使用 awk 或 bash 将字符串附加到列中单元格的所有元素
- ios - FIRUser.uid 更改为某些内容,并且在 swift 5 中不起作用
- python - Python速成课程:json.decoder.JSONDecodeError:期望值:第1行第1列(char 0)
- javascript - 我们可以在另一个 React 应用程序中嵌入一个 React 应用程序吗?
- java - Spring Boot 创建自定义注释以获取登录用户?
- c++ - 返回对函数的引用的函数
- arrays - 返回不透明类型的数组