我在 Interface Builder 中定义了 Swift 中的堆栈 View :
@IBOutlet weak var myStack: UIStackView!
后面的代码:
myStack.frame.height=100 -> Error:Value of type '(CGRect) -> CGRect' has no member 'height'
成员高度的存在是因为XCode的autocomplete提出来的。
这是什么 CGRect 错误?
最佳答案
在框架文档中(CgRect)
https://developer.apple.com/documentation/coregraphics/cgrect/1455645-height
var height: CGFloat { get }
它仅在 CGSize 的文档中作为 getter 可用
https://developer.apple.com/documentation/coregraphics/cgsize/1455076-height
可以设置
myStack.frame.size.height = 100.0
或者
myStack.frame.size = CGSize(width:height)
关于ios - 愿意在 Swift 中调整 View 大小时出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59323514/