Reputation: 16859
I have gone through many tutorials but most of them tell how to add a UIScrollView
using the interface builder. I need to add a scrollview using code. I went through several tutorials and what they did was they add the UIView
to the UIScrollView
. [scrollView addSubView:myView];
simple as that ad connect to using interface builder.
Can someone please guide me as in how to add a UIScrollView
using code (Only Code)
Upvotes: 0
Views: 146
Reputation: 536047
All my examples use code rather than the nib - it's way easier to create and configure a scroll view in code! See here:
https://github.com/mattneub/Programming-iOS-4-Book-Examples/tree/master/convertedToIOS5
The scroll view examples start with p482p494scrollViewInCode.
Upvotes: 1
Reputation: 4950
Is really simple:
UIScrollView * scroller = [[[UIScrollView alloc] initWithFrame:CGTectMake(0, 0, 320, 480)] autorelease];
[self.view addSubview:scroller];
int x = 0;
for (int i = 0; i < 5; i++){
UIView * myview = [[[UIView alloc] initWithFrame:CGRectMake(x, 0, 320, 480)] autorelease];
[scroller addSubview:myView];
x += myView.frame.size.width;
}
[scroller setContentSize:CGSizeMake(x, 480)];
This code was compiled in my head, so sorry if there is a sintax mistake.
Upvotes: 1