有没有办法像UITableView的分隔符一样创建分隔符视图?

时间:2015-06-16 10:02:50

标签: ios objective-c uitableview ios7

我想像这样自定义分隔线视图,但我仍然被困在这里。 Facebook应用程序使分隔线视图很好看。我想存档这样的东西。任何人都可以帮助我吗?

我尝试使用设置框架和更新约束,但它不适用于所有设备(iPhone 4s,iPhone 5,iPhone 6,iPhone 6 Plus)。

我使用UIView的约束和自定义框架使其像分隔线视图一样工作,约束的常量或框架高度的高度为0.5。但它不喜欢UITableView分隔符。像Facebook应用程序那样高度不是很薄,有时也没有显示。

由于

4 个答案:

答案 0 :(得分:1)

UIView * separtor = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 1)];
            separtor.backgroundColor = [UIColor whiteColor];
            [cell.contentView addSubview:separtor];

答案 1 :(得分:0)

你好,

您仍然可以使用您想要的背景颜色添加非常薄且空的UIView

答案 2 :(得分:0)

创建自定义单元格/原型单元格并根据需要进行设计。

在设计的自定义单元格的底部,添加一个视图(最小恒定高度),并根据UI需要设置其大小颜色和其他参数。

为它设置约束(首选为分隔符视图提供预定义的高度),以便视觉效果相同并采用不同设备的宽度。

最后,删除将由表视图设置的默认分隔符。

即:为表视图设置'separator'属性为'None'。

答案 3 :(得分:0)

试试这个

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 3)];/// change size as you need.       
 separatorLineView.backgroundColor = [UIColor whiteColor];// you can also put image here
 [cell.contentView addSubview:separatorLineView];

希望有所帮助

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;


UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 3)];/// change height as you need.       
 separatorLineView.backgroundColor = [UIColor whiteColor];// you can also put image here
 [cell.contentView addSubview:separatorLineView];