iOS tableViewCell相关设置

1. 去掉底部多余的表格线

1
[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

2. 在自定义tableViewCell中设置分割线 顶头显示 self代表cell
1
2
3
4
5
6
7
8
9
10
11
if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
[self setSeparatorInset:UIEdgeInsetsZero];
}

if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
[self setLayoutMargins:UIEdgeInsetsZero];
}

if([self respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
[self setPreservesSuperviewLayoutMargins:NO];
}

3. 代码布局tableview改变cell间隙布局,重写UITableViewCell的frame方法
1
2
3
4
5
6
7
- (void)setFrame:(CGRect)frame{
frame.origin.x += 5;
frame.origin.y += 5;
frame.size.height -= 5;
frame.size.width -= 10;
[super setFrame:frame];
}

4. 动态计算tableviewCell高度
1
2
3
4
5
6
7
8
9
10
11
12
13
//    获取最底部view 的bottom值
// NSArray *views = [self.contentView.subviews sortedArrayUsingComparator:^NSComparisonResult(UIView *view1, UIView *view2) {
// NSString *top1 = [NSString stringWithFormat:@"%f", view1.frame.origin.y];
// NSString *top2 = [NSString stringWithFormat:@"%f", view2.frame.origin.y];
// NSComparisonResult result = [top1 compare:top2 options:NSNumericSearch];
// NSLog(@"^^^::%ld", (long)result);
//
// return result == NSOrderedDescending;
// }];
NSArray *views = self.contentView.subviews;
UIView * bottomView = views.firstObject;
CGFloat height = bottomView.frame.origin.y+bottomView.frame.size.height;
_model.cellHeight = height + 10;

-------------本文结束感谢您的阅读-------------
最近的文章

iOS 静态库开发

本文旨在说明静态库制作中的一些常见问题和特殊处理1. 打包静态库需要的相关问题和设置 静态库中用到分类的需要在项目中设置这个参数:Other Linker Flags为-ObjC或者-all_load 静态库中用到了NSClassFromString或者runtime的objc_getClass, …

继续阅读
更早的文章

iOS 获取屏幕最上层window以及响应者

1. 通过UIApplication获取123UIWindow *window = [UIApplication sharedApplication].keyWindow;或者UIWindow *window = [[UIApplication sharedApplication …

继续阅读