uitableView自适应大小
2015-12-31 14:57
399 查看
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// 列寬
CGFloat contentWidth = self.tableView.frame.size.width;
// 用何種字體進行顯示
UIFont *font = [UIFont systemFontOfSize:13];
// 該行要顯示的內容
NSString *content = [data objectAtIndex:indexPath.row];
// 計算出顯示完內容需要的最小尺寸
CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(contentWidth, 1000)
lineBreakMode:UILineBreakModeWordWrap];
// 這裏返回需要的高度
return size.height;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
// 列寬
CGFloat contentWidth = self.tableView.frame.size.width;
// 用何種字體進行顯示
UIFont *font = [UIFont systemFontOfSize:13];
// 該行要顯示的內容
NSString *content = [data objectAtIndex:indexPath.row];
// 計算出顯示完內容需要的最小尺寸
CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(contentWidth, 1000)
lineBreakMode:UILineBreakModeWordWrap];
// 構建顯示行
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
CGRect rect = [cell.textLabel textRectForBounds:cell.textLabel.frame limitedToNumberOfLines:0];
// 設置顯示榘形大小
rect.size = size;
// 重置列文本區域
cell.textLabel.frame = rect;
cell.textLabel.text = content;
// 設置自動換行(重要)
cell.textLabel.numberOfLines = 0;
// 設置顯示字體(一定要和之前計算時使用字體一至)
cell.textLabel.font = font;
return cell;
}
本文转自http://mrjeye.iteye.com/blog/1045785
// 列寬
CGFloat contentWidth = self.tableView.frame.size.width;
// 用何種字體進行顯示
UIFont *font = [UIFont systemFontOfSize:13];
// 該行要顯示的內容
NSString *content = [data objectAtIndex:indexPath.row];
// 計算出顯示完內容需要的最小尺寸
CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(contentWidth, 1000)
lineBreakMode:UILineBreakModeWordWrap];
// 這裏返回需要的高度
return size.height;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
// 列寬
CGFloat contentWidth = self.tableView.frame.size.width;
// 用何種字體進行顯示
UIFont *font = [UIFont systemFontOfSize:13];
// 該行要顯示的內容
NSString *content = [data objectAtIndex:indexPath.row];
// 計算出顯示完內容需要的最小尺寸
CGSize size = [content sizeWithFont:font constrainedToSize:CGSizeMake(contentWidth, 1000)
lineBreakMode:UILineBreakModeWordWrap];
// 構建顯示行
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
CGRect rect = [cell.textLabel textRectForBounds:cell.textLabel.frame limitedToNumberOfLines:0];
// 設置顯示榘形大小
rect.size = size;
// 重置列文本區域
cell.textLabel.frame = rect;
cell.textLabel.text = content;
// 設置自動換行(重要)
cell.textLabel.numberOfLines = 0;
// 設置顯示字體(一定要和之前計算時使用字體一至)
cell.textLabel.font = font;
return cell;
}
本文转自http://mrjeye.iteye.com/blog/1045785
相关文章推荐
- git获取代码提示SSL certificate problem: unable to get local issuer certificate
- easyUi和ext comBoBox的模糊查询 (支持拼音和汉字)
- iOS UIView如何管理它的子视图
- Sping MVC后台,EasyUI 分页简单功能实现
- UITableView增加自定义Button并绑定点击事件
- IOS UITableView 的协议方法
- svnant的BUILD FAILED Problem: failed to create task or type svnSetting Cause: The name is undefined原因
- 【iOS学习笔记 15-12-31】 UIScrollview与Autolayout的那点事
- UITableViewCell 指定Cell刷新
- DuiLib实现简易GUI
- JAVA图形界面(GUI)之容器
- [leetcode]Inorder Successor in BST
- UITableViewCell点击事件--可跳转到新界面
- Bringing up interface eth0: Error: No suitable device found: no device found for connection 'System
- IOS学习笔记之UIToolBar
- JDBC连接池、监控组件 Druid
- 嵌入式系统WinCE下应用程序GUI界面开发
- druid 使用ConfigFilter
- 连接池 druid(阿里巴巴的框架)
- easy ui datagrid在没有数据时显示相关提示内容