sizeWithFont:constrainedToSize - iOS7

Имам следния метод, който използвах в 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;
}

person flangle    schedule 02.11.2013    source източник


Отговори (2)


Знам, че това е стар въпрос и късен отговор, но все още е много уместен,

Този метод 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;

Надявам се това да помогне, наздраве, Джим.

person Jim Tierney    schedule 26.01.2014

Добавете тези редове:

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