PDA

View Full Version : UIScrollView in UITabBarController




psudheer28
Aug 20, 2010, 01:46 AM
Hi all,

thanks in advance,

i am developing an application by using Tab Bar application, with navigation controller.

In first view controller i am displaying table view, after selecting the cell, it will navigates to another view controller, there i have to use UIScrollView.

in scroll view i have taken the frame width and height is 320 and 650, in this scroll view i have to display webimage below that i have to show description of the image in UITextView in remaining space of the scroll view.

how to add these webimage and textview in scrollview, and how to use the scroll view.

plz suggest me

sudheer,:(:confused:



ianray
Aug 20, 2010, 06:34 PM
Hi! Make a new subclass of UIViewController, for example "PageViewController", and programmatically add the required views.

I stripped the code down to the smallest possible working example, but you will need to take care of memory leaks etc.

#import <UIKit/UIKit.h>

@interface PageController : UIViewController {
UIImageView *imageView;
UITextView *textView;
}

@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UITextView *textView;

@end

#import "PageController.h"

@implementation PageController

@synthesize imageView;
@synthesize textView;

- (void)loadView {

UIScrollView *contentView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView setContentSize:CGSizeMake(320, 650 + 100)];

CGRect r;
r.origin.x = 0;
r.origin.y = 0;
r.size.width = 320;
r.size.height = 650;
imageView = [[UIImageView alloc] initWithFrame:r];
imageView.image = [UIImage imageNamed:@"apple.jpg"];

r.origin.y = 650;
r.size.height = 100;
textView = [[UITextView alloc] initWithFrame:r];
textView.backgroundColor = [UIColor blueColor];
textView.text = @"Hello, world";

[contentView addSubview:imageView];
[contentView addSubview:textView];

self.view = contentView;
[contentView release];
}

- (void)dealloc {
[imageView removeFromSuperview];
[textView removeFromSuperview];
self.imageView = nil;
self.textView = nil;
[super dealloc];
}

@end


Hope this helps :)