UIImageView Programmatically In Swift 5

This tutorial for Adding UIImageView inside UIView Programmatically. Also apply the other properties like cornerRadius, BorderWidth, BorderColor, etc on UIImageView.





UIImageView Code Swift 5:
let imageV = UIImageView(frame: CGRect(x: 50, y: 100, width: 200, height: 150))
    imageV.center = view.center
    imageV.layer.cornerRadius = 10
    imageV.clipsToBounds = true
    imageV.layer.borderWidth = 2.0
    imageV.layer.borderColor = UIColor.red.cgColor
    imageV.image = UIImage(named: "devImage", in: Bundle(for: type(of: self)), compatibleWith: nil)
    view.addSubview(imageV)

Output:





Thanks.

UIImageView Programmatically In Swift 5 UIImageView Programmatically In Swift 5 Reviewed by KIRIT MODI on 21:57:00 Rating: 5

No comments:

Powered by Blogger.