Skip to content

Instantly share code, notes, and snippets.

@tdtsh
Created January 19, 2016 15:10
Show Gist options
  • Save tdtsh/b064bacbbd3ad3bf1a3e to your computer and use it in GitHub Desktop.
Save tdtsh/b064bacbbd3ad3bf1a3e to your computer and use it in GitHub Desktop.
Swift2 で UIButton
class CameraViewController: UIViewController {
...
func renderView() {
// ボタン作成
let buttonTake = UIButton(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width - 50, height: 50))
buttonTake.backgroundColor = UIColor.init(colorLiteralRed: 0.3, green: 0.3, blue: 0.7, alpha: 0.5)
// 角丸
buttonTake.layer.cornerRadius = 5.0
buttonTake.layer.masksToBounds = true
// タイトルとか
buttonTake.setTitle("撮影&アルバム保存", forState: UIControlState.Normal)
//buttonTake.setTitle("タップされた", forState: UIControlState.Highlighted)
//buttonTake.sizeToFit() // 文字の長さ、大きさにフィットするサイズ
// 配置
buttonTake.layer.position = CGPoint(x: self.view.bounds.width/2, y:self.view.bounds.height - 55)
buttonTake.addTarget(self, action: "takePhoto:", forControlEvents: .TouchUpInside)
self.view.addSubview(buttonTake)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment