0

我正在尝试添加一个UITextView. UIScrollview然后添加UIScrollViewUIView. 将 scrollView 添加到UIView有效但添加UITextView到 aUISCrollView不起作用。任何指针?

谢谢

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

3 回答 3

4

你的滚动视图的高度是 250,宽度也是 250。但是你给 textview 的框架超出了这些限制,即 300 和 400。将它们限制在 250、250 之类的

UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
于 2012-05-28T14:52:04.400 回答
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];
于 2012-05-28T15:51:51.107 回答
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];        
于 2014-12-31T09:08:06.920 回答