将CAShapeLayers添加为子图层后,如何将UIButton的titleLabel添加到前面?

时间:2017-07-12 19:37:09

标签: ios swift uibutton cashapelayer

以下是绘制CAShapeLayer并将其添加到UIButton

的代码
let button = self.pickerButton as UIButton
let circleShape = CAShapeLayer()
let circlePath = UIBezierPath.init()//drawing the circle here
circleShape.path = circlePath.cgPath
button.layer.addSublayer(circleShape)

使用以下两种方法将文本添加到UIButton并将其置于前面:

方法1

button.setTitle("pick this one", for: .normal)
button.setTitleColor(UIColor.black, for: .normal)

方法2

button.titleLabel?.text = "pick this one"
button.titleLabel?.textColor = UIColor.black
button.bringSubview(toFront: button.titleLabel)

请指出是否遗漏了某些内容。谢谢。

0 个答案:

没有答案