ios – 在Swift中为属性文本添加属性

前端之家收集整理的这篇文章主要介绍了ios – 在Swift中为属性文本添加属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将属性添加到文本标签

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Center

let para = NSMutableAttributedString()
let font:UIFont? = UIFont(name: "DIN Alternate",size: 18.0)
let font2:UIFont? = UIFont(name: "Arial",size: 12.0)
let labelColor = UIColor.whiteColor()
let text="some text"

//A,error appears here
let myAttributes = [NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:font,NSForegroundColorAttributeName:labelColor]

let attrString = NSAttributedString(
    string: csvObject.provideDetailsAsString(poi)!,attributes: myAttributes)
para.appendAttributedString(attrString)     
detailsText.attributedText = para

但是在//行A中的Swift编译器错误并说:

'_' is not convertible to 'String'

我正在使用XCode 6.4和Swift 1.2

解决方法

找到它,加一个!字体后:NSFontAttributeName:font!

font是可选的

猜你在找的Xcode相关文章