From 324a5bc3fb8a329181d5755c62fd5646adabbecf Mon Sep 17 00:00:00 2001 From: Scott Ludwig Date: Sun, 3 Jan 2016 23:21:34 -0800 Subject: [PATCH] Replace deprecated sizeWithFont with sizeWithAttributes --- game/iphone/chatcell.mm | 6 +++++- game/iphone/chatviewcontroller.mm | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/game/iphone/chatcell.mm b/game/iphone/chatcell.mm index 458f475..d4b5fe7 100644 --- a/game/iphone/chatcell.mm +++ b/game/iphone/chatcell.mm @@ -39,7 +39,11 @@ chatLabel_.frame = frame; nameLabel_.text = user; frame = nameLabel_.frame; - frame.size = [user sizeWithFont:nameLabel_.font]; + + CGSize sizeFont = [user sizeWithAttributes:@{NSFontAttributeName: nameLabel_.font}]; + frame.size.height = ceilf(sizeFont.height); + frame.size.width = ceilf(sizeFont.width); + nameLabel_.frame = frame; // length 0 means system message diff --git a/game/iphone/chatviewcontroller.mm b/game/iphone/chatviewcontroller.mm index 9f3b55d..5b1c91d 100644 --- a/game/iphone/chatviewcontroller.mm +++ b/game/iphone/chatviewcontroller.mm @@ -31,8 +31,8 @@ suspended_ = NO; chatEntries_ = [[NSMutableArray alloc] initWithCapacity:CHAT_HISTORY]; entryFont_ = [UIFont systemFontOfSize:12]; - CGSize size10Spaces = [@" " sizeWithFont:entryFont_]; - width10Spaces_ = size10Spaces.width; + CGSize size10Spaces = [@" " sizeWithAttributes:@{NSFontAttributeName: entryFont_}]; + width10Spaces_ = ceilf(size10Spaces.width); chatc_ = NULL; title_ = @"Chat"; [title_ retain]; @@ -458,8 +458,8 @@ // Insert spaces into chat so that user's name can draw into that // space with a different UILabel. Hack-o-rama. - CGSize sizeUser = [newUser sizeWithFont:entryFont_]; - CGFloat ratio = sizeUser.width / width10Spaces_; + CGSize sizeUser = [newUser sizeWithAttributes:@{NSFontAttributeName: entryFont_}]; + CGFloat ratio = ceilf(sizeUser.width) / width10Spaces_; int countSpaces = ceil(ratio * 10.0) + 2; char szSpaces[256]; @@ -535,12 +535,15 @@ // Calculate what the height is, cache it, return it NSString *chat = (NSString *)[entry objectForKey:@"chat"]; - CGSize sizeBox = CGSizeMake(width, 2800); - CGSize size = [chat sizeWithFont:entryFont_ constrainedToSize:sizeBox - lineBreakMode:UILineBreakModeWordWrap]; - value = [NSString stringWithFormat:@"%d", (int)size.height]; + CGRect rect = [chat boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) + options: NSStringDrawingUsesLineFragmentOrigin + attributes: @{ NSFontAttributeName: entryFont_ } + context:nil]; + CGFloat height = ceilf(rect.size.height); + + value = [NSString stringWithFormat:@"%d", (int)height]; [entry setObject:value forKey:key]; - return size.height; + return height; } - (void)doClear