2014-07-18 24 views
23

Arka plan rengini nasıl değiştireceğimi biliyorum, ancak asıl metin nedir? UIButton'da "color" adlı bir üye ya da bunun gibi bir şey yok gibi görünüyor. Kodum:Düğmeye basıldığında metnin rengini değiştirin.

@IBAction func yellowBtnClicked(sender: UIButton) { 
     gameboard.image = UIImage(named: "Yellow_gb") 
     resultsView.image = UIImage(named: "Yellow_results") 
     colorsView.image = UIImage(named: "Yellow_colors") 
     colorsBtn.color = UIColor.brownColor() //This line has the issue 

    } 

cevap

59

UIButton hiçbir özellik kurucu color yoktur. buton Highlighted devlet kullanımı

colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Highlighted) 
6

Swift 3.0 iken title rengini ayarlamak için UIControlState.Normal

için kahverengi başlık rengi değişir viewWillAppear

colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal) 

Bu yerine setTitleColor gelirse yaz bunu kullanın örnek:

colorsBtn.setTitleColor(UIColor .white, for: UIControlState.normal) 
    colorsBtn.setTitleColor(UIColor .black, for: UIControlState.highlighted) 
İlgili konular