cell根据文本高度动态调整高度适应
2014-08-08 10:58
183 查看
原文出处:http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
1.前提是已经知道文本内容,算出文本的高度。
-》》》根据不同row的文本高度设定cell的高度
-》》》然后设定label的高度适应cell的高度
1.前提是已经知道文本内容,算出文本的高度。
-》》》根据不同row的文本高度设定cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { NSString *text = [items objectAtIndex:[indexPath row]]; CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f); CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; CGFloat height = MAX(size.height, 44.0f); return height + (CELL_CONTENT_MARGIN * 2); }
-》》》然后设定label的高度适应cell的高度
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell; UILabel *label = nil; cell = [tv dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"] autorelease]; label = [[UILabel alloc] initWithFrame:CGRectZero]; [label setLineBreakMode:UILineBreakModeWordWrap]; [label setMinimumFontSize:FONT_SIZE]; [label setNumberOfLines:0]; [label setFont:[UIFont systemFontOfSize:FONT_SIZE]]; [label setTag:1]; [[cell contentView] addSubview:label]; } }
相关文章推荐
- cell根据文本长度来自动调整cell高度
- ios开发笔记之如何让tableView根据文本内容动态改变cell的高度
- cell根据文本长度来自动调整cell高度
- UITableView详解(UITableViewCell(三) cell根据文本长度来自动调整cell高度)
- 动态调整label和cell的高度
- iframe根据被嵌网页高度动态调整自身高度
- 用javascript根据内嵌文档高度动态调整iframe高度
- UITableViewCell 动态高度的调整
- 根据内容自动调整高度的cell
- 根据文本内容计算cell的高度
- iOS开发笔记-根据frame大小动态调整fontSize的自适应文本及圆形进度条控件的实现
- 设置UILabel可变高度(根据文本内容自动适应高度)
- UILabel根据字符 得到高度同时适应于uitableview的cell
- iOS TableViewCell 动态调整高度
- iphone根据文本内容调整label高度的方法。
- IOS 开发中 TableView的文本Cell高度的自适应,UILabel自动换行适应
- iOS TableViewCell 动态调整高度
- 05---MVC模式下动态调整Cell高度三部曲
- ios 文字 控件 自适应 高度 宽度 CustomCell 自适应高度+uilabel自动换行+ UITextView 根据内容自动调整高度
- 动态监听键盘高度调整文本输入框