0

As you can see from the picture, despite the "masksToBounds" I see the layer under the botton x. How can I solve?

class StickerView: UIImageView {

let stickerIdentifier: String

let xButton = UIButton().then {
    $0.setImage(Asset.delete_sticker.image.withRenderingMode(.alwaysOriginal), for: .normal)
    $0.layer.cornerRadius = 30/2
    $0.imageView?.contentMode = .scaleAspectFit
    $0.layer.masksToBounds = true
    $0.alpha = 1
    $0.translatesAutoresizingMaskIntoConstraints = true
}

init(frame: CGRect, name: String) {
    self.stickerIdentifier = "\(name.replacingOccurrences(of: ".png", with: ""))"
    super.init(frame: frame)
    setLayout()
}

func setLayout() {
    self.addSubview(xButton)
    self.bringSubviewToFront(xButton)
    self.xButton.activate([
        self.xButton.topAnchor.constraint(equalTo: self.topAnchor, constant: -10),
        self.xButton.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 10),
        self.xButton.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.15),
        self.xButton.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.15),
        ])
}

layer

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • Try, add xButton after adding your sticker image. – Anand Kore Nov 21 '18 at 11:15
  • @AnandKore I check, but not work.. –  Nov 21 '18 at 11:43
  • Have you checked that the "X" button is actually above the white border (if that is what you are trying to achieve) - theview debugger might help https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/special_debugging_workflows.html – Flexicoder Nov 21 '18 at 11:56
  • @Flexicoder Yes, I just checked how you told me in Debug. and the x button is located above the layer .. I do not know why but I still see the layer under the button –  Nov 21 '18 at 13:11
  • You might need to share the code that combines the x button and the sticker view for people to be able to help you further – Flexicoder Nov 21 '18 at 13:45
  • 1
    Possible duplicate of [Subview appears underneath superviews layer.border?](https://stackoverflow.com/questions/15490720/subview-appears-underneath-superviews-layer-border) – DonMag Nov 21 '18 at 13:45

0 Answers0