Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why UIImageView does not render image in UIView?

I am able to set system image as a button icon and add subviews under views but whatever I try, UIImageView never renders a system image. What am I doing wrong?

    override func viewDidLoad() {
        super.viewDidLoad()

        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        imageView.image = UIImage(named: "pencil")
        imageView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(imageView)
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You should use UIImage(systemName: "pencil") initializer instead of UIImage(named: "pencil") in order to use images from SFSymbols. You can read more about it here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading