LoginSignup
0
0

More than 5 years have passed since last update.

UILabel作成

Last updated at Posted at 2015-10-12

//

// ViewController.swift

// UIKit001

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

    super.viewDidLoad()



    // Labelを作成.

    let myLabel: UILabel = UILabel(frame: CGRectMake(0,0,200,50))



    // 背景をオレンジ色にする.

    myLabel.backgroundColor = UIColor.orangeColor()



    // 枠を丸くする.

    myLabel.layer.masksToBounds = true



    // コーナーの半径.

    myLabel.layer.cornerRadius = 20.0



    // Labelに文字を代入.

    myLabel.text = "Hello Swift!!"



    // 文字の色を白にする.

    myLabel.textColor = UIColor.whiteColor()



    // 文字の影の色をグレーにする.

    myLabel.shadowColor = UIColor.grayColor()



    // Textを中央寄せにする.

    myLabel.textAlignment = NSTextAlignment.Center



    // 配置する座標を設定する.

    myLabel.layer.position = CGPoint(x: self.view.bounds.width/2,y: 200)



    // Viewの背景色を青にする.

    self.view.backgroundColor = UIColor.cyanColor()



    // ViewにLabelを追加.

    self.view.addSubview(myLabel)

}



override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

}

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0