views:

165

answers:

1

hi,

i am setting the size of a UIScrollView in viewDidLoad: but when I try to get the height of it, i am getting 0 in the console

here is my code:

- (void)viewDidLoad {
    [scrollView setContentSize:CGSizeMake(320,500)];

    NSLog(@"scrollView: %@", scrollView);
    NSLog(@"scrollView.contentSize.height: %i", scrollView.contentSize.height);

    [super viewDidLoad];
}

and in the console log i get

scrollView: <UIScrollView: 0x4974110; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = RM+TM; layer = <CALayer: 0x4974010>>
scrollView.contentSize.height: 0

Shouldn't scrollView.contentSize.height be returning 367? On a related note, i specified the height to be 500 via [scrollView setContentSize:], but that doesn't appear to be applied either?

+1  A: 

No. The contentSize is the size of the stuff inside the scrollview. Since nothing is inside the scrollview (ie you're not scrolling anything), the height is 0. The only way to get a valid contentSize is after you've added a subview.

Dave DeLong