tombenner / nui

Style iOS apps with a stylesheet, similar to CSS
MIT License
3.76k stars 461 forks source link

UIButton background color blending #339

Open Emailrus opened 8 years ago

Emailrus commented 8 years ago

Might be related to this issue

When you have a button with defined non-clear backgroundColor (for example in interface builder), any background-color style with translucency will be blending with it, which is undesired.

Possible solutions might be reseting backgroundColor to clear in NUIButtonRenderer or give user opportunity to set backgroundColor of a view in .nss file.

Stunner commented 8 years ago

This talks about solving that very problem (for UIButton). However, that capability is not yet finished to the point where it may be merged back into this repo; but I have successfully used that code in a few apps of mine running in production. Hopefully, that may suffice for the time being.

Emailrus commented 8 years ago

Having custom blocks for styles is ok, but I think this particular situation should be working out of a box.

Stunner commented 8 years ago

Possible solutions might be reseting backgroundColor to clear in NUIButtonRenderer or give user opportunity to set backgroundColor of a view in .nss file.

Background color can be set on UIView instances from .nss file. The color transparency blending issue isn't the only problem as it boils down to a lack of a setColor:forState: method for the UIButton class. The lack of this method causes NUI to be forced to do a hack where it instead tints an image to the specified color, which causes untrue colors to be set for UIButton instances with NUI. The best thing we can possibly do in this case is to leave it up to the developer to do exactly what (s)he would like to in that instance. Thus, the (main) reason why I created overridable properties.

If you have a good idea for what the default behavior should be, I'd be happy to hear it. But it is important to realize people will expect it to more-or-less work out of the box. And although the current solution isn't ideal, it does manage to make the most of what we have access to; all while preventing overly unexpected behavior.

Emailrus commented 8 years ago

As I said, reset backgroundColor to clear color in NUIButtonRenderer, if background-color related properties have any value

Stunner commented 8 years ago

Sure, that's a band aid fix, but you are still going to notice the color specified in the style sheet as slightly off due to the image color tinting hack that NUI currently uses.

Since I take it your are currently experiencing this issue and can readily test it. I'll leave it to you to submit a pull request. On Mon, Mar 14, 2016 at 4:13 AM Emil notifications@github.com wrote:

As I said, reset backgroundColor to clear color in NUIButtonRenderer, if background-color related properties have any value

— Reply to this email directly or view it on GitHub https://github.com/tombenner/nui/issues/339#issuecomment-196262625.

Emailrus commented 8 years ago

Hmm, now I'm not sure if I understood you correctly before. What do you mean by color tinting hack being slightly off? From what I see NUIConverter creates UIImage based on the color you specify in nss file and then NUIButtonRenderer uses it as a background image in UIButton. Is there something I missed?

As for me, I just made a workaround by setting background color as clear in my xib files.