我想将Scroll View添加到ViewController中。我已经通过代码创建了viewcontroller。
secondView = [[SecondView alloc] initWithNibName:@"second" bundle:nil];
现在我想在视图控制器上添加滚动视图。有可能吗?
答案 0 :(得分:3)
[viewController.view addSubview:scrollView]
答案 1 :(得分:3)
是的,可以将scrollview添加到viewcontroller。
按照这个,它可能会帮助你
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];
修改强>
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];
祝你好运..
答案 2 :(得分:0)
将以下内容放在SecondView类的viewDidLoad中
-(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];
}