iOS8 ボタン(UIButton)の基本と装飾
SwiftのViwControllerで、ボタンを作成します。
背景:赤色
文字:赤色
角丸:白色
です。
// buttonを作る(myButtonという名前のボタンを作ります)
let myButton = UIButton()
// ボタンで使う色
let titleColor = UIColor.whiteColor()
// サイズを設定する
myButton.frame = CGRectMake(120,250,90,40)
//ボタンの位置を指定する
myButton.layer.position = CGPoint(x: self.view.frame.width/2, y:600)
// 背景色を設定する
myButton.backgroundColor = UIColor.whiteColor()
// 角丸を指定する
myButton.layer.cornerRadius = 15
// タイトルを設定する(Startという文字を入れる)
myButton.setTitle("Start", forState: UIControlState.Normal)
// テキストの色設定
myButton.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
// ボタンをViewに追加する
self.view.addSubview(myButton)