i have .xib file called "menu" file design view, init class doing following:
self.menuviewcontroller = [[twtmenuviewcontroller alloc] initwithnibname:@"menu" bundle:nil]; everything great the design visualized, size 600x600. how can it's full screen , adapts device screen size?
the nib uses autolayout , have constraints. want go full size , respect constrains.
set constraints superview or change frame (old way)
override func didmovetosuperview() { super.didmovetosuperview() self.translatesautoresizingmaskintoconstraints = false nslayoutconstraint(item: self.superview!, attribute: nslayoutattribute.width, relatedby: nslayoutrelation.equal, toitem: self, attribute: nslayoutattribute.width, multiplier: 1, constant: 0).active = true nslayoutconstraint(item: self.superview!, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: self, attribute: nslayoutattribute.height, multiplier: 1, constant: 0).active = true nslayoutconstraint(item: self.superview!, attribute: nslayoutattribute.left, relatedby: nslayoutrelation.equal, toitem: self, attribute: nslayoutattribute.left, multiplier: 1, constant: 0).active = true nslayoutconstraint(item: self.superview!, attribute: nslayoutattribute.bottom, relatedby: nslayoutrelation.equal, toitem: self, attribute: nslayoutattribute.bottom, multiplier: 1, constant: 0).active = true } old way:
- (void)layoutsubviews { cgrect fr = self.frame; fr.size = self.superview.frame.size; self.frame = fr; [super layoutsubviews]; } now autolayout constrains on view work.
Comments
Post a Comment