ios - Xcode Auto Layout with custom view -
i working on first project using auto layout , custom views. question this:
i created custom view in interface builder added constraints stretch view if needed working way want to, however, consider following code snippet custom view class -
// mycustomview
-(id)initwithcoder:(nscoder*)decoder { self = [super initwithcoder:decoder]; if(self != nil) { cgfloat layerwidth = self.bounds.size.width; cgfloat layerheight = self.bounds.size.height; } return self; } this code return size set in ib. drawing code relies on new width , height (if view has been stretched) don't know how retrieve them.
first, code utterly silly because creating variables layerwidth , layerheight , throwing them away, pointless.
second, self.bounds.size view's width , height. however, pointless ask in initwithcoder:, (as have rightly seen) happens long before view put interface , longer before auto layout takes place resizes it. if drawing code relies on bounds size, retrieve bounds size when draw. if need draw again because view has changed size, , if not happening itself, implement layoutsubviews tell view needs drawn again.
Comments
Post a Comment