Illep
Illep

Reputation: 16841

Adding a scrollView

I have a scrollview and its initialize as this ;

scrollV = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

Later in the application i add a UIView, and i need the UIView to take the height and width of the scrollView. (Since a scrollView can very in its length i can't hard code the value)

So i tried this ;

justAnotherView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.scrollV.frame.size.width, self.scrollV.frame.size.height)]; 

But, it isn't taking the size of the scrollview (the total size of the scrollview). It only shows part of the screen (width 320 and height 460). Is this because of the scrollV initialization statement i wrote above ? How can i correct this ?

Upvotes: 0

Views: 104

Answers (3)

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29965

You may want to use the contentSize property of the UIScrollView instead.

... initWithFrame:CGMakeRect(0,0,scrollV.contentSize.width, scrollV.contentSize.height) ...

Upvotes: 1

Fernando Valente
Fernando Valente

Reputation: 1096

How about

justAnotherView = [[UIView alloc] initWithFrame:self.scrollV.frame];

Upvotes: 0

Jeremy
Jeremy

Reputation: 9010

I assume you added justAnotherView as a subview to scrollV:

Just as you did for justAnotherView, you should set scrollV's point and size relative to its parent. It should look something like this:

scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,parent.frame.size.width,parent.frame.size.height)];

Upvotes: 0

Related Questions