//文字高度
+ (float)height:(NSString *)lab
{
#ifdef __IPHONE_7_0
NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize: K_FONT_SIZE],NSFontAttributeName, nil];
if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
CGRect rect = [lab boundingRectWithSize:CGSizeMake(K_INTRODUCE_LABLE_WIDTH, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
if ([lab isEqualToString:@""]) {
rect.size.height = 0;
}
return rect.size.height;
}
else
{
CGSize rect = [lab sizeWithFont:[UIFont systemFontOfSize:K_FONT_SIZE] constrainedToSize:CGSizeMake(220,2000) lineBreakMode:NSLineBreakByTruncatingHead];
if ([lab isEqualToString:@""]) {
rect.height = 0;
}
return rect.height;
}
#endif
}
- (void)setCellVal:(NSString *)cellVal
{
if (_cellVal != cellVal) {
[_cellVal release];
_cellVal = [cellVal retain];
}
self.cellLabel.text = cellVal;
#ifdef __IPHONE_7_0
//计算文本在限定范围内的高度
NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:K_FONT_SIZE], NSFontAttributeName, nil];
if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
CGRect rect = [_cellLabel.text boundingRectWithSize:CGSizeMake(K_INTRODUCE_LABLE_WIDTH, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
_cellLabel.frame = CGRectMake(_cellLabel.left, _cellLabel.top, _cellLabel.width, rect.size.height);
}
else if ([[[UIDevice currentDevice]systemVersion]floatValue] < 7.0){
CGSize rect = [_cellLabel.text sizeWithFont:[UIFont systemFontOfSize:K_FONT_SIZE] constrainedToSize:CGSizeMake(220,2000) lineBreakMode:NSLineBreakByTruncatingHead];
_cellLabel.frame = CGRectMake(_cellLabel.left, _cellLabel.top, _cellLabel.width, rect.height);
}
#endif
}