【swift】UIButtonひな型
アプリ開発してると、サンプルアプリ作ってみてうまくいったら開発中のアプリに組み込む
っていうながれが多いんですけど、僕の場合はサンプルアプリつくるさいにとりあえずボタンをおくことが多いんです
が、そのボタンをおくのに過去のソースから探して・・・っていう時間がなにげにかかって毎回地味に時間無駄にしてるので自分用にメモ
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var button = UIButton()
button.frame = CGRectMake(0, 0, 200, 40)
button.layer.position = CGPoint(x: self.view.frame.width/2, y: 200)
button.setTitle("ボタン", forState: UIControlState.Normal)
button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
button.layer.borderColor = UIColor.blackColor().CGColor
button.layer.borderWidth = 0.5
button.layer.cornerRadius = 5
button.addTarget(self, action: "onButton:", forControlEvents: .TouchUpInside)
self.view.addSubview(button)
}
func onButton(sender: UIButton) {
// ボタンが押されたときの処理
}
}htmlだったらタグとか簡単なのでこんなこと考える必要もないんですけどね^^;というお話でした
以上です