【发布时间】:2017-04-02 11:23:45
【问题描述】:
在 Swift Playground 中,如何将 UILabel 居中在 UIViewController 内?
当我使用title.center = CGPoint(x: vc.view.frame.width / 2, y: 20) 时,文本会从屏幕上消失。
这就是问题
如果有帮助,这是我的代码。
import UIKit
import PlaygroundSupport
// Set up ViewController and other things
var vc = UIViewController()
vc.view.frame.size.height = 75
vc.view.backgroundColor = .white
let title = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
title.textAlignment = .center
title.center = vc.view.center
title.text = "Which code is correct?"
vc.view.addSubview(title)
PlaygroundPage.current.liveView = vc
【问题讨论】:
-
试试 title.center = self.view.center
-
@Harambe Squad stackoverflow.com/questions/34645943/…
-
title.center = GCPoint(x:self.view .bounds.size.width / 2.0, y:self.view .bounds.size.height / 2.0)
-
还是不行
标签: ios swift3 swift-playground