2013-04-07 116 views
0

所以我創建了一個UITextView並將它放在UIScrollView中。但是,我禁用滾動UITextView,所以我想知道是否有可能在滾動瀏覽我的UIScrollView的同時滾動textview?用UIScrollview滾動UITextview

我不確定是否有人已經問過這樣的問題,我試圖通過網站搜索,找不到與我的問題有關的任何主題。如果有這樣一個現有的職位,我會很感激,如果有人指責我。

+0

所以你想了'UIScrollView'的滾動綁定到'UITextView'? – 2013-04-08 00:06:16

+0

是的差不多那 – 2013-04-08 03:03:00

回答

1

UIScrollView是滾動UIView。所以,你只需要到UITextView添加滾動視圖作爲一個子視圖,它會用它滾動,基本上是這樣的:

UIScrollView *scrollView = [UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,460)];//adjust the frame to fit your needs 
scrollView.contentSize = CGSizeMake(400, 600);//make sure the size in contentSize is bigger than the size of the scrollView frame: (400, 600) is bigger than (320, 460), otherwise the scroll effect won't be performed 
UITextView *textView = [UITextView alloc]initWithFrame:CGRectMake(0,0,200,400)];//adjust the frame to fit your needs 
[scrollView addSubview:textView];//need to add the text view as a subview 
[self.view addSubview:scrollView]; 
+0

還需要設置滾動視圖的contentSize。如果contentSize小於滾動視圖的大小,則不會發生滾動。 – user523234 2013-04-08 01:54:11

+0

感謝您的回答,但是您能否詳述一下contentSize?對不起,我是新編輯的客戶端C – 2013-04-08 03:02:05

+0

,@ user523234 thanx。 – Malloc 2013-04-08 17:20:26