I have a UIScrollView and I wanted the frame height to adjust proportionally when I adjust the width, is this possible? Basically I am talking about auto adjusting the frame height of the UIScrollView when I adjust the width of the UIScrollView? I have tried setting the autoResizingMask to UIViewAutoresizingFlexibleWidth and height, but this doesn’t work
I have a UIScrollView and I wanted the frame height to adjust proportionally when
Share
I don’t think there’s an automatic way to do it. but you can added a UIView+SCaleAddition to do this:
@interface UIView(RespectScale) - (void)setWidthRespect:(float)w; - (void)setHeightRespect:(float)h; @end @implement UIView(RespectScale) - (void)setWidthRespect:(float)w { float scale = self.bounds.size.width / self.bounds.size.height; float h = w/scale; CGRect bounds = self.bounds bounds.size.width = w; bounds.size.height = h; self.bounds = bounds; } - (void)setHeightRespect:(float)h { // write it your own } @end