[英]how to add subview to subviews of scroll view
how create this view. 如何创建此视图。 code for adding scroll view
用于添加滚动视图的代码
yPos=0;
for (int i=0; i<24; i++) {
UIView *timeView=[[UIView alloc]initWithFrame:CGRectMake(71, yPos, 909, 60)];
timeView.userInteractionEnabled=TRUE;
timeView.exclusiveTouch=YES;
if (i==4) {
UIView *ssview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 80)];
ssview.tag=1;
ssview.userInteractionEnabled=TRUE;
UILabel *recurenceId=[[UILabel alloc]init];
recurenceId.text=@"A12334";
[ssview addSubview:recurenceId];
ssview.backgroundColor=[UIColor orangeColor];
[timeView addSubview:ssview];
[ssview addGestureRecognizer:tap];
}
here ssview height is more than timeview.so it be added to next subview also 这里ssview的高度大于timeview.so,所以它也被添加到下一个子视图中
here every row is a subview of scroll view. 这里的每一行都是滚动视图的子视图。 Now i have to addd another view which is in green color.
现在我必须添加另一个绿色的视图。
NSArray *greenViewsIndexes=[NSArray arrayWithObjects:[NSNumber numberWithInt:5],[NSNumber numberWithInt:6],[NSNumber numberWithInt:11],[NSNumber numberWithInt:12], nil];
for (int i=0; i<24; i++) {
for (int j=0; j>greenViews.count; j++) {
if ([[greenViews objectAtIndex:j]intValue]==i){
UIView *greenView=[[UIView alloc]initWithFrame:CGRectMake(71,61*(j+1),100,80)];
[greenView setBackgroundColor:[UIColor greenColor]];
}
}
//another operations
}
I got you problem. 我有问题 It's not overlap your next cell, because your next cell lie on your previous cell and overlap previous cell's edge.
它不与您的下一个单元格重叠,因为您的下一个单元格位于上一个单元格上,并且与上一个单元格的边缘重叠。 Try to: remove cell (which will has a green view) from super view and add again with green view:
尝试:从超级视图中删除单元格(将具有绿色视图),然后使用绿色视图再次添加:
NSArray *greenViewsIndexes=[NSArray arrayWithObjects:[NSNumber numberWithInt:5],[NSNumber numberWithInt:11], nil];
for (int i=0; i<greenViewsIndexes.count; i++) {
int j=[[greenViewsIndexes objectAtIndex:i]intValue];
[[self.view subviews] objectAtIndex:i] removeFromSuperView]
UIView *timeView=[[UIView alloc]initWithFrame:CGRectMake(71, 61*(j+1), 909, 60)]; //set your values
timeView.userInteractionEnabled=TRUE;
timeView.exclusiveTouch=YES;
UIView *greenView=[[UIView alloc]initWithFrame:CGRectMake(71,61*(j+1),100,80)]; //set yourValues
[greenView setBackgroundColor:[UIColor greenColor]];
[timeView addSubview:greenView];
[self.view addSubview:timeView];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.