我有一个 UIView,它在 Storyboard中垂直和水平居中,并具有固定的高度 (100) 和宽度 (300)。现在我希望 uiview 在运行时调整大小 (100, 100)。
到目前为止我已经尝试过,但没有任何效果。
let cgRect = CGRect(x: 0, y: 0, width: 100, height: 100)
sampleView.draw(cgRect)
和
sampleView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
和
sampleView.frame.size.height = 100
sampleView.frame.size.width = 100
最佳答案
将宽度和高度约束 Hook 为 IBOutlet 和 in
@IBAction func btnClicked(_ sender: Any) {
self.widthCon.constant = 100
self.heightCon.constant = 100
self.view.layoutIfNeeded()
}
关于ios - 在运行时调整 UIView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49873340/