2013-11-02 22 views
1

我有以下的方法,我在iOS6的,但与iOS7使用遇到错误的sizeWithFont:constrainedToSize - iOS7

下面
CGSize labelHeight = [tweetText sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(self.tweetsTableView.bounds.size.width - 84, 4000)]; 

完整的方法,关于如何修改为iOS7任何想法?

- (CGFloat)heightForCellAtIndex:(NSUInteger)index { 

    NSDictionary *tweet = self.tweets[index]; 
    CGFloat cellHeight = 50; 
    NSString *tweetText = tweet[@"text"]; 

    CGSize labelHeight = [tweetText sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(self.tweetsTableView.bounds.size.width - 84, 4000)]; 

    cellHeight += labelHeight.height; 
    return cellHeight; 
} 

回答

1

我知道这是一个老问题&末的答案,但它仍然是非常相关的,

这sizeWithFont方法现在已经过时,这种新的方法效果最佳

NSString *content = **Whatever your label's content is expected to be** 
CGSize maximumLabelSize = CGSizeMake(390, 1000); 

NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey: NSFontAttributeName]; 

CGSize newExpectedLabelSize = [content boundingRectWithSize:maximumLabelSize options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:stringAttributes context:nil].size; 

所以,你可以调整您的标签(或表格单元格等)至

label.frame.size.height = newExpectedLabelSize.height; 

我希望t他的帮助,欢呼声,吉姆。

0

添加此行:

UIFont *font = [UIFont boldSystemFontOfSize:16]; 
CGRect new = [string boundingRectWithSize:CGSizeMake(200, 300) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: font} context:nil]; 
CGSize stringSize= new.size;