表达式的类型是没有更多上下文的ambiguos

时间:2016-03-25 17:36:46

标签: ios xcode swift

text.drawInRect(aRectangle, withFont: font, lineBreakMode: .UILineBreakModeTailTruncation, alignment: .Center)

我在.UILineBreakModeTailTruncation中收到错误...所以我该如何解决? 我正在使用Xcode 7,swift 2

我得到另一个错误,这是: ' drawInRect(_:withFont:lineBreakMode:对准:)'不可用..我怎么解决???

谢谢.. !!!

1 个答案:

答案 0 :(得分:3)

您传递的枚举值不正确,您应该传递值:

text.drawInRect(aRectangle, withFont: font, lineBreakMode: .TailTruncation, alignment: .Center)

text.drawInRect(aRectangle, withFont: font, lineBreakMode: UILineBreakMode.TailTruncation, alignment: .Center)

FYI

UILineBreakMode is deprecated(从iOS 6开始),您应该使用NSLineBreakMode。所以上面的代码改为:

text.drawInRect(aRectangle, withFont: font, lineBreakMode: .ByTruncatingTail, alignment: .Center)

text.drawInRect(aRectangle, withFont: font, lineBreakMode: NSLineBreakMode.ByTruncatingTail, alignment: .Center)