我想在自定义 UITableViewCell 中插入自定义 UIView。 我创建了一个包含一些操作的 nib 文件,我想将此 View 放在我的单元格底部,但内容显示在我的单元格顶部。为什么 ?
编辑:
我的观点代码:
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
func xibSetup() {
view = loadViewFromNib()
// use bounds not frame or it'll be offset
view.frame = bounds
// Make the view stretch with containing view
view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
// Adding custom subview on top of our view (over any custom drawing > see note below)
addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "viewActionsTimeline", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
return view
}
最佳答案
我解决了我的问题。 我把这一行:
view.translatesAutoresizingMaskIntoConstraints = true
关于ios - nib 中的 uiview 内容位于容器外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43806042/