Skip to content

Instantly share code, notes, and snippets.

@tdtsh
Created January 17, 2016 02:43
Show Gist options
  • Save tdtsh/966793cc0b43639528cb to your computer and use it in GitHub Desktop.
Save tdtsh/966793cc0b43639528cb to your computer and use it in GitHub Desktop.
Swift2 でラベルを表示する
class CameraViewController: UIViewController {
...
override func viewDidLoad() {
super.viewDidLoad()
// 角丸なLabelを作成
let labelHello: UILabel = UILabel(frame: CGRectMake(0, 0, 300, 40))
labelHello.layer.masksToBounds = true
labelHello.layer.cornerRadius = 5.0
// 文字と文字色、背景色をセット
labelHello.text = "Hello, This is CameraViewController!"
labelHello.textColor = UIColor.whiteColor()
labelHello.backgroundColor = UIColor.init(colorLiteralRed: 0.8, green: 0.2, blue: 0.3, alpha: 1.0)
// 文字を中央寄せ、ウィンドウ中央に配置
labelHello.textAlignment = NSTextAlignment.Center
labelHello.layer.position = CGPoint(x: self.view.bounds.width/2,y: self.view.bounds.height/2)
// ViewにLabelを追加.
self.view.addSubview(labelHello)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment