我无法更改 UITextView
的 fontSize
,即使我设置了 .isSelectable=false
。
下面的代码无效。 fontSize
不可编辑。
let linkLabel: UITextView = {
let v = UITextView()
v.backgroundColor = .clear
v.text = "Link"
v.textColor = .lightGray
v.font = UIFont(name: "AvenirNext", size: 23)
v.textAlignment = .right
v.isSelectable = false
v.isScrollEnabled = false
v.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
// v.attributedText = NSAttributedString(string: "", attributes: [.underlineStyle: NSUnderlineStyle.single.rawValue])
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
最佳答案
您的字体大小没有任何影响,因为“AvenirNext”不存在。 尝试:“AvenirNext-Regular”
let linkLabel: UITextView = {
let v = UITextView()
v.backgroundColor = .clear
v.text = "Link"
v.textColor = .lightGray
v.font = UIFont(name: "AvenirNext-Regular", size: 23)
v.textAlignment = .right
v.isSelectable = false
v.isScrollEnabled = false
v.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
// v.attributedText = NSAttributedString(string: "", attributes: [.underlineStyle: NSUnderlineStyle.single.rawValue])
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
这是获取 iOS 中包含的字体的正确字体名称的好资源
关于ios - 更改 UITextView 字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59760754/