「Swift」UIButtonでボタンのタイトル、色を設定するサンプル
書式
button.setTitle(xxx)
使用例
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// タイトル
button.setTitle("test title", for: .normal)
// 色
button.setTitleColor(UIColor.green, for: .normal)
}
}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// タイトル
button.setTitle("test title", for: .normal)
// 色
button.setTitleColor(UIColor.green, for: .normal)
}
}
import UIKit class ViewController: UIViewController { @IBOutlet weak var button: UIButton! override func viewDidLoad() { super.viewDidLoad() // タイトル button.setTitle("test title", for: .normal) // 色 button.setTitleColor(UIColor.green, for: .normal) } }