更改UITextView字体大小

问题描述 投票:0回答:1

即使设置了fontSize,我也无法更改UITextView.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
    }()
ios swift fonts uitextview
1个回答
1
投票

您的字体大小没有任何作用,因为“ 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

© www.soinside.com 2019 - 2024. All rights reserved.