我的 XIB 中有一个图像,我想根据实际屏幕的大小调整它的大小。我该怎么做?
在常规 View Controller 中,我能够执行以下操作:
myImage.frame.size.width = self.view.bounds.width * 0.40 // it will always be 40% of my view's size
我尝试了与 XIB 类类似的方法,但它根本没有调整我的图像大小。
有什么想法吗?
编辑:
required init?(coder aDecoder: NSCoder) {
// properties
super.init(coder: aDecoder)
// Setup
setup() // trying to resize the image here
}
最佳答案
我认为你的意思是 UIView
子类?将调整大小的代码放入 layoutSubviews
中。您可能还需要在加载 xib 后立即在 View Controller 内调用 setNeedsLayout
和 layoutIfNeeded
(按此顺序)。
关于ios - 如何在运行时调整 XIB/NIB 内 subview 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43924642/