How to set the title text color of UIButton?
Example in setting button title color
btnDone.setTitleColor(.black, for: .normal)
This is swift 5 compatible answer. If you want to use one of the built-in colours then you can simply use
button.setTitleColor(.red, for: .normal)
If you want some custom colours, then create an extension for a UIColor as below first.
import UIKit
extension UIColor {
static var themeMoreButton = UIColor.init(red: 53/255, green: 150/255, blue: 36/255, alpha: 1)
}
Then use it for your button as below.
button.setTitleColor(UIColor.themeMoreButton, for: .normal)
Tip: You can use this method to store custom colours from rgba colour code and reuse it throughout your application.
Swift UI solution
Button(action: {}) {
Text("Button")
}.foregroundColor(Color(red: 1.0, green: 0.0, blue: 0.0))
Swift 3, Swift 4, Swift 5
to improve comments. This should work:
button.setTitleColor(.red, for: .normal)
You have to use func setTitleColor(_ color: UIColor?, for state: UIControl.State)
the same way you set the actual title text. Docs
isbeauty.setTitleColor(UIColorFromRGB("F21B3F"), for: .normal)