以下是绘制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)
请指出是否遗漏了某些内容。谢谢。