如何删除 iOS TableView 分隔符
How to remove iOS TableView Separator
您好,感谢阅读。
一段时间以来,我一直试图删除这些分隔符,太糟糕了,我无法删除它们。我在 Whosebug 中尝试了很多答案,但没有人有帮助:/
这是问题所在:
我无法删除单元格之间的这些白色 spaces:s。
我试过了:
- 将背景颜色更改为与单元格相同的灰色,但它不起作用
- 检查单元格大小
- 将 separatorStyle 设置为 UITableViewCellSeparatorStyle.None
- 使用 tableView 返回合适的高度(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
- 在主故事板中禁用分隔符
...我真的不明白如何去除这些白色space ...
对不起我的英语,
谢谢
我正在添加这个。现在你可以检查我的设置:(你可以看到分隔符被禁用)
试试这个 tableView 方法:
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
{
return 0.00001
}
试试这个希望对你有帮助。
Objective C :
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1f;
}
-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero] ;
}
Swift :
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView(frame: CGRectZero)
}
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1f
}
设置 tableviewcell 分隔符 none 同样图像 http://imgur.com/MbVA7pM
您只需要在属性检查器中更改它:
在 swift 中隐藏 table 视图分隔符
func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!)
{
cell.backgroundColor = UIColor.clearColor()
}
试试这个:
func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) {
// Remove seperator inset
if cell.respondsToSelector("setSeparatorInset:") {
cell.separatorInset = UIEdgeInsetsZero
}
// Prevent the cell from inheriting the Table View's margin settings
if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
cell.preservesSuperviewLayoutMargins = false
}
// Explictly set your cell's layout margins
if cell.respondsToSelector("setLayoutMargins:") {
cell.layoutMargins = UIEdgeInsetsZero
}
}
好的,很抱歉,问题出在我的代码上,所以您无法回答我...
它在我的函数中:tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
某处我想在我的单元格上添加边框,所以我写了:
var layer: CALayer = cell.layer
layer.borderColor = UIColor.rgbaColor(red: 288, green: 83, blue: 88, alpha: 1).CGColor
layer.borderWidth = 2
但是这段代码不起作用,因为 red:288 应该是 red:188,所以我有一个白色的边框而不是一个错误,我没有注意到...抱歉,谢谢非常感谢您的帮助:)
只需将页脚视图设置为空视图:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
因此空单元格的分隔符将消失(您仍然保留正常单元格的分隔符)。
在objective c
[self.tableView setSeparatorColor:[UIColor myColor]];
在Swift
tableView.separatorColor = UIColor.clear
一段时间以来,我一直试图删除这些分隔符,太糟糕了,我无法删除它们。我在 Whosebug 中尝试了很多答案,但没有人有帮助:/
这是问题所在:
我无法删除单元格之间的这些白色 spaces:s。
我试过了:
- 将背景颜色更改为与单元格相同的灰色,但它不起作用
- 检查单元格大小
- 将 separatorStyle 设置为 UITableViewCellSeparatorStyle.None
- 使用 tableView 返回合适的高度(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
- 在主故事板中禁用分隔符
...我真的不明白如何去除这些白色space ...
对不起我的英语,
谢谢
我正在添加这个。现在你可以检查我的设置:(你可以看到分隔符被禁用)
试试这个 tableView 方法:
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
{
return 0.00001
}
试试这个希望对你有帮助。
Objective C :
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1f;
}
-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero] ;
}
Swift :
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView(frame: CGRectZero)
}
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1f
}
设置 tableviewcell 分隔符 none 同样图像 http://imgur.com/MbVA7pM
您只需要在属性检查器中更改它:
在 swift 中隐藏 table 视图分隔符
func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!)
{
cell.backgroundColor = UIColor.clearColor()
}
试试这个:
func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) {
// Remove seperator inset
if cell.respondsToSelector("setSeparatorInset:") {
cell.separatorInset = UIEdgeInsetsZero
}
// Prevent the cell from inheriting the Table View's margin settings
if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
cell.preservesSuperviewLayoutMargins = false
}
// Explictly set your cell's layout margins
if cell.respondsToSelector("setLayoutMargins:") {
cell.layoutMargins = UIEdgeInsetsZero
}
}
好的,很抱歉,问题出在我的代码上,所以您无法回答我...
它在我的函数中:tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
某处我想在我的单元格上添加边框,所以我写了:
var layer: CALayer = cell.layer
layer.borderColor = UIColor.rgbaColor(red: 288, green: 83, blue: 88, alpha: 1).CGColor
layer.borderWidth = 2
但是这段代码不起作用,因为 red:288 应该是 red:188,所以我有一个白色的边框而不是一个错误,我没有注意到...抱歉,谢谢非常感谢您的帮助:)
只需将页脚视图设置为空视图:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
因此空单元格的分隔符将消失(您仍然保留正常单元格的分隔符)。
在objective c
[self.tableView setSeparatorColor:[UIColor myColor]];
在Swift
tableView.separatorColor = UIColor.clear