2011-08-24 181 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。