From ac916c3027639d17b0a7ee06fc1067bf1bea011a Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 22 Sep 2014 18:01:13 +0800 Subject: [PATCH] Cocos2d-x used a deprecated method to get the content size of a CCLabelTTF on iOS 7. --- cocos/platform/ios/CCDevice-ios.mm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cocos/platform/ios/CCDevice-ios.mm b/cocos/platform/ios/CCDevice-ios.mm index c76cf531a4..de01f7311b 100644 --- a/cocos/platform/ios/CCDevice-ios.mm +++ b/cocos/platform/ios/CCDevice-ios.mm @@ -221,7 +221,14 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize textRect.height = constrainSize->height > 0 ? constrainSize->height : 0x7fffffff; - CGSize dim = [str sizeWithFont:font constrainedToSize:textRect]; + CGSize dim; + if(s_isIOS7OrHigher){ + NSDictionary *attibutes = @{NSFontAttributeName:font}; + dim = [str boundingRectWithSize:textRect options:(NSStringDrawingOptions)(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attibutes context:nil].size; + } + else { + dim = [str sizeWithFont:font constrainedToSize:textRect]; + } dim.width = ceilf(dim.width); dim.height = ceilf(dim.height);