UITableView分割线左边空白解决方法
2016-03-18 10:37
411 查看
ios7中,左侧会有默认15像素的空白。设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。
ios8中,setSeparatorInset:UIEdgeInsetsZero 的设置已经不起作用了。
下面是解决方法:
首先在viewDidLoad方法加入以下代码:
[self.tableView setSeparatorColor:[UIColor colorWithRed:(227/255.0) green:(229/255.0) blue:(231/255.0) alpha:0.9]];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在代理设置下面
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
{
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
ios8中,setSeparatorInset:UIEdgeInsetsZero 的设置已经不起作用了。
下面是解决方法:
首先在viewDidLoad方法加入以下代码:
[self.tableView setSeparatorColor:[UIColor colorWithRed:(227/255.0) green:(229/255.0) blue:(231/255.0) alpha:0.9]];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在代理设置下面
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
{
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
相关文章推荐
- 对iOS 9 新增的控件 UIStackView 官方文档的翻译<第一部分>
- 在子线程中,更新ui的几种方法
- Android 实现不同样式风格的CharSequence
- php quickSort_快速排序
- Kendo UI常用示例汇总(二)
- Rescue the Rabbit HDU4057
- easyUI 设置列可编辑
- 《iOS Human Interface Guidelines》——Table View
- 亲测:NGUI不规则按钮实现 !!!!
- 程序之间数据的共享,UIActivityViewController类让你的程序进入AirDrop列表
- IOS控件学习之UIScrollView(5)
- 自定义UIButton一般方法
- [Sencha ExtJS & Touch] Ext类结构中的requires和uses
- UI控件--EditText
- 在iOS 8中使用UIAlertController
- iOS开发--UISwitch用法
- iOS开发--UISwitch用法
- [转]UIStepper
- easyui 中怎么修改主题
- IOS控件学习之UIScrollView(4)