如何在UIImageView上圆角和阴影

时间:2018-09-29 02:50:39

标签: swift uiimage rounded-corners dropshadow roundedcorners-dropshadow

我已经尝试了几乎所有内容,但是完全不知道如何在图像视图上同时获得圆角和阴影。这就是我目前所拥有的,它只会有圆角或阴影,而不会同时有两者。

Exporter::import

也尝试过:

class ImageRoundedCorner: UIImageView {

    override func awakeFromNib() {
        super.awakeFromNib()


        self.clipsToBounds = false
        self.layer.shadowColor = UIColor.black.cgColor
        self.layer.shadowOpacity = 1
        self.layer.shadowOffset = CGSize.zero
        self.layer.shadowRadius = 10
        self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: 10).cgPath

        let image = UIView(frame: self.bounds)
        self.clipsToBounds = true
        self.layer.cornerRadius = 7

        self.addSubview(image) 

    }
}

0 个答案:

没有答案