【发布时间】:2018-07-12 11:22:48
【问题描述】:
我写了这段代码:
let myAttributes = [
NSAttributedStringKey.font: UIFont(name: "Avenir-HeavyOblique", size: 15.0)! ,
NSAttributedStringKey.foregroundColor: UIColor.white
]
let myAttributedString = NSAttributedString(string: textRightUpLabel!, attributes: myAttributes )
let textLayer = CATextLayer()
textLayer.string = myAttributedString
textLayer.backgroundColor = UIColor.clear.cgColor
textLayer.frame = CGRect(x: self.frame.size.width - width + textMarginRightUpLabel, y: 8, width: width, height: height)
self.layer.addSublayer(textLayer)
这很好用,但它似乎添加了 2 层,如何在我的故事板中显示:
所以问题是:为什么文本“3 DAYS LEFT”会显示 2 次?一个在好地方,另一个在 ShapeLayer 后面?
感谢您的回复
【问题讨论】:
-
其余代码在哪里。这是可设计的吗?
-
@agibson007 是的,这是一个可设计的类
-
那么你在哪里调用这个方法。多少次?我们需要剩下的代码来确定为什么会有多个实例。
-
@agibson007 是的,每次我更新情节提要时,都会调用该函数:pastebin.com/mgma51SG
标签: ios iphone swift xcode layer