[在我的应用程序中,我正在创建混合UILabel
和UITextview
的视图控制器,由于文本是动态的并且还超出了垂直屏幕尺寸,因此它们希望可以滚动。
我目前拥有Scrollview,其子视图如下。在Xcode 4.3故事板。]中创建视图。
UILabel1(说标题)
UITextView1(可以是任意大小的动态文本)
UILabel2(第二个标题)
UITextView2(可以是任意大小的动态文本)
依此类推。
问题是
[UITextView1
具有更多内容时,它将与我不想要的UILabel2
重叠。
我想将UILabel1
放在scrollView的顶部,并将UITextView1
放在UILabel1
的下方。 UILabel2
下方的UITextView1
,依此类推。
我必须做什么才能实现这一目标?
编辑
在情节提要中
![在此处输入图片描述] [1]
在模拟器中
![在此处输入图片描述] [2]
感谢您的帮助。非常感谢。
代码
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [scrollView setScrollEnabled:YES]; [self.view addSubview:cockTailNameLabel]; [self.view insertSubview:txtIngredients belowSubview:cockTailNameLabel]; [self.view insertSubview:scrollView belowSubview:cockTailNameLabel]; //[scrollView] [self.cockTailNameLabel setText:self.passcockTailName]; [_txtUse setText:self.passUse]; [_txtUse setEditable:NO]; [_txtUse setUserInteractionEnabled:NO]; CGRect useFrame = _txtUse.frame; useFrame.size.height = _txtUse.contentSize.height; _txtUse.frame = useFrame; [txtIngredients setText:self.passIngredients]; [txtIngredients setEditable:NO]; [txtIngredients setUserInteractionEnabled:NO]; CGRect ingredientFrame = txtIngredients.frame; ingredientFrame.size.height = txtIngredients.contentSize.height; txtIngredients.frame = ingredientFrame; [txtRecipe setText:self.passReceipe]; [txtRecipe setEditable:NO]; [txtRecipe setUserInteractionEnabled:NO]; CGRect recipeFrame = txtIngredients.frame; recipeFrame.size.height = txtRecipe.contentSize.height; txtRecipe.frame = recipeFrame; [scrollView insertSubview:_txtUse belowSubview:cockTailNameLabel]; [scrollView insertSubview:titleIngredients belowSubview:_txtUse]; [scrollView insertSubview:txtIngredients belowSubview:titleIngredients]; [scrollView insertSubview:btnReceipe belowSubview:txtIngredients]; [scrollView insertSubview:btnHome belowSubview:txtIngredients]; [scrollView insertSubview:txtRecipe belowSubview:btnHome]; [scrollView insertSubview:btnfacebookShare belowSubview:txtRecipe]; [scrollView insertSubview:btnTwitterShare belowSubview:txtRecipe]; /*[scrollView addSubview:_txtUse]; [scrollView addSubview:titleIngredients]; [scrollView addSubview:txtIngredients]; [scrollView addSubview:btnReceipe]; [scrollView addSubview:btnHome]; [scrollView addSubview:txtRecipe]; [scrollView addSubview:btnfacebookShare]; [scrollView addSubview:btnTwitterShare];*/ [scrollView setContentSize:CGSizeMake(320, 1000)]; NSLog(@"RecipeName :%@ ",passcockTailName);
}
在我的应用程序中,我正在创建混合了UILabel和UITextview的视图控制器,由于文本是动态的并且还超出了垂直屏幕的尺寸,因此它们希望可以滚动。我目前有...
在情节提要或IB中,您可以自由地重新排列它们。
在代码中(在viewDidLoad中:)>
UIScrollView *scroll =[[UIScrollView alloc] initWithFrame:CGrectMake(0,0 320, 480)];
[self.view addSubview:scroll];
// code to init your UI object
UILabel *uilabel1 = [[UIlabel alloc] initWithFrame:CGrectMake(10,10, 100, 40)]; // example
uilabel1.font = [UIFont systemFontOfSize:10];
uilabel1.text = @"UILabel1";
uilabel1.backgroundColor = [UIColor clearColor];
//
//
UILabel *uilabel2 = [[UIlabel alloc] initWithFrame:CGrectMake(10, 10 + 10 + uilabel1.frame.origin.y, 100, 40)]; // example
uilabel2.font = [UIFont systemFontOfSize:10];
uilabel2.text = @"UILabel2";
uilabel2.backgroundColor = [UIColor clearColor];
//
//
[scroll addSubview:uilabel1];
[uilabel1 releale];
[scroll addSubview:uilabel2];
[uilabel2 releale];
//
//
// in end
float offset = 10.0 * 2; // offset between uiobjects, N - number of objects
scroll.contentSize = CGSizeMake (0, 0, uilabel1.frame.size.height + uilabel2.frame.size.height + offset, 320);
您可以像这样告诉下一个视图从第一个视图的结尾开始:
您的问题是标签出现在textview的顶部(重叠),对吗?
就我而言,我必须将其投影到父视图上,所以请记住也有一些东西,