2012-05-28 95 views
0

我想在UIScrollview上添加UITextView。然後將UIScrollView添加到UIView。添加scrollView到UIView工作,但將UITextView添加到UISCrollView不起作用。任何指針?在UIScrollView上添加UITextView/UILabel

感謝

UIScrollView * contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(300, 400, 250, 250)]; 
contentScrollView.backgroundColor = [UIColor whiteColor]; 
UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(300, 400, 200, 200)]; 
mainContent.text = @"HELLO"; 
mainContent.textColor = [UIColor blackColor]; 
[contentScrollView addSubview:mainContent]; 
[contentScrollView setUserInteractionEnabled:YES]; 
[contentView addSubview:contentScrollView]; 

回答

4

您scrol鑑於高度250和寬度也250但你是給的TextView的框架超出這些限制,即300和400,限制在250,250像

UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; 
+0

哦,所以拉布勒的位置是相對的UIScrollView?我認爲這是相對於主屏幕。安斯是有效的。謝謝:) – CodeGeek123

+0

沒有。它應該是相對於每個事物的父/超視圖 – Saad

2

使用此代碼:

UIScrollView * contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, 320, 270)]; 
contentScrollView.backgroundColor = [UIColor whiteColor]; 
[contentScrollView setUserInteractionEnabled:YES];  

UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(60, 30, 200, 200)]; 
mainContent.text = @"HELLO"; 
mainContent.textColor = [UIColor blackColor]; 

[contentScrollView addSubview:mainContent];   
[self.view addSubview:contentScrollView]; 
1

使用這種技術

UIScrollView * contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, 320, 270)]; 

,並將其添加到您的UIScrollView,如:

UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; 
contentScrollView.backgroundColor = [UIColor whiteColor]; 
[contentScrollView setUserInteractionEnabled:YES];  
[contentScrollView addSubview:mainContent];