【发布时间】:2016-04-14 14:36:04
【问题描述】:
我试图在图像顶部放置一些文本,该图像将位于图像顶部的 CGRect 中心。下面是一段代码:
let textColor: UIColor = UIColor.whiteColor()
let textFont: UIFont = UIFont(name: "Helvetica Bold", size: 17
)!
let textAlignment = NSTextAlignment.Center
let textFontAttributes = [
NSFontAttributeName: textFont,
NSForegroundColorAttributeName: textColor,
NSTextAlignment: textAlignment
]
myString.drawInRect(rect, withAttributes: textFontAttributes)
问题在于文本对齐方式。当我这样写时,我得到一个错误:
没有更多上下文的表达类型是模棱两可的
当我将键和值类型设置为 [String : AnyObject] 时,编译器再次报错:
无法将“NSTextAlignment.Type”类型的值转换为预期的字典键类型“String”
我明白了。我对此进行了大约两个小时的研究,但没有找到任何最新的解决方案,也没有找到一个如何使用 Swift 编写云的解决方案。
【问题讨论】: