From 12012ce8c81fdeb5478fc643d2827e0f90e8291f Mon Sep 17 00:00:00 2001 From: Eric Kille Date: Mon, 27 Feb 2017 15:09:10 -0500 Subject: [PATCH 1/2] Use backgroundColor instead of backgroundImage for setting a buttons background color --- StyleKit/StyleKit/ButtonStylist.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StyleKit/StyleKit/ButtonStylist.swift b/StyleKit/StyleKit/ButtonStylist.swift index 16930e9..0d83e09 100644 --- a/StyleKit/StyleKit/ButtonStylist.swift +++ b/StyleKit/StyleKit/ButtonStylist.swift @@ -130,7 +130,7 @@ extension UIButton { func assignColors(_ colors: ColorStyle, forState state: UIControlState, resources:CommonResources) { if let colorKey = colors.backgroundColor, let color = resources.colors[colorKey] { - self.setBackgroundImage(UIImage.imageWithColor(color), for: state) + self.backgroundColor = color } if let colorKey = colors.textColor, let color = resources.colors[colorKey] { self.setTitleColor(color, for: state) From c69405e870105ce6f42a4dbced2c119cd075e30c Mon Sep 17 00:00:00 2001 From: Eric Kille Date: Mon, 27 Feb 2017 16:34:52 -0500 Subject: [PATCH 2/2] Going back to using image as background color since it supports control states. Using a 1x1 pixel images instead of 0.5x44 fixes washed out color issue with button backgrounds. --- StyleKit/StyleKit/ButtonStylist.swift | 2 +- StyleKit/StyleKit/Utils.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/StyleKit/StyleKit/ButtonStylist.swift b/StyleKit/StyleKit/ButtonStylist.swift index 0d83e09..16930e9 100644 --- a/StyleKit/StyleKit/ButtonStylist.swift +++ b/StyleKit/StyleKit/ButtonStylist.swift @@ -130,7 +130,7 @@ extension UIButton { func assignColors(_ colors: ColorStyle, forState state: UIControlState, resources:CommonResources) { if let colorKey = colors.backgroundColor, let color = resources.colors[colorKey] { - self.backgroundColor = color + self.setBackgroundImage(UIImage.imageWithColor(color), for: state) } if let colorKey = colors.textColor, let color = resources.colors[colorKey] { self.setTitleColor(color, for: state) diff --git a/StyleKit/StyleKit/Utils.swift b/StyleKit/StyleKit/Utils.swift index 8562e6e..63068bc 100644 --- a/StyleKit/StyleKit/Utils.swift +++ b/StyleKit/StyleKit/Utils.swift @@ -52,7 +52,7 @@ extension Int { extension UIImage { class func imageWithColor(_ color: UIColor) -> UIImage { - let rect = CGRect(x: 0, y: 0, width: 0.5, height: 44.0) + let rect = CGRect(x: 0, y: 0, width: 1.0, height: 1.0) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() context!.setFillColor(color.cgColor);