0

I do my swift project using code only no storyboards, so no storyboard solutions please I have an agree to terms button and when selected the checkmark is covered in the tint color I am trying to prevent the tint color highlighting the image when selected I am not sure why this is happening here is the button code

let agreeToTermsAndConditions : UIButton = {
    let button = UIButton(type: .system)
    button.tintColor = .gray
    button.backgroundColor = .white
    button.adjustsImageWhenHighlighted = false  
    button.setImage(UIImage(named:"unchecked" )!, for: .normal)
    button.setImage(UIImage(named:"agreechecked" )!, for: .selected)
    button.addTarget(self, action: #selector(userAgreedToTerms), for: .touchUpInside)
    
    return button
}()

enter image description here

The code is running on xcode 10.2.1 using swift 4 and iOS 12 deployment

1 Answer 1

1

Change

UIButton(type: .system)

to

UIButton(type: .custom)

Now you have complete control over the look and behavior of the button.

Sign up to request clarification or add additional context in comments.

4 Comments

This has unintended side effects though for me. It makes the button different when highlighted.
@Eric Yes, that's the intention. If you have a question because of that, ask it as a question.
Sorry I should have been more specific. It changes the "highlighting" effect which is intended. However, it also changes the actual image itself to the "selected" or "unselected" image, even though the button isn't technically selected or unselected yet (since it's only highlighted). I can post a question about it if this is unclear.
You should post a question about it whether it's clear or not. I'm not going to respond in the comments to a question that is satisfactorily answered. If you have a question for something you want help with, ask it as a question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.