Created
January 17, 2016 02:43
-
-
Save tdtsh/966793cc0b43639528cb to your computer and use it in GitHub Desktop.
Swift2 でラベルを表示する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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