「Swift」UIButtonでボタンのタイトル、色を設定するサンプル

2021年7月21日

書式
button.setTitle(xxx)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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) 
    }
}

 

Swift

Posted by arkgame