Created
May 14, 2013 07:47
-
-
Save lexrus/5574347 to your computer and use it in GitHub Desktop.
LTScrollView.m set contentSize that fit the contents of UIScrollView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "LTScrollView.h" | |
@implementation LTScrollView | |
- (void)layoutSubviews | |
{ | |
CGFloat perfectContentWidth = 0.0f; | |
CGFloat perfectContentHeight = 0.0f; | |
BOOL isHorizontalScrollIndicatorVisible = self.showsHorizontalScrollIndicator; | |
BOOL isVerticalScrollIndicatorVisible = self.showsVerticalScrollIndicator; | |
self.showsHorizontalScrollIndicator = self.showsVerticalScrollIndicator = NO; | |
for (UIView *view in self.subviews) { | |
if (!view.hidden) { | |
CGFloat x = view.frame.origin.x; | |
CGFloat y = view.frame.origin.y; | |
CGFloat w = view.frame.size.width; | |
CGFloat h = view.frame.size.height; | |
if (x + w > perfectContentWidth) { | |
perfectContentWidth = x + w; | |
} | |
if (y + h > perfectContentHeight) { | |
perfectContentHeight = y + h; | |
} | |
} | |
} | |
self.showsHorizontalScrollIndicator = isHorizontalScrollIndicatorVisible; | |
self.showsVerticalScrollIndicator = isVerticalScrollIndicatorVisible; | |
[self setContentSize:CGSizeMake(perfectContentWidth, perfectContentHeight)]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment