2011-03-09 59 views
0

我想在ViewController中添加滚动视图。我已经通过代码创建了viewcontroller。如何在viewcontroller上添加滚动视图?

secondView = [[SecondView alloc] initWithNibName:@"second" bundle:nil]; 

现在我想在视图控制器上添加滚动视图。可能吗 ?

回答

3

耶有可能滚动视图添加到您的视图 - 控制。

按照此,它可以帮助你

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]; 

好运..在你SecondView类的viewDidLoad以下

+0

仍然无法正常工作......还有一个基于导航的... [self.navigationController pushViewController:secondView animated:YES]; – Maulik 2011-03-09 09:21:44

+0

@maulik:试试这个.. [secondview.view addSubview:scroll]; \t \t \t \t [滚动发布]; – kanmani 2011-03-09 09:27:13

+0

@maulik:我给出的上述代码对我来说效果很好..让我知道如果你有任何澄清.. – kanmani 2011-03-09 09:31:31

3

[viewController.view addSubview:滚动视图]

0

认沽

-(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]; 
} 
相关问题