how to add scroll view on viewcontroller?
I want to add Scroll View into ViewController. I have created viewcontroller by code.
secondView = [[SecondView alloc] initWithNibName:@"second" bundle:nil];
Now i want to add scroll开发者_StackOverflow中文版 view on view controller. is it possible ?
yeah it's possible to add scrollview to your viewcontroller.
Follow this,it might help you
CGRect rect=CGRectMake(0,0,320,480);
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:rect];
scroll.contentSize = CGSizeMake(320, 400);
scroll.showsHorizontalScrollIndicator = YES;
[self.secondview addSubview:scroll];
Edit:
SecondView *secondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:secondView animated:YES];
CGRect frame = CGRectMake(0,0,320,600);
scroll = [[UIScrollView alloc] initWithFrame:frame];
scroll.contentSize = CGSizeMake(secondView.bounds);
scroll.showsHorizontalScrollIndicator = YES;
scroll.showsVerticalScrollIndicator = YES;
[secondView.view addSubview:scroll];
[scroll release];
Good Luck..
[viewController.view addSubview:scrollView]
Put following in viewDidLoad of your SecondView class
-(void)viewDidLoad{
[super viewDidLoad];
CGRect frame = CGRectMake(0,0,320,600);
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:frame];
scroll.contentSize = CGSizeMake(secondView.bounds);
scroll.showsHorizontalScrollIndicator = YES;
scroll.showsVerticalScrollIndicator = YES;
[secondView.view addSubview:scroll];
[scroll release];
}
精彩评论