我正在尝试编写一些代码,但我在标题中得到了错误......这是代码...
let text: NSString = messages[indexPath.row] as! NSString
var size: CGSize = text.boundingRectWithSize(CGSizeMake(240.0, 480.0), options: NSStringDrawingOptions.UsesDeviceMetrics, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14.0)], context: nil)
我在第二行得到错误
另外,我有Objective-C代码,没问题......但我喜欢它在Swift中
NSString *text = [messages objectAtIndex:indexPath.row];
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0f, 480.0f) lineBreakMode:UILineBreakModeWordWrap];
提前致谢!!!
答案 0 :(得分:6)
尝试将.size
添加到最后,例如:
var size:CGSize = text.boundingRectWithSize(CGSizeMake(240.0, 480.0), options: NSStringDrawingOptions.UsesDeviceMetrics, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14.0)], context: nil).size