Re: UIScrollView Sizing
Re: UIScrollView Sizing
- Subject: Re: UIScrollView Sizing
- From: Fritz Anderson <email@hidden>
- Date: Tue, 27 Apr 2010 16:06:40 -0500
On 27 Apr 2010, at 12:58 PM, Bob Barnes wrote:
> I have a UIScrollView that can contain a variable number of other UIViews (UILabels, UIImageViews, etc), but I'm confused as to how to manage the UIScrollView contentSize given the variability in the number of views it will contain. I'd like to use IB to create my view, but is this type of view better suiting to being built programmatically? UIScrollViews with variable content seems like a rather common paradigm and I'm wondering how folks approach this type of UI.
Pseudocode, written in Mail. I have code that does this right, but I don't have access to it just now. Expect to debug, or to get a better answer from someone else:
#define VIEW_WIDTH 320.0
// or whatever
UIScrollView * scrollView = ...
CGSize totalSize = { VIEW_WIDTH, 0.0 };
// Assuming you want to stack the views vertically
for (each view I want to add) {
UIView * aView = [[AViewClass alloc] init...];
// ... other initialization that sets bounds
[scrollView addSubview: aView];
CGRect frameRect = aView.frame;
frameRect.origin.y = totalSize.height;
aView.frame = frameRect;
totalSize.height = CGRectGetMaxY(frameRect);
}
scrollView.contentSize = totalSize;
/* Reiterate disclaimers */
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden