Reputation: 6130
I have a UIView
which I need to stretch to the width of a UIScrollView
. The problem is the next:
I'd need to stretch that UIView (which is EGOTableViewPullRefresh, just a custom UIView). In the view initialization I put
[_refreshHeaderView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
. I tried:
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidZoom");
[_refreshHeaderView setFrame:CGRectMake(0.0f, 0.0f - webScroller.bounds.size.height, webScroller.frame.size.width, webScroller.bounds.size.height)];
}
But it just looks as the image. If I enter to a iOS designed page (such as Mobile Google), it looks ok:
How can I do that?
Upvotes: 0
Views: 3904
Reputation: 23223
The size.width
of a UIScrollView
is width of the view on your device, not the width of the contents inside the scroll view (which would be scrollView.contentSize.width
).
This means, if "your view" is outside the UIScrollView
you do want the scroll view width, but if your view is inside the scroll view you need the content width.
Notice the bottom/Google screenshot you provided. Notice how there is no horizontal scrolling? In this case the scroll view contents size width is the same as the scroll view width so it works perfectly. The upper/stack overflow image does have a horizontal scroll bar though. So the content width of the scroll view is bigger than the scroll view width.
Short answer: Try setting your view to be the scrollView.contentSize.width
, not scrollView.frame.size.width
Upvotes: 2