Swift代码语法问题

时间:2015-10-24 17:33:41

标签: swift cocoa

我试图获得具有固定宽度的NSAttributedString的高度。我收到的错误是:

使用未解析的标识符' NSStringDrawingUsesLineFragmentOrigin'

任何帮助将不胜感激。我的代码如下:

let string: NSAttributedString = self.attributedStringValue
let width: CGFloat = self.frame.size.width * 0.95;
var rect: CGRect = string.boundingRectWithSize(CGSizeMake(width, CGFLOAT_MAX), options: NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading, context: nil)

1 个答案:

答案 0 :(得分:0)

Swift 2已将许多枚举更改为选项集类型,用此替换最后一行:

var rect: CGRect = string.boundingRectWithSize(CGSizeMake(width, CGFLOAT_MAX), options: [.UsesLineFragmentOrigin, .UsesFontLeading], context: nil)

如果您想知道值名称的来源,请点击documentation