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 Tutorials > Tutorial Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 02-01-2010, 12:58 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 24
iamsgtyang is on a distinguished road
Default UIScrollView tutorial w/o IB

Created my tutorial here and you can download the source code too.

I will add more to this tutorial as I have time such as how to add views and additional properties for the UIScrollView and such. I say download the source code for the commented directions and details.


How to create a UIScrollView and set it’s size and content.

1. Create an iPhone app with Xcode using View-based Application and name it ScrollViewTutorial.

2. Open up ScrollViewTutorialViewController.h and add these two lins:
UIScrollView *myScrollView;

@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView;
The final ScrollViewTutorialViewController.h file should look like this:
#import <UIKit/UIKit.h>

@interface ScrollViewTutorialViewController : UIViewController {
UIScrollView *myScrollView;
}

@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView;

@end
3. Now lets add open up ScrollViewTutorialViewController.m and add these lines:
@synthesize myScrollView;

myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(960, 480);
myScrollView.pagingEnabled = TRUE;
myScrollView.scrollEnabled = FALSE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];

[myScrollView release];
The final ScrollViewTutorialViewController.m file should look like this:
#import “ ScrollViewTutorialViewController.h”

@implementation ScrollViewTutorialViewController

@synthesize myScrollView; // don’t forget to synthesize your UIViewController

- (void)viewDidLoad {
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(960, 480);
myScrollView.pagingEnabled = FALSE;
myScrollView.scrollEnabled = TRUE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
}

- (void)dealloc {
[myScrollView release];
[super dealloc];
}

@end
There you go. Creating a UIScrollView with size of the iPhone screen and *content* size of 3 pages.

Last edited by iamsgtyang; 02-01-2010 at 01:01 AM.
iamsgtyang is offline   Reply With Quote
Old 07-23-2010, 11:12 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 3
iphoneDevNoob is on a distinguished road
Default

Quote:
Originally Posted by iamsgtyang View Post
Created my tutorial here and you can download the source code too.

I will add more to this tutorial as I have time such as how to add views and additional properties for the UIScrollView and such. I say download the source code for the commented directions and details.


How to create a UIScrollView and set it’s size and content.

1. Create an iPhone app with Xcode using View-based Application and name it ScrollViewTutorial.

2. Open up ScrollViewTutorialViewController.h and add these two lins:
UIScrollView *myScrollView;

@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView;
The final ScrollViewTutorialViewController.h file should look like this:
#import <UIKit/UIKit.h>

@interface ScrollViewTutorialViewController : UIViewController {
UIScrollView *myScrollView;
}

@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView;

@end
3. Now lets add open up ScrollViewTutorialViewController.m and add these lines:
@synthesize myScrollView;

myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(960, 480);
myScrollView.pagingEnabled = TRUE;
myScrollView.scrollEnabled = FALSE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];

[myScrollView release];
The final ScrollViewTutorialViewController.m file should look like this:
#import “ ScrollViewTutorialViewController.h”

@implementation ScrollViewTutorialViewController

@synthesize myScrollView; // don’t forget to synthesize your UIViewController

- (void)viewDidLoad {
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView.contentSize = CGSizeMake(960, 480);
myScrollView.pagingEnabled = FALSE;
myScrollView.scrollEnabled = TRUE;
myScrollView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:myScrollView];
}

- (void)dealloc {
[myScrollView release];
[super dealloc];
}

@end
There you go. Creating a UIScrollView with size of the iPhone screen and *content* size of 3 pages.
Hello,

You code works beautifully but i'm getting some image pixelation when I zoom in. How do I fix that?

Thanks
iphoneDevNoob 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
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,959
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

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