您的位置:首页 > 移动开发 > IOS开发

IOS中Cell高度的自适应(ios6、ios7)

2014-01-10 11:56 337 查看
一:IOS7 cell 高度自适应

-(float)getHeight:(NSString *)text
{

if (self.interfaceOrientation ==
UIDeviceOrientationPortrait || self.interfaceOrientation ==
UIDeviceOrientationPortraitUpsideDown)
{

//正

CGRect rect=[text
boundingRectWithSize:CGSizeMake(screen_w,
1000)
options:NSStringDrawingUsesLineFragmentOrigin

attributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIFont
systemFontOfSize:12],NSFontAttributeName,
nil]
context:nil];

float x=rect.size.height;

return x+20;
}

else
{

//反

CGRect rect=[text
boundingRectWithSize:CGSizeMake(screen_h,
1000)
options:NSStringDrawingUsesLineFragmentOrigin

attributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIFont
systemFontOfSize:12],NSFontAttributeName,
nil]
context:nil];

float x=rect.size.height;

return x+20;
}
}

二:ios6 cell的高度的自适应

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{

CGSize size = [self.str
sizeWithFont:[UIFont
systemFontOfSize:14]
constrainedToSize:CGSizeMake(320,
10000)];

return size.height+20;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: