LoginSignup
5
3

More than 3 years have passed since last update.

【swift】UIButtonのタイトルラベルに下線を付けた上で色を調整する方法

Last updated at Posted at 2019-06-27

実現したいこと

UIButtonのタイトルラベルに下線を付けた上で色を調整する

経緯

下線を付ける方法を調べていたら

let AttributedString = NSAttributedString(string: "text", attributes: [.underlineStyle: NSUnderlineStyle.single.rawValue
と書けば下線を弾けることが分かった。

しかし、色が青色になってしまう。

button.setTitleColor(ColorManager().white(), for: .normal)

と書いても色を変更できないため、ハマった。

結論

let AttributedString = NSAttributedString(string: "text", attributes: [.underlineStyle: NSUnderlineStyle.single.rawValue, NSAttributedString.Key.foregroundColor : UIColor.white])
button.setAttributedTitle(AttributedString, for: .normal)

と書けば良い。

5
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3