iPhone

Underline text / title in UIButton

zombie45 2020. 6. 10. 01:53

use NSAttributedString to underline the string itself

let btShop: UIButton = UIButton()
btShop.frame = CGRect(x: 40, y: 240, width: 320, height: 50)
let attributedString: NSAttributedString = NSAttributedString(string: NSLocalizedString("Buy", comment: ""), attributes:[
    NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16.0),
    NSAttributedString.Key.foregroundColor : UIColor.gray,
    NSAttributedString.Key.underlineStyle:1.0
])
btShop.setAttributedTitle(attributedString, for: .normal)
self.view.addSubview(btShop)
반응형