我想用NSMutableAttributedString
文字来绘制CATextLayer
文字。我尝试将属性设置为类似的字体和字体颜色,但忽略NSMutableAttributedString
其中的[attrString setAttributes:attributes range:range];
所有属性。NSMutableParagraphStyle
let str = "I want to use NSMutableAttributedString to draw the text on the CATextLayer with the text. I try set attributes to the like font and fontcolor of the NSMutableAttributedString through the [attrString setAttributes:attributes range:range]; but all attributes in the NSMutableParagraphStyle are ignored."
let att = NSMutableAttributedString(string: str)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 12
att.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, str.characters.count))
let contentLayer = initTextLayer("", andFontSize: 11)
contentLayer.string = att
contentLayer.frame = CGRect(x: 30 * AUTOSIZESCALEX, y: CGRectGetMaxY(titleLayer.frame) + 15 * AUTOSIZESCALEY, width: SCREEN_WIDTH - 60 * AUTOSIZESCALEX, height: 200 * AUTOSIZESCALEY)
self.contentView.layer.addSublayer(contentLayer)
func initTextLayer(title: String, andFontSize size: CGFloat) -> CATextLayer{
let textLayer = CATextLayer()
textLayer.foregroundColor = UIColor(hexString: "333333").CGColor
textLayer.string = title
textLayer.alignmentMode = kCAAlignmentLeft
textLayer.contentsScale = UIScreen.mainScreen().scale
textLayer.shouldRasterize = false
textLayer.wrapped = true
textLayer.fontSize = size * AUTOSIZESCALEY
return textLayer
}
有什么我做错了吗?