在UIScrollView上添加UITextView/UILabel
问题描述:
我想在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];
答
您scrol鉴于高度250和宽度也250但你是给的TextView的框架超出这些限制,即300和400,限制在250,250像
UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
答
使用此代码:
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];
答
使用这种技术
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];
哦,所以拉布勒的位置是相对的UIScrollView?我认为这是相对于主屏幕。安斯是有效的。谢谢:) – CodeGeek123
没有。它应该是相对于每个事物的父/超视图 – Saad