对于我的设计规范,我的表格视图应该只有顶部、左侧和右侧三个边框。我已经使用以下代码添加了它....
CGSize mainViewSize = menu_table.bounds.size;
CGFloat borderWidth = 1;
UIColor *borderColor = [UIColor lightGrayColor];
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, borderWidth, mainViewSize.height)];
UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(mainViewSize.width - borderWidth, 0, borderWidth, mainViewSize.height)];
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mainViewSize.width, borderWidth)];
leftView.opaque = YES;
rightView.opaque = YES;
topView.opaque = YES;
leftView.backgroundColor = borderColor;
rightView.backgroundColor = borderColor;
topView.backgroundColor = borderColor;
// for bonus points, set the views' autoresizing mask so they'll stay with the edges:
leftView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin;
rightView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin;
topView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
[menu_table addSubview:leftView];
[menu_table addSubview:rightView];
[menu_table addSubview:topView];
它工作正常,但是当我滚动表格时,添加的子视图也向上移动。我不确定为什么子视图随着单元格移动而不是它应该用表格修复,知道问题是什么以及如何用表格视图大小修复它。谢谢。