码迷,mamicode.com
首页 > 其他好文 > 详细

tableview分组时的一些问题

时间:2015-10-20 19:17:06      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

1.UILabel的上对齐

UILabel的默认对齐方式只有左、中、右,而没有上对齐。若想实现这样的效果,最简单直接的方式就是在text后加一串"\n ",并且\n之后最少有一个空格,否则会被UILabel忽略。如下

self.text = [myLabel.text stringByAppendingString:@"\n "];

 

2.UITableView的分割线问题

默认情况下,cell之间的分割线会与左端有一定距离,如

技术分享

 

比较简单的处理方式就是自定义分割线。添加分割线时推荐使用UIImageView添加背景色方法,不推荐在cell中用drawRect画线的方法,这样太耗资源

//先在tableview中取消cell之间的分割线
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//在cell中自定义分割线
UIImageView *lineImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, contentLab.bottom + 9, mScreenWidth, 0.5)];
lineImg.backgroundColor = [UIColor lightGrayColor];
[self.contentView addSubview:lineImg];

 

3.修改section之间的距离

如只设置cell的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

效果如下:

技术分享

 

此时就需要设置section之间的距离,用

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

设置后的效果如下,基本达到要求

技术分享

 

 

4.若想设置如通讯录右侧索引,可以用

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    return @[@"A",@"B",@"C",@"D",@"E"];
}

 

tableview分组时的一些问题

标签:

原文地址:http://www.cnblogs.com/Apologize/p/4895545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!