自定义UITableView的Seperator
2015-12-21 16:08
543 查看
在默认配置中 ,UITableView的Cell之间的Seperator左边总是空出一块,即使在Storyboard中设置为0 ,也没有效果
需要在代码中进行配置,在ViewController中实现如下方法
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
// iOS 7:
[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];
// iOS 8:
if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
[[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}
原文链接:http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working
需要在代码中进行配置,在ViewController中实现如下方法
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
如果所有的界面都是如此风格,也可以通过UIAppearance 统一配置
// iOS 7:
[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];
// iOS 8:
if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
[[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}
原文链接:http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working
相关文章推荐
- UIActionSheet常用属性(控件8.3之后失效)
- iOS UITableView的Section Footer加入button
- [easyui]实际应用中遇到的问题
- ueditor-------百度编辑器,跨目录上传图片等
- 使用UITableview实现横向滚动
- String、StringBuffer、StringBuilder区别
- Troubleshooting "Global Enqueue Services Deadlock detected" (Doc ID 1443482.1)
- iOS开发之如何在NSURLRequest中设置自定义header请求头
- UITableView 刷新头部时,头部每次都变为开始的状态,无法记录当前的状态
- 基于ROS_Arduino室内移动机器人SLAM实验测试
- 基于ROS_Arduino室内移动机器人SLAM实验测试
- 基于ROS_Arduino室内移动机器人SLAM实验测试
- 【PHP】PHP include()和require()方法的区别
- ios图片缩放,根据UIImageView Frame的尺寸,自动调整UIImage缩放,保证图片显示不变形
- UIMenuContnroller的使用
- Android BlueDroid(一):BlueDroid概述
- Hello : break continue return
- IOS开发之 ---- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- Ant_build.xml解释
- iOS开发日记53-CALayer和UIView