ios - UIViewController: adjust contraints of xib -
in project defined xib , viewcontroller contain xib.
class feeddetailviewcontroller: uiviewcontroller, feeddetaildelegate { var feeddetail: feeddetail! override func viewdidload() { super.viewdidload() feeddetail = (nsbundle.mainbundle().loadnibnamed("feeddetail", owner: self, options: nil)[0] as? uiview)! as! feeddetail feeddetail.delegate = self; self.view.addsubview(feeddetail) self.adjustcontraints() } func adjustcontraints() { feeddetail.sizethatfits(self.view.frame.size) var constraint = nslayoutconstraint(item: feeddetail, attribute: nslayoutattribute.bottom, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.bottom, multiplier: 1, constant: 0) view.addconstraint(constraint) constraint = nslayoutconstraint(item: feeddetail, attribute: nslayoutattribute.top, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.top, multiplier: 1, constant: 0) view.addconstraint(constraint) constraint = nslayoutconstraint(item: feeddetail, attribute: nslayoutattribute.trailing, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.trailing, multiplier: 1, constant: 0) view.addconstraint(constraint) constraint = nslayoutconstraint(item: feeddetail, attribute: nslayoutattribute.leading, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.leading, multiplier: 1, constant: 0) view.addconstraint(constraint) self.view.layoutifneeded() }
what want xib @ "fullscreen", xib borders not "sticked" main view of controller.
border legend:
- red: self.view
- yellow: feeddetail
- others: element inside feeddetail (test only)
try call method before adding constraints.
feeddetail.settranslatesautoresizingmaskintoconstraints(false)
Comments
Post a Comment