Adding padding and border to an UIImageView

后端 未结 2 532
梦谈多话
梦谈多话 2021-01-04 11:13

How can I add padding between an UIImageView and its border?

Img.layer.cornerRadius = Img.bounds.width / 2
Img.layer.borderWidth = 2
Img.layer.         


        
2条回答
  •  执笔经年
    2021-01-04 11:39

    For adding padding to the UIImage of UIImageView, use the below piece of code in Swift

    let padding: CGFloat = 6    
    myImageView.contentMode = .scaleAspectFill
    myImageView.image = UIImage(named: "myImage.png").resizableImage(withCapInsets: UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), resizingMode: .stretch)
    

提交回复
热议问题