我正试着把一些文字放在中心,但我觉得它似乎不起作用.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let title = UILabel()
title.text = "Some Sentence"
title.numberOfLines = 0
title.frame = CGRectMake(self.view.bounds.size.width/2,50,self.view.bounds.size.width, self.view.bounds.size.height) // x , y, width , height
title.textAlignment = .Center
title.sizeToFit()
title.backgroundColor = UIColor.redColor()
self.view.addSubview(title)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
这就是我使用的代码,但我得到的是:
它不是屏幕的中心.有人能告诉我我做错了什么吗?