![](/img/trans.png)
[英]How to round a single corner of an image used in a Grouped-style UITableView on iPhone
[英]Removing cell borders from a section of grouped-style UITableView
我有一个UITableViewController初始化与分组样式,并有多个部分。 对于其中一个部分,我希望它的组成单元格完全透明并且没有边框。 我计划为此部分中的每一行分配一个自定义视图,但是由分组的表格单元格包围的自定义视图看起来很糟糕:(
以下使得单元格的背景颜色变为黑色而不是透明......我仍然不知道如何摆脱边框。
cell.backgroundColor = [UIColor clearColor];
有什么指针吗? 谢谢!
注意:这似乎不适用于iOS7及更高版本。 对于iOS7,请尝试这个答案。
对于iOS6及更低版本,要从分组表格视图单元格中的单元格中删除分组背景:
这没用
cell.backgroundView = nil; // Did Not Work
这样做了
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
如果你已经转移到ARC (我听说这有效,但还没有测试过)
cell.backgroundView = [UIView new];
你必须实际设置
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
去除细胞边界。
以下hack适用于iOS 7 - 目前。 :)
子类UITableViewCell
,并将此单元格用于不应具有分隔符的部分。
覆盖单元子类中的addSubview
方法:
-(void)addSubview:(UIView *)view
{
// The separator has a height of 0.5pt on a retina display and 1pt on non-retina.
// Prevent subviews with this height from being added.
if (CGRectGetHeight(view.frame)*[UIScreen mainScreen].scale == 1)
{
return;
}
[super addSubview:view];
}
这适用于具有分组样式表的情况
[tableView setSeparatorColor:[UIColor clearColor]];
这段代码对我有用:)
[self.tableView setSeparatorColor:[UIColor clearColor]];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
将单元格的backgroundView设置为nil。 对于分组表,单元格图像是该视图的一部分。
尝试使用tableView.separatorColor = [UIColor clearColor];
并且,不要使用tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
我测试了两者,如果样式为无,则使截面边框不可见不起作用,而只是更改其颜色,并且截面边框将显示为无。
iOS似乎区分了使对象无,并使对象透明
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cell.backgroundView = [UIView new];
奇迹般有效! 经测试! iOS6的
从iOS 8开始,将separator属性设置为none也可以。
设置内容视图也可以摆脱边框。 将自定义视图设置为cell.contentView。
从分组样式UITableView的一部分中删除单元格边框的最简单方法:
[tableViewOutlet setBackgroundView:nil];
在viewDidLoad方法中。
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
cell.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:imageView];
如果您有自定义UITableCellView,则可以在视图中添加以下方法以删除背景视图。
- (void)setBackgroundView:(UIView *)backgroundView
{
// We don't want background views for this cell.
[super setBackgroundView:nil];
}
我只是认为我会将我的评论转换成@Intentss到一个答案,因为它可能对那些人有用,使用他的解决方案。
使用带有分组UITabelView的iOS6.1,使用ARC:
[tableView setSeparatorColor:[UIColor clearColor]];
不行
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
有用吗
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.