0

示例图像

如何创建此视图。添加滚动视图的代码

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];



    }

这里 ssview 高度大于 timeview.so 它也被添加到下一个子视图

这里每一行都是滚动视图的子视图。现在我必须添加另一个绿色视图。

4

2 回答 2

1
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

}
于 2013-08-21T12:19:46.330 回答
0

我有你的问题。它不会与您的下一个单元格重叠,因为您的下一个单元格位于您的前一个单元格上并与前一个单元格的边缘重叠。尝试:从超级视图中删除单元格(将具有绿色视图)并再次添加绿色视图:

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];
}
于 2013-08-21T12:55:58.517 回答