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

How to change size and color of image UIButton?

I have the UIButton that I create, like this

        let btn = UIButton()
        view.addSubview(btn)
        btn.setImage(UIImage(systemName: "star"), for: .normal)
        btn.translatesAutoresizingMaskIntoConstraints = false
        btn.frame = CGRect(x: 30, y: 30, width: 150, height: 150)
        btn.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 35).isActive = true
        btn.rightAnchor.constraint(equalTo: btnDelete.leftAnchor, constant: 0).isActive = true
        btn.heightAnchor.constraint(equalToConstant: 44).isActive = true
        btn.widthAnchor.constraint(equalToConstant: 44).isActive = true

the problem is that I see the star icon button, but I can’t find a way to make it bigger and change the color of the star itself, currently it is blue, but I need it white.

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

>Solution :

For make it bigger use below code to fill width and height u giving in btn.frame :

btn.contentHorizontalAlignment = .fill
btn.contentVerticalAlignment = .fill

For make it change the color of icon use :

 btn.tintColor = .white
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