Search code examples
iosswiftuiimageviewcalayeruibezierpath

image appear over UIImageView corner radius border swift


when I set border width and corner radius to UIImageView and load image it appear over border how to fix this problem

let viewedImage : UIImageView = {
    let img = UIImageView()
    img.layer.borderWidth = 1
    img.layer.borderColor = UIColor.lightGray.cgColor
    img.layer.cornerRadius = 28
    return img
}()

enter image description here


Solution

  • try it and tell me it work or not ...

    let viewedImage : UIImageView = {
    
            let img = UIImageView()
            img.layer.cornerRadius = 28
            img.layer.clipsToBounds = true
            img.layer.borderWidth = 2
            img.layer.borderColor = UIColor.lightGray.cgColor
            return img
        }()