tbointeractive / bytes

bytes is a set of Swift tools to cover many all-day tasks in iOS development.
MIT License
7 stars 1 forks source link

UIImage with color #11

Closed brototyp closed 6 years ago

brototyp commented 6 years ago

From time to time it is helpful to generate a 1x1 sized image with just one color. For example if one wants to set the background color of a UIButton in the highlighted state.

Thus I propose the following function.

extension UIImage {

   // Returns a 1x1 sized image of just that color
   static func with(_ color: UIColor) -> UIColor

}

Things open for discussion: Should we add any caching?

brototyp commented 6 years ago

Let me know if you accept pull requests for this. I will happily implement this.

pstued commented 6 years ago

Since this is "just" an extension of a UIImage I wouldn't do any caching. If someone is using this heavily, they should also do the caching in my opinion.

What about extending the function to allow different sizes of colored Images?

static function with(_ color: UIColor, size: CGSize = CGSize(1,1)) -> UIImage
pstued commented 6 years ago

But in general I'm fine with that piece of byte :)

brototyp commented 6 years ago

@achelsmar Thanks for your feedback.

About the caching. I just added a very simple one but I am open to discussions about that one.

About different sizes: What would be the point in doing that? In the end there is no information added, right? If you want to display a 2x2 square (or what ever size) in the same color one can simply stretch the 1x1 image, right? Or did I miss a point that you had in mind?