Akhtar Akhtar - 4 months ago 21
iOS Question

How to create UILabel programmatically by Swift language?

How do I create a

UILabel
programmatically using Swift language in Xcode 6?

I have started with a new "Single View Application" in Xcode 6 and select the Swift language for this project. I have my files
AppDelegate.swift
and
ViewController.swift
and I'm not sure what to do from here.

Answer
override func viewDidLoad()
{
  super.viewDidLoad()
  var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
  label.center = CGPointMake(160, 284)
  label.textAlignment = NSTextAlignment.Center
  label.text = "I'am a test label"
  self.view.addSubview(label)
}