How to change the color of the button title in Swift

uibutton title not showing swift
uibutton text color
swift button action
uibutton states
swift change button color when pressed
button title font swift
uibutton background color swift
how to get button title in swift

Is-it possible to change the color of the Title for the button ?

Because this code d'ont work

btnLogin.titleColor = UIColor.darkGray

Try this:

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

Setting UIButton Title and Title Color "The Right Way" in Swift 3 , Every time I set a UIButton color or title I fail at first because I try to do the following: //This is incorrect, don't do this let button = UIButton()  //Setting UIButton color and title the right way let button = UIButton () button. setTitle ("My Amazing Button", for: . normal) button. setTitleColor (. blue, for: . normal) Perhaps now I'll finally remember the right way to do it, and I hope you will too!

As the other comments says, use

    btnLogin.setTitleColor(UIColor.darkGray, for: .normal)

Here you can read the explanation of this method and the different states (normal, selected, highlighted, ...)

https://developer.apple.com/documentation/uikit/uibutton/1623993-settitlecolor

How to change a button background color using Swift?, How do I change the color of a button in Swift? To do this, press Control + Command + Space key at same time to popup mac os emoji select panel, then select one emoji to input it in the button title text box. 2.3 Change Button Title Text Color. In Button area,  select the text color in Text Color drop down list. You can select customized color in the popup color pane.

You can set like this -

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

Swift Change UIButton text, How do I change the text of a button in Swift? In order to change color of navigation bar for all view controllers, you have to set it in AppDelegate.swift file Add following code to didFinishLaunchingWithOptions function in AppDelegate.swift var navigationBarAppearace = UINavigationBar.appearance() navigationBarAppearace.tintColor = uicolorFromHex(0xffffff) navigationBarAppearace.barTintColor = uicolorFromHex(0x034517)

How to set textColor of UILabel in Swift, Sets the color of the title to use for the specified state. Therefore, at a minimum, you should set the value for the normal state. Configuring the Button Title. 12 Answers 12. You change the title by changing the title of the view controller being displayed: Normally this is done in view did load on the view controller: However, this only works if you have your view controller embedded in a UINavigationController.

Highlight a button when Pressed In swift, When setting the content of a button, you must specify the title, image, and appearance attributes for This property sets the color of the button image and text. The following Playground sample code show how to create a UIbutton in a UIViewController and change it's title color using setTitleColor(_:for:):. import UIKit import PlaygroundSupport class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.white // Create button let button = UIButton(type: UIButton.ButtonType.system) // Set

setTitleColor(_:for:), You've now successfully set the button to change the background color of the view, but Because Swift is a very readable programming language, you can probably To learn how to change the title of the button, refer to the Xcode Developer  Use this method to set the title for the button. The title you specify derives its formatting from the button’s associated label object. If you set both a title and an attributed title for the button, the button prefers the use of the attributed title over this one. At a minimum, you should set the value for the normal state.

Comments
  • Usually, use setTitleColor(_:for:) because buttons can have different UIControlState: .normal, .highlighted, .selected, etc.