ios - How to set constraint for UIView to appear below the status bar in Swift? -


here case: have nib file custom uitoolbar. load nib file in uinavigationcontroller (so appear everywhere while user using app). however, when add subview, appears under status bar. , since new swift , constraints, need help, people :)

here code:

override func viewdidload() {     super.viewdidload();      var statusbarheight = uiapplication.sharedapplication().statusbarframe.size.height      var toolbarview = self.loadfromnibnamed("toolbarview")!      toolbarview.settranslatesautoresizingmaskintoconstraints(false);      self.view.addsubview(toolbarview);     self.view.bringsubviewtofront(toolbarview);     let statusbarconstraint = nslayoutconstraint(item: toolbarview, attribute: nslayoutattribute.top, relatedby: nslayoutrelation.equal, toitem: self.view, attribute: nslayoutattribute.top, multiplier: 1, constant: statusbarheight)      self.view.addconstraint(statusbarconstraint)     // additional setup after loading view. }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func loadfromnibnamed(nibnamed: string, bundle : nsbundle? = nil) -> uiview? {     return uinib(         nibname: nibnamed,         bundle: bundle         ).instantiatewithowner(self, options: nil)[0] as? uiview } 

how set subview appear right bellow status bar using nslayoutconstraint instead of changing frame's origin.y?


Comments