Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-13-2010, 10:25 PM   #1 (permalink)
College Student
 
ColouredRobot's Avatar
 
Join Date: Dec 2009
Location: Los Angeles, CA
Posts: 75
ColouredRobot is on a distinguished road
Default Add an PageControl to my Scroll View?!?!

I was wondering if anyone could walk me through the correct steps to add page control to my scroll view.

Below is my controller's implementation code for my scroll view


Code:
const CGFloat kScrollObjHeight	= 339.0;
const CGFloat kScrollObjWidth	= 320.0;
const NSUInteger kNumImages		= 8;

- (void)layoutScrollImages
{
		UIImageView *view = nil;
		NSArray *subviews = [scrollView1 subviews];
		
		// reposition all image subviews in a horizontal serial fashion
		CGFloat curXLoc = 0;
		for (view in subviews)
		{
				if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
				{
						CGRect frame = view.frame;
						frame.origin = CGPointMake(curXLoc, 0);
						view.frame = frame;
						
						curXLoc += (kScrollObjWidth);
				}
		}
		
		// set the content size so it can be scrollable
		[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
		// 1. setup the scrollview for multiple images and add it to the view controller
		//
		// note: the following can be done in Interface Builder, but we show this in code for clarity
		[scrollView1 setCanCancelContentTouches:NO];
		scrollView1.clipsToBounds = YES;		// default is NO, we want to restrict drawing within our scrollview
		scrollView1.scrollEnabled = YES;
		
		// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
		// if you want free-flowing scroll, don't set this property.
		scrollView1.pagingEnabled = YES;
		
		// load all the images from our bundle and add them to the scroll view
		NSUInteger i;
		for (i = 1; i <= kNumImages; i++)
		{
				NSString *imageName = [NSString stringWithFormat:@"step%d.png", i];
				UIImage *image = [UIImage imageNamed:imageName];
				UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
				
				// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
				CGRect rect = imageView.frame;
				rect.size.height = kScrollObjHeight;
				rect.size.width = kScrollObjWidth;
				imageView.frame = rect;
				imageView.tag = i;	// tag our images for later use when we place them in serial fashion
				[scrollView1 addSubview:imageView];
				[imageView release];
		}
		
		[self layoutScrollImages];	// now place the photos in serial layout within the scrollview
    [super viewDidLoad];
}
I was thinking that I'd just need to add a page control item in IB, set it to 8 pages, add an IB Outlet, what other items would I need to add in my header file?
__________________
-Coloured Robot

Have a quick minute? Wish you had a keyboard that let you type expressive messages with pictures and icons such asor? If you don't have emoticons installed on your iPhone, go get yourself a copy of Unpackr™ today! Unpackr™ outdates all other Emoji Apps!



-ColouredRobot™
ColouredRobot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 330
9 members and 321 guests
2Apps1Day, akacaj, Domele, michelle, NSString, SLIC, soohyun, Techgirl-52, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0