Sag*_*ari 65 iphone uitableview
默认情况下,uitableview中有一个单行分隔符.
但我想把我的自定义行作为分隔符.
可能吗?怎么样?
Dan*_*son 83
如果你想做的不仅仅是使用UITableView的separatorColor属性更改分隔符的颜色,那么你可以将separatorStyle属性设置为UITableViewCellSeparatorStyleNone,然后:
例如,如果您的表当前显示5行,则可以将其更新为显示9行,而索引1,3,5,7处的行将是分隔符单元格.
有关如何创建自定义UITableViewCell的更多信息,请参阅" 表视图编程指南"中的"对UITableViewCell进行子类化".
Jer*_*mps 34
更好的解决方案是使用单元格的当前宽度和高度.像这样的东西:
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
lineView.backgroundColor = [UIColor darkGrayColor];
[cell.contentView addSubview:lineView];
Run Code Online (Sandbox Code Playgroud)
Oli*_*ain 31
如果您需要不同行的不同分隔符颜色,或者您希望分隔突出显示行时分隔符保持可见,请尝试以下操作:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// We have to use the borderColor/Width as opposed to just setting the
// backgroundColor else the view becomes transparent and disappears during
// the cell's selected/highlighted animation
UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 1024, 1)];
separatorView.layer.borderColor = [UIColor redColor].CGColor;
separatorView.layer.borderWidth = 1.0;
[cell.contentView addSubview:separatorView];
Run Code Online (Sandbox Code Playgroud)
这假设您的单元格的背景颜色是透明的.
上述解决方案来自一些广泛的实验.以下是关于我的发现的一些注意事项,我相信我会帮助人们:
在正常的"未选择"状态
选择一个单元格,随后出现以下任何动画:
取消选择单元格后,将开始删除突出显示的动画:
mxc*_*xcl 13
这些答案导致突出显示rect被您添加到单元格的分隔符覆盖(至少在iOS 6上进行测试).您需要设置为separatorColor
以[UIColor clearColor]
使单元格仍然以1px分隔,然后您可以在间隙中绘制分隔符:
- (void)viewDidLoad {
self.tableView.separatorColor = [UIColor clearColor];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// snip
CALayer *separator = [CALayer layer];
separator.backgroundColor = [UIColor redColor].CGColor;
separator.frame = CGRectMake(0, 43, self.view.frame.size.width, 1);
[cell.layer addSublayer:separator];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
您添加cellForRowAtIndexPath
tableView 的以下代码委托来为每个单元创建1px高度和200px宽度的自定义图像视图
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, self.view.bounds.size.width, 1)];
lineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:lineView];
Run Code Online (Sandbox Code Playgroud)
注意:我不知道它在性能上有多重.
归档时间: |
|
查看次数: |
96659 次 |
最近记录: |