首先说一下实现这一功能的核心类别,UITableViewCell+FSAutoCountHeight。这个类其实是利用运行时将每个cell高度通过子控件的约束动态加以控制进而返回一个值,这个值就是我们要在tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath中要返回的值,那么有朋友要问了这个数据肯定是从后台来的,如果数据很多的时候在cell自身重用机制的因素下会不会受到影响?当然这层是考虑到的,FSCellHeightForTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath cacheKey:(NSString*)cacheKey cellContentViewWidth:(CGFloat)contentViewWidth bottomOffset:(CGFloat)bottomOffset这个方法其实就是通过cacheKey进而进行对cell高度缓存的策略,cacheKey如何取呢,举个栗子,比如接口上返回的是有两个字段,一个productId 一个productName, 显而易见productId意思就是每个产品不同的ID。很简单这里的cacheKey就可以取这里的productId。


#import "ViewController.h"#import "WeiChatTableViewCell.h"#import "Masonry.h"#import "UITableViewCell+FSAutoCountHeight.h"#define SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width#define SCREEN_HEIGHT  [[UIScreen mainScreen] bounds].size.height#define COLOR_White [UIColor whiteColor]@interface ViewController ()@property (nonatomic, strong) UITableView *tableView;@property (nonatomic, strong) NSMutableArray *dataArr;@property (nonatomic, strong) UISlider *slider;@property (nonatomic, assign) CGFloat fontSize;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];self.dataArr = [NSMutableArray array];[self.dataArr addObjectsFromArray:@[@"你好1",@"你好2",@"你好3",@"你好4",@"你好5",@"你好6",@"你好7"]];[self setUpTableView];[self setUpMyControlView];//设置默认字体大小为16pxself.fontSize=16;}- (void)setUpTableView{self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 100)];self.tableView.backgroundColor = [UIColor greenColor];self.tableView.dataSource = self;self.tableView.delegate=self;[self.view addSubview:self.tableView];self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;}- (void)setUpMyControlView{UIView*smallView = [[UIViewalloc]init];smallView.backgroundColor = [UIColor yellowColor];[self.viewaddSubview:smallView];smallView.frame=CGRectMake(0,SCREEN_HEIGHT-100,SCREEN_WIDTH,100);//    [smallView mas_makeConstraints:^(MASConstraintMaker *make) {//        make.top.equalTo(self.tableView.mas_bottom);//        make.left.with.equalTo(self.view);//        make.height.mas_equalTo(100);//    }];UISlider *slider = [[UISlider alloc] init];self.slider= slider;slider.minimumValue=9;slider.maximumValue=32;slider.value=16;[smallViewaddSubview:slider];[slidermas_makeConstraints:^(MASConstraintMaker *make) {make.center.equalTo(smallView);make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 30));}];slider.continuous=YES;//滑轮左边颜色,如果设置了左边的图片就不会显示slider.minimumTrackTintColor = [UIColor greenColor];//滑轮右边颜色,如果设置了右边的图片就不会显示slider.maximumTrackTintColor = [UIColor redColor];[slideraddTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];}- (void)sliderValueChanged:(UISlider*)slider{for (WeiChatTableViewCell *cell in [self.tableView visibleCells]) {cell.fontSize= slider.value;}}#pragma mark - tableViewDataSource- (NSInteger) numberOfSectionsInTableView:(UITableView*)tableView{return 1;}- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{return self.dataArr.count;}- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{WeiChatTableViewCell *cell = [WeiChatTableViewCell cellWithTableView:tableView];cell.fontSize = self.fontSize;if(self.dataArr.count> indexPath.row){cell.mainLabel.text=self.dataArr[indexPath.row];   }returncell;}- (CGFloat) tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{if(self.dataArr.count> indexPath.row) {NSString*titleString =self.dataArr[indexPath.row];return [WeiChatTableViewCell FSCellHeightForTableView:tableView indexPath:indexPath cacheKey:titleString cellContentViewWidth:0 bottomOffset:0];}return 0.01f;}@end这个是自定义的cell(.h)#import@interfaceWeiChatTableViewCell :UITableViewCell@property (nonatomic, strong) UILabel *mainLabel;//外界改变label大小方式的键@property (nonatomic, assign) CGFloat fontSize;+ (instancetype)cellWithTableView:(UITableView*)tableView;@end(.m)#import "WeiChatTableViewCell.h"#import "Masonry.h"#import "UITableViewCell+FSAutoCountHeight.h"@implementationWeiChatTableViewCell+ (instancetype)cellWithTableView:(UITableView*)tableView{static NSString * cellId=@"PersonCentreCell";WeiChatTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId];if(cell==nil) {cell=[[WeiChatTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];}returncell;}- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];if(self) {       for(UIView *sub in self.contentView.subviews){[subremoveFromSuperview];}[selfcreatUI];}return self;}- (void)creatUI{self.mainLabel = [[UILabel alloc] init];self.mainLabel.textColor = [UIColor grayColor];self.mainLabel.backgroundColor = [UIColor blueColor];self.mainLabel.textAlignment = NSTextAlignmentLeft;self.mainLabel.translatesAutoresizingMaskIntoConstraints = NO;if(self.fontSize&&self.fontSize>0) {self.mainLabel.font = [UIFont systemFontOfSize:self.fontSize];}else{//默认是16self.mainLabel.font = [UIFont systemFontOfSize:16];}[self.contentView addSubview:self.mainLabel];[self.mainLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(self.contentView.mas_top).offset(25);//        make.top.mas_equalTo(SCREEN_AUTO_HIGHT * 30/1271);make.left.mas_equalTo(12);make.right.lessThanOrEqualTo(self.contentView.mas_right).with.offset(- 12);}];UIView*smallView = [[UIViewalloc]init];[self.contentView addSubview:smallView];[smallViewmas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(self.mainLabel.mas_bottom);make.left.with.equalTo(self.contentView);make.height.mas_equalTo(20);}];self.FS_cellBottomView= smallView;}- (void)setFontSize:(CGFloat)fontSize{_fontSize= fontSize;self.mainLabel.font = [UIFont systemFontOfSize:fontSize];[self layoutIfNeeded];}@end最后上一下提到的核心(分)类(.h)#import@interfaceUITableViewCell (FSAutoCountHeightCell)/**cell底视图(提高计算效率,能传则传)*/@property(nonatomic,strong)UIView* FS_cellBottomView;/**cell底视图数组(在不确定最下面的视图关系时,可以传入一个视图数组)*/@property(nonatomic,strong)NSArray* FS_cellBottomViews;/**cell自动计算行高@param tableView tableView@param indexPath indexPath@param contentViewWidth cell内容宽度,不确定可传0@return cell高度*/+ (CGFloat)FSCellHeightForTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath cellContentViewWidth:(CGFloat)contentViewWidth bottomOffset:(CGFloat)bottomOffset;/**cell自动计算行高优化版@param tableView tableView@param indexPath indexPath@param cacheKey 当前cell唯一标识符@param contentViewWidth cell内容宽度,不确定可传0@return cell高度*/+ (CGFloat)FSCellHeightForTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath cacheKey:(NSString*)cacheKey cellContentViewWidth:(CGFloat)contentViewWidth bottomOffset:(CGFloat)bottomOffset;@end(.m)#import "UITableViewCell+FSAutoCountHeight.h"#import#define ScreenScale ([[UIScreen mainScreen] scale])CG_INLINE CGFloatflatSpecificScale(CGFloatfloatValue,CGFloatscale) {scale = scale ==0?ScreenScale: scale;CGFloatflattedValue =ceil(floatValue * scale) / scale;returnflattedValue;}CG_INLINE CGFloatflat(CGFloatfloatValue) {returnflatSpecificScale(floatValue,0);}CG_INLINE CGRectCGRectSetWidth(CGRectrect,CGFloatwidth) {rect.size.width=flat(width);returnrect;}CG_INLINE voidReplaceMethod(Class_class,SEL_originSelector,SEL_newSelector) {MethodoriMethod =class_getInstanceMethod(_class, _originSelector);MethodnewMethod =class_getInstanceMethod(_class, _newSelector);BOOLisAddedMethod =class_addMethod(_class, _originSelector,method_getImplementation(newMethod),method_getTypeEncoding(newMethod));if(isAddedMethod) {class_replaceMethod(_class, _newSelector, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));}else{method_exchangeImplementations(oriMethod, newMethod);}}@interfaceUITableView (FSAutoCountHeight)@property(nonatomic,strong)NSMutableDictionary*keyCacheDic_Portrait;@property(nonatomic,strong)NSMutableDictionary*keyCacheDic_Landscape;@property(nonatomic,strong)NSMutableArray*indexCacheArr_Portrait;@property(nonatomic,strong)NSMutableArray*indexCacheArr_Landscape;@property (nonatomic, assign) BOOL isIndexPath;@end@implementationUITableView (FSAutoCountHeight)+ (void)load{SELselectors[] = {@selector(reloadData),@selector(insertSections:withRowAnimation:),@selector(deleteSections:withRowAnimation:),@selector(reloadSections:withRowAnimation:),@selector(moveSection:toSection:),@selector(insertRowsAtIndexPaths:withRowAnimation:),@selector(deleteRowsAtIndexPaths:withRowAnimation:),@selector(reloadRowsAtIndexPaths:withRowAnimation:),@selector(moveRowAtIndexPath:toIndexPath:)};for(NSUIntegerindex =0; indexSELoriginalSelector = selectors[index];SEL swizzledSelector = NSSelectorFromString([@"FS_" stringByAppendingString:NSStringFromSelector(originalSelector)]);ReplaceMethod(self, originalSelector, swizzledSelector);}}#pragma mark setter/getter- (NSMutableDictionary*)keyCacheDicForCurrentOrientation{return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) ? self.keyCacheDic_Portrait: self.keyCacheDic_Landscape;}- (void)setKeyCacheDic_Portrait:(NSMutableDictionary*)keyCacheDic_Portrait{objc_setAssociatedObject(self, @selector(keyCacheDic_Portrait), keyCacheDic_Portrait, OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (NSMutableDictionary*)keyCacheDic_Portrait{return objc_getAssociatedObject(self, _cmd);}- (void)setKeyCacheDic_Landscape:(NSMutableDictionary*)keyCacheDic_Landscape{objc_setAssociatedObject(self, @selector(keyCacheDic_Landscape), keyCacheDic_Landscape, OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (NSMutableDictionary*)keyCacheDic_Landscape{return objc_getAssociatedObject(self, _cmd);}- (NSMutableArray*)indexCacheArrForCurrentOrientation{return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation) ? self.indexCacheArr_Portrait: self.indexCacheArr_Landscape;}- (void)setIndexCacheArr_Portrait:(NSMutableArray*)indexCacheArr_Portrait{objc_setAssociatedObject(self,@selector(indexCacheArr_Portrait), indexCacheArr_Portrait,OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (NSMutableArray*)indexCacheArr_Portrait{return objc_getAssociatedObject(self, _cmd);}- (void)setIndexCacheArr_Landscape:(NSMutableArray*)indexCacheArr_Landscape{objc_setAssociatedObject(self,@selector(indexCacheArr_Landscape), indexCacheArr_Landscape,OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (NSMutableArray*)indexCacheArr_Landscape{return objc_getAssociatedObject(self, _cmd);}- (void)setIsIndexPath:(BOOL)isIndexPath{objc_setAssociatedObject(self, @selector(isIndexPath), @(isIndexPath), OBJC_ASSOCIATION_ASSIGN);}- (BOOL)isIndexPath{return [objc_getAssociatedObject(self, _cmd) boolValue];}#pragma mark exchangeVoid- (void)FS_reloadData{if (self.indexCacheArrForCurrentOrientation&&self.isIndexPath) {[self.indexCacheArrForCurrentOrientation removeAllObjects];}[self FS_reloadData];}- (void)FS_reloadSections:(NSIndexSet*)sections withRowAnimation:(UITableViewRowAnimation)animation{if (self.indexCacheArrForCurrentOrientation&§ions&&self.isIndexPath) {[sectionsenumerateIndexesUsingBlock:^(NSUIntegeridx,BOOL*_Nonnullstop) {if (idx < self.indexCacheArrForCurrentOrientation.count) {[self.indexCacheArrForCurrentOrientation[idx] removeAllObjects];}}];}[self FS_reloadSections:sections withRowAnimation:animation];}- (void)FS_reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{if (self.indexCacheArrForCurrentOrientation&&indexPaths&&self.isIndexPath) {[indexPathsenumerateObjectsUsingBlock:^(NSIndexPath*_Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop) {if (obj.section < self.indexCacheArrForCurrentOrientation.count) {NSMutableArray*rowCacheArr =self.indexCacheArrForCurrentOrientation[obj.section];if(obj.row< rowCacheArr.count) {rowCacheArr[obj.row] = @-1;}}}];}[self FS_reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];}- (void)FS_moveSection:(NSInteger)section toSection:(NSInteger)newSection{if (self.isIndexPath && self.indexCacheArrForCurrentOrientation) {if (section < self.indexCacheArrForCurrentOrientation.count && newSection < self.indexCacheArrForCurrentOrientation.count) {[self.indexCacheArrForCurrentOrientation exchangeObjectAtIndex:section withObjectAtIndex:newSection];}}[selfFS_moveSection:sectiontoSection:newSection];}- (void)FS_moveRowAtIndexPath:(NSIndexPath*)indexPath toIndexPath:(NSIndexPath*)newIndexPath{if (self.isIndexPath && self.indexCacheArrForCurrentOrientation) {if (indexPath.section < self.indexCacheArrForCurrentOrientation.count && newIndexPath.section < self.indexCacheArrForCurrentOrientation.count) {NSMutableArray *indexPathRows =self.indexCacheArrForCurrentOrientation[indexPath.section];NSMutableArray *newIndexPathRows =self.indexCacheArrForCurrentOrientation[newIndexPath.section];if(indexPath.row< indexPathRows.count&& newIndexPath.row< newIndexPathRows.count) {NSNumber*indexValue = indexPathRows[indexPath.row];NSNumber*newIndexValue = newIndexPathRows[newIndexPath.row];indexPathRows[indexPath.row] = newIndexValue;newIndexPathRows[newIndexPath.row] = indexValue;}}}[self FS_moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];}- (void)FS_insertSections:(NSIndexSet*)sections withRowAnimation:(UITableViewRowAnimation)animation{if (self.isIndexPath && self.indexCacheArrForCurrentOrientation) {[sectionsenumerateIndexesUsingBlock:^(NSUIntegeridx,BOOL*_Nonnullstop) {if (idx <= self.indexCacheArrForCurrentOrientation.count) {[self.indexCacheArrForCurrentOrientation insertObject:[NSMutableArray array] atIndex:idx];}}];}[self FS_insertSections:sections withRowAnimation:animation];}- (void)FS_insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{if (self.isIndexPath && self.indexCacheArrForCurrentOrientation) {[indexPathsenumerateObjectsUsingBlock:^(NSIndexPath*_Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop) {if (obj.section < self.indexCacheArrForCurrentOrientation.count) {NSMutableArray *rowCacheArr =self.indexCacheArrForCurrentOrientation[obj.section];if(obj.row<= rowCacheArr.count) {[rowCacheArrinsertObject:@-1atIndex:obj.row];}}}];}[self FS_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];}- (void)FS_deleteSections:(NSIndexSet*)sections withRowAnimation:(UITableViewRowAnimation)animation{if (self.isIndexPath && self.indexCacheArrForCurrentOrientation) {[sectionsenumerateIndexesUsingBlock:^(NSUIntegeridx,BOOL*_Nonnullstop) {if (idx < self.indexCacheArrForCurrentOrientation.count) {[self.indexCacheArrForCurrentOrientation removeObjectAtIndex:idx];}}];}[self FS_deleteSections:sections withRowAnimation:animation];}- (void)FS_deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{if (self.isIndexPath && self.indexCacheArrForCurrentOrientation) {[indexPathsenumerateObjectsUsingBlock:^(NSIndexPath*_Nonnullobj,NSUIntegeridx,BOOL*_Nonnullstop) {if (obj.section < self.indexCacheArrForCurrentOrientation.count) {NSMutableArray *rowCacheArr =self.indexCacheArrForCurrentOrientation[obj.section];if(obj.row< rowCacheArr.count) {[rowCacheArrremoveObjectAtIndex:obj.row];}}}];}[self FS_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];}@end@implementationUITableViewCell (FSAutoCountHeightCell)- (void)setFS_cellBottomViews:(NSArray*)FS_cellBottomViews {objc_setAssociatedObject(self,@selector(FS_cellBottomViews),FS_cellBottomViews,OBJC_ASSOCIATION_COPY);}- (NSArray*)FS_cellBottomViews {return objc_getAssociatedObject(self, _cmd);}- (void)setFS_cellBottomView:(UIView*)FS_cellBottomView {objc_setAssociatedObject(self,@selector(FS_cellBottomView),FS_cellBottomView,OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (UIView*)FS_cellBottomView {return objc_getAssociatedObject(self, _cmd);}+ (CGFloat)FSCellHeightForTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath cellContentViewWidth:(CGFloat)contentViewWidth bottomOffset:(CGFloat)bottomOffset{if(!indexPath) {return0;}tableView.isIndexPath=YES;if (!tableView.indexCacheArr_Portrait) {tableView.indexCacheArr_Portrait= [NSMutableArrayarray];}if (!tableView.indexCacheArr_Landscape) {tableView.indexCacheArr_Landscape= [NSMutableArrayarray];}for(NSIntegersectionIndex =0; sectionIndex <= indexPath.section; sectionIndex++) {if(sectionIndex >= tableView.indexCacheArrForCurrentOrientation.count) {tableView.indexCacheArrForCurrentOrientation[sectionIndex] = [NSMutableArrayarray];}}NSMutableArray*rowCacheArr = tableView.indexCacheArrForCurrentOrientation[indexPath.section];for(NSIntegerrowIndex =0; rowIndex <= indexPath.row; rowIndex++) {if(rowIndex >= rowCacheArr.count) {rowCacheArr[rowIndex] = @-1;}}if(![tableView.indexCacheArrForCurrentOrientation[indexPath.section][indexPath.row]isEqualToNumber:@-1]) {CGFloatcellHeight =0;NSNumber*heightNumber = tableView.indexCacheArrForCurrentOrientation[indexPath.section][indexPath.row];cellHeight = heightNumber.floatValue;returncellHeight;}UITableViewCell *cell = [tableView.dataSource tableView:tableView cellForRowAtIndexPath:indexPath];if(contentViewWidth ==0) {[tableViewlayoutIfNeeded];contentViewWidth =CGRectGetWidth(tableView.frame);}if(contentViewWidth ==0) {return0;}cell.frame=CGRectSetWidth(cell.frame, contentViewWidth);cell.contentView.frame = CGRectSetWidth(cell.contentView.frame, CGRectGetWidth(tableView.frame));[celllayoutIfNeeded];UIView*cellBottomView =nil;if (cell.FS_cellBottomView) {cellBottomView = cell.FS_cellBottomView;}else if (cell.FS_cellBottomViews && cell.FS_cellBottomViews.count > 0) {cellBottomView = cell.FS_cellBottomViews[0];for(UIView*viewincell.FS_cellBottomViews) {if(CGRectGetMaxY(view.frame) >CGRectGetMaxY(cellBottomView.frame)) {cellBottomView = view;}}}else{NSArray*contentViewSubViews = cell.contentView.subviews;if(contentViewSubViews.count==0) {cellBottomView = cell.contentView;}else{cellBottomView = contentViewSubViews[0];for(UIView*viewincontentViewSubViews) {if(CGRectGetMaxY(view.frame) >CGRectGetMaxY(cellBottomView.frame)) {cellBottomView = view;}}}}CGFloatcellHeight =CGRectGetMaxY(cellBottomView.frame) + bottomOffset;tableView.indexCacheArrForCurrentOrientation[indexPath.section][indexPath.row] =@(cellHeight);returncellHeight;}+ (CGFloat)FSCellHeightForTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath cacheKey:(NSString*)cacheKey cellContentViewWidth:(CGFloat)contentViewWidth bottomOffset:(CGFloat)bottomOffset{if(!indexPath || !cacheKey) {return0;}tableView.isIndexPath=NO;if (!tableView.keyCacheDic_Portrait) {tableView.keyCacheDic_Portrait = [NSMutableDictionary dictionary];}if (!tableView.keyCacheDic_Landscape) {tableView.keyCacheDic_Landscape = [NSMutableDictionary dictionary];}NSNumber*cacheHeight = tableView.keyCacheDicForCurrentOrientation[cacheKey];if(cacheHeight !=nil) {CGFloatcellHeight =0;cellHeight = cacheHeight.floatValue;returncellHeight;}UITableViewCell *cell = [tableView.dataSource tableView:tableView cellForRowAtIndexPath:indexPath];if(contentViewWidth ==0) {[tableViewlayoutIfNeeded];contentViewWidth =CGRectGetWidth(tableView.frame);}if(contentViewWidth ==0) {return0;}cell.frame=CGRectSetWidth(cell.frame, contentViewWidth);cell.contentView.frame = CGRectSetWidth(cell.contentView.frame, CGRectGetWidth(tableView.frame));[celllayoutIfNeeded];UIView*cellBottomView =nil;if (cell.FS_cellBottomView) {cellBottomView = cell.FS_cellBottomView;}else if (cell.FS_cellBottomViews && cell.FS_cellBottomViews.count > 0) {cellBottomView = cell.FS_cellBottomViews[0];for(UIView*viewincell.FS_cellBottomViews) {if(CGRectGetMaxY(view.frame) >CGRectGetMaxY(cellBottomView.frame)) {cellBottomView = view;}}}else{NSArray*contentViewSubViews = cell.contentView.subviews;if(contentViewSubViews.count==0) {cellBottomView = cell.contentView;}else{cellBottomView = contentViewSubViews[0];for(UIView*viewincontentViewSubViews) {if(CGRectGetMaxY(view.frame) >CGRectGetMaxY(cellBottomView.frame)) {cellBottomView = view;}}}}CGFloatcellHeight =CGRectGetMaxY(cellBottomView.frame) + bottomOffset;[tableView.keyCacheDicForCurrentOrientationsetValue:@(cellHeight)forKey:cacheKey];returncellHeight;}@end

