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 版