Friday, January 28, 2011

ScrollView and Zooming in iphone

1.create a view based app, name it as you like...total 4 files will be generated in view based app, 2 for appdelegate class and 2 view controller class.

2.In viewcontroller.h file, declare a UIImageview instance variable and property for it.
UIImageView *imageView;
@property(nonatomic,retain) UIImageView *imageView;

3.synthesis the property in viewcontroller.m file.
@synthesize imageView;

4.In viewdidLoad method.
- (void)viewDidLoad {

[super viewDidLoad];

UIImage *image=[UIImage imageNamed:@"20.jpg"];

imageView=[[UIImageView alloc] initWithImage:image];

[self.view addSubview:imageView];

[(UIScrollView *) self.view setContentSize:[image size]];

[(UIScrollView *) self.view setMaximumZoomScale:2.0];

}


5.For Zooming implement this method.

- (UIView *)viewForZoomingInScrollView:(UIScrollView*)scrollView

{

return imageView;

}


6.Open the viewcontroller.xib file,palce UIImage view from library to the view and give necessary connections to it.(delegate).


7.Then build and run the app.


No comments:

Post a Comment