I have a UIButton
and i want to add a circle badge on top of it, here is how it looks.
public func addCircleBadge(_ width: CGFloat, color: UIColor) {
let bounds = self.mybtn.bounds
let layer = CAShapeLayer()
let radius = width / 2
layer.path = UIBezierPath(roundedRect: CGRect(x: bounds.width - (radius + 2.0), y: bounds.minY - (radius-2.0), width: width, height: width), cornerRadius: radius).cgPath
layer.fillColor = color.cgColor
layer.zPosition = 999
layer.name = "circleBadge"
self.mybtn.layer.addSublayer(layer)
}
and in viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
mybtn.layer.borderColor = UIColor.blue.cgColor
mybtn.layer.cornerRadius = 3.0
mybtn.layer.borderWidth = 2.0
mybtn.contentEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
addCircleBadge(20, color: UIColor.red.withAlphaComponent(1.0))
}
but this layer is looking transparent, so the button area is visible, i want to have an opaque layer on top of button. can it be done through layer or do i need to add a different view and place both button and this separate UIView
in a common view