设置cell点击动画
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
清除cell中的那条线
_tableView.separatorStyle = NO;
用UIView代替UIImageView
UIView *v = [UIView new];
v.layer.contents = (__bridge id)([UIImage imageNamed:@"CircleMask.png"].CGImage);
[self.contentView addSubview:v];
[v mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.width.height.equalTo(_headerImage);
}];
UIView根据URL设置图片
uiimageView根据URL设置图片的第三方框架:SDWebImage
#import "YYKit.h"
[_headerImageView.layer setImageURL:[NSURL URLWithString:item.imageURL]];
不要直接去切成圆形,可以找设计师要一份切完的图片盖上去
_headerImageView.layer.cornerRadius = 40;
_headerImageView.layer.masksToBounds = YES;
CircleMask.png
自动cell高度
1. 这个个只有是cell中的label、button、imageView等才会将cell撑开
_tableView.estimatedRowHeight = 2.0;
2. 一个单例函数
+ (float)getTextHeightWithString:(NSString*)textStr andSize:(CGSize)size {
static UILabel *label;
static dispatch_once_t pre;
_dispatch_once(&pre, ^{
label = [UILabel new];
label.numberOfLines = 0;
label.font = [UIFont systemFontOfSize:17];
});
label.text = textStr;
float height = [label sizeThatFits:size].height;
return height;
}
// 输入文字和label的宽高
float labelHeight = [AutoCellHeight getTextHeightWithString:_articleArr[indexPath.section] andSize:CGSizeMake(self.view.bounds.size.width - 100, MAXFLOAT)];
3. 第三方框架
TempCell
#import "UITableView+FDTemplateLayoutCell.h"
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [tableView fd_heightForCellWithIdentifier:@"cell" cacheByIndexPath:indexPath configuration:^(CustomTableViewCell *cell) {
cell.item = _datas[indexPath.row];
}];
}
网友评论