Comment définir la couleur du text du titre de UIButton?

J'ai essayé de changer les colors du text pour un button, mais il rest blanc.

isbeauty = UIButton() isbeauty.setTitle("Buy", forState: UIControlState.Normal) isbeauty.titleLabel?.textColor = UIColorFromRGB("F21B3F") isbeauty.titleLabel!.font = UIFont(name: "AppleSDGothicNeo-Thin" , size: 25) isbeauty.backgroundColor = UIColor.clearColor() isbeauty.layer.cornerRadius = 5 isbeauty.layer.borderWidth = 1 isbeauty.layer.borderColor = UIColorFromRGB("F21B3F").CGColor isbeauty.frame = CGRectMake(300, 134, 55, 26) isbeauty.addTarget(self,action: "first:", forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(isbeauty) 

J'ai aussi essayé de changer le rouge, le noir, le bleu, mais rien ne se passe.

Vous devez utiliser func setTitleColor(_ color: UIColor?, forState state: UIControlState) la même manière que vous avez défini le text du titre réel. Docs

 isbeauty.setTitleColor(UIColorFromRGB("F21B3F"), forState: .Normal) 

SWIFT 3, Swift 4

pour améliorer les commentaires. Cela devrait fonctionner:

button.setTitleColor(.red, for: .normal)

Exemple de définition de la couleur du titre du button

btnDone.setTitleColor (UIColor.black, pour: UIControlState.normal)