Skip to content

Instantly share code, notes, and snippets.

@tibr
Created August 8, 2013 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tibr/6187127 to your computer and use it in GitHub Desktop.
Save tibr/6187127 to your computer and use it in GitHub Desktop.
UIScrollView needs a subview with an absolute width value to use it's full width as contentSize. I'm trying to use a helper view here to make sure it always uses it's own width as it's content width. https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/
UIView *scrollViewWidthEnforcer = [UIView new];
[scrollViewWidthEnforcer setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.scrollView addSubview:scrollViewWidthEnforcer];
[self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[enforcer(==scrollView)]|"
options:0
metrics:nil
views:@{
@"enforcer" : scrollViewWidthEnforcer,
@"scrollView" : self.scrollView
}]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment