IOS表视图动态高度实现实例
来源:互联网 发布:网络本科统考 编辑:程序博客网 时间:2024/06/05 20:03
作者:朱克锋
邮箱:zhukefeng@iboxpay.com
转载请注明出处:http://blog.csdn.net/linux_zkf
文件头
#import <UIKit/UIKit.h>
@interface DynamicHeightsViewController :UIViewController {
IBOutlet UITableView *dataTableView;
NSMutableArray *items;
}
@end
文件实现#import "DynamicHeightsViewController.h"
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f
@implementation DynamicHeightsViewController
- (void)viewDidLoad {
[superviewDidLoad];
items = [[NSMutableArrayalloc] init];
//your str add by you 自己添加长度不同的字符进行测试
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
[itemsaddObject:@"your str add by you"];
}
- (void)dealloc {
[items release], items = nil;
[super dealloc];
}
#pragma mark -
#pragma mark UITableView Delegaates
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [itemscount];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
return1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [itemsobjectAtIndex:[indexPath row]];
CGSize constraint =CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN *2), 99999.0f);
CGSize size = [textsizeWithFont:[UIFontsystemFontOfSize:FONT_SIZE]constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height =MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN *2);
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UILabel *label =nil;
cell = [tv dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell ==nil)
{
cell = [[[UITableViewCellalloc] initWithFrame:CGRectZeroreuseIdentifier:@"MyCell"]autorelease];
label = [[UILabelalloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
[[label layer]setBorderWidth:2.0f];
[[cell contentView]addSubview:label];
}
NSString *text = [itemsobjectAtIndex:[indexPath row]];
CGSize constraint =CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN *2), 20000.0f);
CGSize size = [textsizeWithFont:[UIFontsystemFontOfSize:FONT_SIZE]constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
if (!label)
label = (UILabel*)[cellviewWithTag:1];
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN,CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN *2), MAX(size.height,44.0f))];
return cell;
}
@end
- IOS表视图动态高度实现实例
- IOS视图交换实现实例
- IOS视图交换实现实例
- IOS 文本高度自适应变化实现实例
- ios实现动态加载cell高度
- iOS UITableView Cell的动态高度实现
- iOS 动态表情控件视图的实现
- iOS tableview动态高度
- ios动态调整UITableViewCell高度的实现方法
- iOS开发-Storyboard实现cell的动态高度
- iOS Cell子视图添加约束后,动态计算Cell高度
- ios --- 动态获取键盘高度
- iOS TableViewCell 动态调整高度
- 动态计算iOS键盘高度
- ios --- 动态获取键盘高度
- IOS动态获取cell高度
- ios --- 动态获取键盘高度
- ios --- 动态获取键盘高度
- java.lang.OutOfMemoryError: Java heap space + myeclipse中分配tomcat启动时所占内存大小
- linux socket编程相关问题
- Android 文件上传参考
- Painter11快捷键中英文对照表
- jquery插件开发模式(下)
- IOS表视图动态高度实现实例
- QT QWidget设置窗体透明度方法汇总
- 类全局变量的构造和析构顺序
- [MySQL Patch] Binlog文件预分配
- 原型模式
- Linux中的文件i节点
- 黑马程序员--面试题之---交通管理系统
- 多态分类
- 面试杂项题