0

I'm using a library for message cells in Obj-C and I'm bridging from Swift. Here are the 2 lines of code I'm trying to convert to iOS8 compatibility.

+(CGSize)messageSize:(NSString*)message {
return [message sizeWithFont:[UIFont systemFontOfSize:messageTextSize] constrainedToSize:CGSizeMake([PTSMessagingCell maxTextWidth], CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
}

and

CGSize dateSize = [self.timeLabel.text sizeWithFont:self.timeLabel.font forWidth:[PTSMessagingCell maxTextWidth] lineBreakMode:NSLineBreakByClipping];

My attempt for both are as follows. I'm not a seasoned Obj-C coder, so go easy on me.

+(CGSize)messageSize:(NSString*)message {
return [message sizeWithAttributes:@{NSFontAttributeName:PTSMessagingCell}];
}

and

CGSize dateSize = [self.timeLabel.text sizeWithAttributes:@{NSFontAttributeName:PTSMessagingCell}];

Are my attempts correct translations of the first 2 snippets?

user83039
  • 3,047
  • 5
  • 19
  • 31
  • But...what's your question? – Jack Nov 21 '14 at 20:48
  • Am I correct with my attempts to convert these? – user83039 Nov 21 '14 at 20:53
  • You don't capture the linebreak modes, you need to use `NSParagraphStyleAttributeName`. See http://stackoverflow.com/questions/18948180/align-text-using-drawinrectwithattributes – Jack Nov 21 '14 at 20:55
  • Also a dupe of http://stackoverflow.com/questions/18903304/replacement-for-deprecated-sizewithfontconstrainedtosizelinebreakmode-in-ios?lq=1 – rmaddy Nov 22 '14 at 00:14

0 Answers0