iOS UITableView(十一) tableView的几个小技巧

来源:互联网 发布:python 提取文件名 编辑:程序博客网 时间:2024/05/22 04:54

一、我们在加载有分割线的cell的时候会发现它的右端会短一点,并没有到屏幕右侧,我这里给大家提供两个方法,

1、用XIB拉出分割线,加载的时候分割线自然不会消失,还有一个是在inspector 里面有个Separator Insetss 标签 默认是 Default,我们选择一下 发现有个Custom  这时候我们惊奇的发现Left  15  ,这时候我们只要把这个 15  改成 0 , 然后保存, 你就会发现tableview 的分割线跟以前一样了。

2、用代码对它进行修改

在ios7中我们可以用这行代码  [myTableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];   但是这个在iOS8中好像不起作用了 下面是解决办法

//在此处加入下面代码- (void)viewDidLoad {    [super viewDidLoad];    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];}}

二、在定义cell的时候加入下面代码会让你的tableView加载更平滑

cell.layer.shouldRasterize = YES;cell.layer.rasterizationScale = [UIScreen mainScreen].scale;

三、固定cell.imageView.image的大小

cell.imageView.image = [UIImage imageNamed:[imageArray objectAtIndex:[indexPath row]]];CGSize itemSize = CGSizeMake(60, 50);UIGraphicsBeginImageContext(itemSize);    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);    [cell.imageView.image drawInRect:imageRect];    cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();






0 0
原创粉丝点击