荣幸的是,想支撑文本异步衬着也有现成的库 YYText ,下面来讲讲若何搭配它最大年夜程度知足我们如丝般顺滑的需求:
Frame 搭配异步衬着
根本思路和计算 frame 类似,只不过把体系的 boundingRectWithSize: 、 sizeWithAttributes: 换成 YYText 中的办法:
设备 frame model:
- //FrameYYModel.h
- @interface FrameYYModel : NSObject
- @property (assign, nonatomic, readonly) CGRect titleFrame;
- @property (strong, nonatomic, readonly) YYTextLayout *titleLayout;
- @property (assign, nonatomic, readonly) CGFloat cellHeight;
- @property (strong, nonatomic) FDFeedEntity *entity;
- @end
- //FrameYYModel.m
- @implementation FrameYYModel
- - (void)setEntity:(FDFeedEntity *)entity {
- if (!entity) return;
- _entity = entity;
- CGFloat maxLayout = ([UIScreen mainScreen].bounds.size.width - 20.f);
- CGFloat space = 10.f;
- CGFloat bottom = 4.f;
- //title
- NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:entity.title];
- title.yy_font = Font(16.f);
- title.yy_color = [UIColor blackColor];
- YYTextContainer *titleContainer = [YYTextContainer containerWithSize:CGSizeMake(maxLayout, CGFLOAT_MAX)];
- _titleLayout = [YYTextLayout layoutWithContainer:titleContainer text:title];
- CGFloat titleX = 10.f;
- CGFloat titleY = 10.f;
- CGSize titleSize = _titleLayout.textBoundingSize;
- _titleFrame = (CGRect){titleX,titleY,CGSizeMake(titleSize.width, titleSize.height)};
- //cell Height
- _cellHeight = (CGRectGetMaxY(_titleFrame) + bottom);
- }
- @end
UITableViewCell 处理 :
控件赋值:
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (!self) return nil;
- YYLabel *title = [YYLabel new];
- title.displaysAsynchronously = YES; //开启异步衬着
推荐阅读
【译者注】在本文中,作者介绍了即将在9.21宣布的Java 9新特点,除了最重要的模块化以外,还涉及到编译,对象,协定,缓存等新特点,也说起了在此次版本中移除的功能,供Java爱好者浏览和>>>详细阅读
本文标题:iOS中关于列表滚动流畅的一些探讨
地址:http://www.17bianji.com/lsqh/37290.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示