iOS swift5 UIlabel添加下滑线

  lazy var privacyPolicyBtn:UIButton = {
    
    
        let btn = UIButton(type: .custom)
        btn.addTarget(self, action: #selector(privacyPolicyBtnClick), for: .touchUpInside)
        let number = NSNumber(integerLiteral: NSUnderlineStyle.single.rawValue)//此处需要转换为NSNumber 不然不对,rawValue转换为integer
        let attributedString = NSAttributedString(string: LocalizableManager.localValue("privacyPolicy"), attributes: [NSAttributedString.Key.font : UIFont(name: "PingFangSC-Regular", size: 12),NSAttributedString.Key.foregroundColor:UIColor.hexColor(hexValue: 0x757575),NSAttributedString.Key.underlineStyle:number])
        btn.setAttributedTitle(attributedString, for: .normal)
        return btn
    }()

参考博客:
IOS UIButton UILabel 等title 添加下划线 swift 版

猜你喜欢

转载自blog.csdn.net/baidu_40537062/article/details/123675606