Open fpaaske opened 11 years ago
Try NUISettings for getting values for a class for now.
Ah, but If I was to use this I'd need to create a class in the nss
and add a property for each nss variable
I need. It doesn't sound awesome. I'd like to access the variables directly.
Anyway, if anyone has the time I'd appreciate a method for getting color by variable name, not class property. Until then I'll just use NUISettings
. Thanks!
I'd like to access the variables directly.
I think you missunderstand how this works. Variables are just placeholders, they are not real obj-c variables. The .nss file is just like a plist file, it's text, and it does not gets compiled. NUISettings is the only way to go.
No, I understand that the @-variables in the nss file are just placeholders, but at some point they are parsed and substituted within the nss-class blocks. At some time during that process, they could be loaded into a map/dictionary for manual retrieval later. It makes no sense to manually load a resource for a specific nss-class (e.g. SomeButton) to use it in a completely different UI element (e.g. SIAlertView's button number three).. The only way that makes sense is if you make a nss-class for the specific resource, then load and apply it manually. But that feels wrong, that you have the class, but must apply it manually.
It makes no sense to manually load a resource for a specific nss-classs
I had no such problem. The NUISettings contains a dirtionary that you can read via the class name. The file is parsed only once and you read from that everytime.
If you only want to access specific variables values, just create a nui-class that contains those values. But usign the nuiClass
property is much cleaner.
What do you mean by 'using the nuiClass
property'? Can you give a small example of how you'd do it? Maybe I'm totally missing the point here :)
self.view.nuiClass = @"MyClass";
In your controller. You need to import UIView+NUI.h file
See this section of the README: https://github.com/tombenner/nui#setting-an-elements-style-class-programmatically
Ok, I wasn't missing the point after all :-)
Yes, I do this for the UI elements I have control over. But sometimes I need to style 3rd party UI elements (like SIAlertView, which supports UIAppearance). For that I can't set the nuiClass anymore, at least not without inspecting/modifying their source code. This is the particular use case that triggered this request.
To achieve this in today's NUI I'd have to create a class in nss, add all the styling I need
@alertDestructiveButtonColor: #ff0000;
...
SIAlertViewHolder {
destructive-button-background-color: @alertDestructiveButtonColor;
...
}
then for each styling parameter, use [NUISettings getColor: withClass:]
to get the resource and use it with the correct UIAppearance
method.
UIColor *destructiveColor = [NUISettings getColor:@"destructive-button-background-color" withClass:@"SIAlertViewHolder"];
[[SIAlertView appearance] setDestructiveButtonColor:destructiveColor];
It's not totally bad, but it adds overhead and complexity to the code and its maintainability.
I'd still like to do it like this:
[[SIAlertView appearance] setDestructiveButtonColor:
[NUISettings getColor:@"alertDestructiveButtonColor"]];
It is cleaner, more intuitive and has much less config/nss (only one string that can be mistyped).
Having something like:
[NUISettings getColorByName:@"someCustomColorName"]];
would just awesome.
Getting values of defined variables (in .nui file) is convenient. I think that stuff should be in NUI library
When using 3rd party components that supports UIAppearance (e.g. SIAlertView), it would be nice to do something like
[NUISettings setGlobalExclusions:@[@"SIAlertView"]];
then
[[SIAlertView appearance] setButtonColor:[NUIAppearance getColor:@"primaryButtonColor"];
[[SIAlertView appearance] setCancelButtonColor:[NUIAppearance getColor:@"cancelButtonColor"];