How to set the title text color of UIButton?

后端 未结 7 1411
温柔的废话
温柔的废话 2020-12-13 05:18

I tried changing the colors of the text for a button, but it\'s still staying white.

isbeauty = UIButton()
isbeauty.setTitle(\"Buy\", forState: UIControlStat         


        
7条回答
  •  青春惊慌失措
    2020-12-13 06:05

    referring to radio buttons ,you can also do it with Segmented Control as following:

    step 1: drag a segmented control to your view in the attribute inspector change the title of the two segments ,for example "Male" and "Female"

    step 2: create an outlet & an action for it in the code

    step 3: create a variable for future use to contain choice's data

    in the code do as following:

    @IBOutlet weak var genderSeg: UISegmentedControl!
    
    var genderPick : String = ""
    
    
     @IBAction func segAction(_ sender: Any) {
    
        if genderSeg.selectedSegmentIndex == 0 {
             genderPick = "Male"
            print(genderPick)
        } else if genderSeg.selectedSegmentIndex == 1 {
            genderPick = "Female"
              print(genderPick)
        }
    }
    

提交回复
热议问题