2011-08-24 140 views
1

我已经通过代码创建了一个UIView,并且希望在该视图上添加一些图像和说明。为此,我希望添加滚动视图,以便用户可以向下滚动到看到图像和description.Can任何人都可以帮助我如何通过代码添加UIView上方的滚动视图。提前感谢。在视图上方动态添加滚动视图iphone

回答

1

嗨试试这个: -

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; 
    scrollView.backgroundColor=[UIColor clearColor]; 
    scrollView.showsHorizontalScrollIndicator = NO; 
    [scrollView setDelegate:self]; 
    [scrollView setShowsVerticalScrollIndicator:NO]; 
    [scrollView setShowsHorizontalScrollIndicator:NO];  
    [[self view] addSubview:scrollView]; 

Now set the content size of scroll view:- 

     scrollView.contentSize = CGSizeMake(320, 600);//put values according to your requirements. 
+0

Thanku.but即时得到一个错误“不兼容的类型参数1“initWithFrame'.and一个警告‘未找到(返回类型默认为ID)’方法视图。你能帮我解决这个问题 – ishhhh

+0

你在哪种方法中加入这段代码 – Gypsa

+0

是你在哪个类中加入了这个UIViewController类型或UIView类型。 – Gypsa

0
UIScrollView *newView = [[UIScrollView alloc] initWithFrame:scrollFrame]; 
    [newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; 
    [newView setDelegate:self]; 
    [newView setBackgroundColor:backgroundColor]; 
    [newView setPagingEnabled:YES]; 
    [newView setShowsVerticalScrollIndicator:NO]; 
    [newView setShowsHorizontalScrollIndicator:NO]; 

    [[self view] addSubview:newView]; 

您可以设置框架代替scrollFrame。

欢呼

0

其实你可能不希望创建一个UIView,你应该创建一个UIScrollView然后添加图像和作为UIScrollView的子视图。那么你将有一切滚动。然后,您将按照您希望的方式设置UIScrollView。