我有UITextView
我希望它的容器高度和宽度相同。这是一个简单的UIViewContainer
我尝试了以下操作:
override public func viewDidLoad() {
self.edgesForExtendedLayout = .None
resultText.text = result
resultText.frame = view.frame
}
这似乎适用于肖像,但不适用于风景。 我所要做的就是让UITextView占用它容器的所有空间。
如果我能在Objective-C中找到答案,我可以很容易地将其翻译成Swift。我只是在寻找iOS的答案。
答案 0 :(得分:3)
我建议你使用自动布局
然后点击添加4个约束。
如果有任何警告,
点击更新框架
答案 1 :(得分:2)
Autolayout是您的朋友 - 可以使用Interface Builder或代码轻松完成:
override public func viewDidLoad() {
super.viewDidLoad()
self.edgesForExtendedLayout = .None
resultText.text = result
// add vertical constraints to pin the view to the superview edge
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0.0-[resultText]-0.0-|", options: nil, metrics: nil, views: ["resultText": resultText]))
// add horizontal constrains to pin the view to the superview edge
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0.0-[resultText]-0.0-|", options: nil, metrics: nil, views: ["resultText": resultText]))
}