Home > Software design >  Why UIImageView does not render image in UIView?
Why UIImageView does not render image in UIView?

Time:10-18

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)
    }

CodePudding user response:

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.

  • Related