Q
xib
采用file owner
的方式,无论如何修改frame
以及增加约束
,控件的大小始终存在问题。
A
frame
和约束放在viewDidLayoutSubviews
-
size
改成freedom
或者Trait Variations
上述方案还是无效果尝试
let carryView = UIView()
carryView.frame = XXX
addSubView(carryView)
let xibView = Bundle......
//1
xibView.frame = carryView.bounds
carryView.addSubView(xibView)
//2 或者
let t = NSLayoutConstraint.init(item: xibView, attribute: NSLayoutConstraint.Attribute.Top......
let l = NSLayoutConstraint......
let b = NSLayoutConstraint......
let r = NSLayoutConstraint......
carryView.addConstraints([t, l, b, r])
carryView.setNeedsLayout()
carryView.layoutIfNeeds()
- 换sb吧
- 如果还是无解,那就纯代码写吧......