tableViewCell的相关优化思想

设置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];
    }];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,195评论 4 61
  • 昨天的文章里,说到了理性思维,今天,我想分享给几个看《万万没想到》一书的心得,更多的是一些观念工具了,既是我对自己...
    知鱼君阅读 1,826评论 0 0
  • H今年35岁,父母70+高龄,身板硬朗、精神矍铄,她很幸运。但是她的父爱来的特别迟。 故事要从新房的一场大火说起。...
    盐主儿阅读 3,762评论 0 5
  • selector可以用来实现不同状态之间的不同表现 selector标签,用多个item定义不同状态的表现。定义的...
    C二叔阅读 3,188评论 0 0
  • mybatis的全局配置文件SqlMapConfig.xml,配置内容如下: properties(属性)sett...
    Seo_sir阅读 3,077评论 0 1