Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate setBackgroundColor from UIButtonExtensions #310

Open
lfarah opened this issue Nov 10, 2016 · 3 comments
Open

Deprecate setBackgroundColor from UIButtonExtensions #310

lfarah opened this issue Nov 10, 2016 · 3 comments

Comments

@lfarah
Copy link
Collaborator

lfarah commented Nov 10, 2016

This method is useless since UIButton.backgroundColor = .black exists since iOS 8.

extension UIButton {
    public func setBackgroundColor(_ color: UIColor, forState: UIControlState) {
        UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
        UIGraphicsGetCurrentContext()?.setFillColor(color.cgColor)
        UIGraphicsGetCurrentContext()?.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
        let colorImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        self.setBackgroundImage(colorImage, for: forState)
    }
}
@piv199
Copy link
Collaborator

piv199 commented Nov 10, 2016

I okay it's inherited from UIView.

But what if I want different different colors for different states?

Especially I faced this method when I had one color for the button, and that color but with less alpha for highlight state.

@lfarah
Copy link
Collaborator Author

lfarah commented Nov 10, 2016

Hmmmmm totally makes sense!

@lfarah lfarah closed this as completed Nov 10, 2016
@Esqarrouth Esqarrouth reopened this Nov 15, 2016
@Esqarrouth
Copy link
Owner

Esqarrouth commented Nov 15, 2016

Wait, lets not disregard this yet. There might be a better way to achieve this with shorter code in new swift. I'm not sure how but lets think about it.

Lets try to solve this without using UIGraphicsImageContext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants