以编程方式正确校正图层

时间:2018-11-21 11:02:43

标签: ios iphone swift layer

从图片中可以看到,尽管出现了“ masksToBounds”,但我仍然看到了botton x下的图层。我该怎么解决?

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

0 个答案:

没有答案