Search code examples
iosuiviewnibibdesignable

Content of uiview from nib is outside container


I want to insert a custom UIView in a custom UITableViewCell. I have created a nib file with some actions and I want to put this view at the bottom of my cell but the content displays on the top of my cell. Why ? enter image description here

EDIT :

Code of my 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
}

Solution

  • I resolve my problem. I put this line :

    view.translatesAutoresizingMaskIntoConstraints = true