ios - 更改 UITextView 字体大小

标签 ios swift fonts uitextview

我无法更改 UITextViewfontSize,即使我设置了 .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 中包含的字体的正确字体名称的好资源

http://iosfonts.com

关于ios - 更改 UITextView 字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59760754/

相关文章:

ios - 从远程服务器获取 ios 应用程序的时间

ios - 如何查找 NSMutableDictionary 中的重复项?

css - 在 visual studio 2015 中嵌入字体

CSS 导入字体问题

ios - 在构建时添加框架 - XCode

ios - AviarySDK iOS 错误

ios - 在 Swift 中使用未解析的标识符 "class"

ios - 如何检索 EKEventStoreChanged 通知中已更改的事件

swift - 使用swift强制将数字显示为小数点后两位

javascript - 如何在自定义字体 css 文件中查找可用的字体粗细