内容有点多,其实我这边还有压缩版的,可以添加我的微信(Xpc1314520xpc),直接发给你们。这个是干货,感觉用的上的小伙伴可以赞一个,不一定要打赏嘛☺!

iOS模仿微信滑块动态设置字体大小的功能相关推荐

  1. pyqt5动态设置字体大小

    利用QFontDialog组件的getFont()方法进行字体的设置 下面是使用工具栏按钮绑定设置字体的方法进行界面字体设置,设置完成后并进行本地化保存,界面重启时进行加载 利用下面的方式进行工具栏按 ...

  2. 移动端应该如何动态设置字体大小?

    rem由来:font size of the root element,那么rem是个单位,单位大小由它第一代老祖宗的font-size的大小决定.现在前端码农们为了能在各个屏幕上看到一个健康的网页在 ...

  3. 通过JavaScript动态设置字体大小

    <script>function setRem() {var ui_w = 375;// 获取屏幕的宽度var clientWidth = document.documentElement ...

  4. vue3+element-plus动态设置字体大小

    1.先定义一个字体数据 setup() {const state = reactive({size: 1, //默认字体大小值val: "",//双向绑定的值//字体数组posts ...

  5. Android 代码中动态设置字体大小-TextView.SetTextSize()

    关键代码 - setTextSize(TypedValue.COMPLEX_UNIT_PX,15); //15像素 - setTextSize(TypedValue.COMPLEX_UNIT_SP,1 ...

  6. HTML设置字体大小自适应屏幕与echarts图表颜色根据数据大小实时刷新图表颜色

    设置html文字大小根据页面大小自适应,在使用rem之前是使用的px和百分比,后来发现页面缩放或在小屏幕的电脑显示不尽人意,后改用rem,写法如:font-size: .21rem;或font-siz ...

  7. android 设置字体大小不随系统大小变化,App字体大小不随系统改变而改变

    在 "设置" , "显示" , "字体大小" 里面我们可以设置系统字体大小 App界面字体,如果被修改之后,可能就达不到理想状态的效果,界面 ...

  8. android html字体大小,android Html.fromHtml font 标签支持设置字体大小和颜色

    由于在android 中的Html源码中对html标签的支持不是很完全,在使用textview加载html自定义字体样式的时候遇到坑了,就是font标签不支持size属性,查看源码中发现没有去解析si ...

  9. 根据屏幕大小动态设置字体rem

    //根据屏幕大小动态设置字体rem var docEl = document.documentElement,//当设备的方向变化(设备横向持或纵向持)此事件被触发.绑定此事件时,//注意现在当浏览器 ...

最新文章

  1. CentOS 6.5下SSH总提示Warning: Permanently added '****' (RSA) to the list of known hosts.
  2. Leetcode 92 反转链表 II (每日一题 20210726)
  3. NuGet社区使用体验调查
  4. 前端学习(2027)vue之电商管理系统电商系统之实现省--市联动
  5. python 除数不能为零的报错有哪些_【社区精选40】Python错误处理及代码调试方法(文末赠书中奖名单)...
  6. etmvc mysql乱码_etmvc中集成spring使用druid连接池
  7. micropython esp32驱动舵机_PCA9685舵机控制板与MicroPython-ESP32-1Z实验室
  8. PNChart,简洁高效有动画效果的iOS图表库
  9. 【点阵液晶编程连载五】液晶驱动代码的移植
  10. HTML代码中中逗号和句号怎么写,逗号和句号的用法
  11. 选型宝分享数据爆炸时代,如何驾驭海量日志?
  12. 闲鱼怎么用快手做引流,快手怎么找痛点引流
  13. ubuntu16.0.4bug无法解析域名
  14. 计算机网络原理知识点及考点整理(谢希仁第七版)
  15. 平安科技实习生面试经历
  16. 现代企业管理笔记——领导
  17. 大学冷知识「高校的学生也有专属昵称」
  18. 一个基于java实现的代码计数器
  19. javascript基础知识+实例(全套) 免费附HTML+CSS课程视频资料(链接:https://pan.baidu.com/s/1qyyf0mZxP7_M6ssGJuVlag 提取码:私信)
  20. 基金投资好简单,从入门到精通 -学习笔记day1

热门文章

  1. 网络云盘本地加载工具:CloudMounter Mac中文版
  2. 印刷和喷绘过程中高精度油墨流量和压力的串级控制解决方案
  3. 与老婆相处十日(一)
  4. 大王币说 | “IPFS中国区教父”周欢:散户怎样才能在IPFS中获利
  5. 数字信息化时代,VR会议开启商务云洽谈新方式
  6. 这3类人,可能不适合学习编程开发?
  7. Excel2016 逗号分隔一段数据
  8. 怎么从src包中文件直接访问WebContent下面文件
  9. 腾讯java程序设计师_腾讯大神耗时三年巅峰之作,立足实际开发,详解高并发程序设计...
  10. 设A是n*n的对称矩阵,将A的对角线及对角线上方的元素以列为主的次序存放在一维数组B[1..n(n+1)/2]中,对上述任一元素aij(1=i,j=n,且i=j)在B中的位置为()