Tod*_*ddB 3 iphone objective-c nsstring ios
为什么这不起作用?无论弦的长度如何,它总是返回18.有这个主题,但不是一个明确的答案.
NSString * t = @"<insert super super long string here>";
CGSize size = [t sizeWithFont:[UIFont systemFontOfSize:14.0] forWidth:285 lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"size.height is %f and text is %@", size.height, t);
Run Code Online (Sandbox Code Playgroud)
谢谢,
托德
请sizeWithFont:constrainedToSize:lineBreakMode:改用.
NSString * t = @"<insert super super long string here>";
CGSize constrainSize = CGSizeMake(285, MAXFLOAT);
CGSize size = [t sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:constrainSize lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"size.height is %f and text is %@", size.height, t);
Run Code Online (Sandbox Code Playgroud)