UITable里的分割线
2015-06-24 10:55
381 查看
到了iOS8上,发现uitable是越来越不会用了;不说了,先看一下截屏效果:
设计期望的效果是:
1,自定义一个单元格,背景是黄色的;期望铺满整个表格单元;
2,单元分割线是贯通;
现实与理想的差别如下:
1,黄颜色单元格没能横向铺满整个单元;
2,分割线右侧没有拉到头;
3,我只花了三个单元格;没有充满的空间,OS里也画上了分割线。
这是我的解决方法:
解决问题1的方式是:
设置table的边距:[tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
这是iOS8上新出的特性,所以这个问题在iOS7上没有的。
解决问题2和3的方式是:
第一步:设置统一设置表格的分割线留空 [tableView setSeparatorInset:UIEdgeInsetsMake(0, 1000, 0, 0)];
这里设置分割线横行留空1000个像素,这个的目的是为了让所有的分割线画到视图之外,这样子可以让iOS自动补上的分割线都不可见了。
第二步:针对每个单元格设置留空:
[cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
这样可以让我们需要的单元格分割线回到视图中。
[objc] view
plaincopy
#import "ViewController.h"
#import "DemoCell.h"
@interface ViewController ()
{
IBOutlet UITableView *tableView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//以下两行为关键代码
<strong> [tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
[tableView setSeparatorInset:UIEdgeInsetsMake(0, 1000, 0, 0)];</strong>
[tableView setSeparatorColor:[UIColor redColor]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DemoCell *cell = (DemoCell*)[[[NSBundle mainBundle] loadNibNamed:@"DemoCell" owner:self options:nil] lastObject];
//以下两行为关键代码
<strong> [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
</strong>
return cell;
}
@end
设计期望的效果是:
1,自定义一个单元格,背景是黄色的;期望铺满整个表格单元;
2,单元分割线是贯通;
现实与理想的差别如下:
1,黄颜色单元格没能横向铺满整个单元;
2,分割线右侧没有拉到头;
3,我只花了三个单元格;没有充满的空间,OS里也画上了分割线。
这是我的解决方法:
解决问题1的方式是:
设置table的边距:[tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
这是iOS8上新出的特性,所以这个问题在iOS7上没有的。
解决问题2和3的方式是:
第一步:设置统一设置表格的分割线留空 [tableView setSeparatorInset:UIEdgeInsetsMake(0, 1000, 0, 0)];
这里设置分割线横行留空1000个像素,这个的目的是为了让所有的分割线画到视图之外,这样子可以让iOS自动补上的分割线都不可见了。
第二步:针对每个单元格设置留空:
[cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
这样可以让我们需要的单元格分割线回到视图中。
[objc] view
plaincopy
#import "ViewController.h"
#import "DemoCell.h"
@interface ViewController ()
{
IBOutlet UITableView *tableView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//以下两行为关键代码
<strong> [tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
[tableView setSeparatorInset:UIEdgeInsetsMake(0, 1000, 0, 0)];</strong>
[tableView setSeparatorColor:[UIColor redColor]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DemoCell *cell = (DemoCell*)[[[NSBundle mainBundle] loadNibNamed:@"DemoCell" owner:self options:nil] lastObject];
//以下两行为关键代码
<strong> [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
</strong>
return cell;
}
@end
相关文章推荐
- SharePoint 2013 引发类型为“System.ArgumentException”的异常。 参数名: encodedValue
- iOS 9: UIStackView入门
- 如何让UILabel显示多行,并在结尾显示省略号
- (转载)UIKIt力学教程
- Builder模式
- SQL Server 中master..spt_values的应用
- master.dbo.spt_values
- [Groovy]获取当前活动的Environment,获取response中节点的name和节点的value
- execute、executeQuery和executeUpdate之间的区别
- 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记35 UITextField文本框
- What components are not suitable to work as component interfaces
- Devexpress VCL Build v2015 vol 15.1.2发布
- UIModalPresentationStyle和UIModalTransitionStyle
- 用block将UIAlertView与UIActionSheet统一起来
- Android 使用正则表达式来快速生成多套dpi及分分辨率适配的UI
- UIControl
- 10 DelayQueue 延时队列类——Live555源码阅读(一)基本组件类
- UIButton 设置圆角 边框颜色 点击回调方法 &&图片在右文字在左
- 9 DelayQueueEntry 延时队列节点类——Live555源码阅读(一)基本组件类
- 【to be continue】五金配件,省得以后不认识