ios - nib 中的 uiview 内容位于容器外部

标签 ios uiview nib ibdesignable

我想在自定义 UITableViewCell 中插入自定义 UIView。 我创建了一个包含一些操作的 nib 文件,我想将此 View 放在我的单元格底部,但内容显示在我的单元格顶部。为什么 ? enter image description here

编辑:

我的观点代码:

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/

相关文章:

ios - 如何实现两个 Storyboard? ios

objective-c - 如何在 Mac Os X 中向我的 cocoa 应用程序的屏幕添加信息

ios - 为什么 NSManagedObject 实例不持有对其 NSManagedObjectContext 的强引用?

ios - SwfUpload Flash uploader 在 IOS 中不可见且无法工作

ios - 非常大的 uiview 中的 drawrect 和内存不足

xcode - 每个没有 Navbar 或 Tabbar 的 View 都被下推 20px

ios - 即使启用了后台模式和推送通知,Firebase 电话身份验证也会在 iOS 上弹出一个 reCAPTCHA 验证窗口

ios - 将 subview 添加到 xib 文件

ios - 在 View 之间滑动

ios - 随机删除自定义 UIView Not Working swift 3