sizeWithFont:constrainedToSize-iOS7

sizeWithFont:constrainedToSize-iOS7,ios7,sizewithfont,Ios7,Sizewithfont,我在iOS6中使用了下面的方法,但是在iOS7中我得到了错误 CGSize labelHeight = [tweetText sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(self.tweetsTableView.bounds.size.width - 84, 4000)]; 下面是完整的方法,关于如何修改iOS7有什么想法吗 - (CGFloat)heightForCellAtIndex:(

我在iOS6中使用了下面的方法,但是在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;
}

我知道这是一个老生常谈的问题&迟来的回答,但它仍然非常相关

此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;
因此,您可以将标签(或表格单元格等)调整为


我希望这会有帮助,干杯,吉姆。

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

此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;
因此,您可以将标签(或表格单元格等)调整为

我希望这有帮助,干杯,吉姆。

添加以下内容:

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

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