How to standardize look and feel across my iphone app
I'm trying to figure out how to create a standard look and feel across my iphone app. So if I ever wanted to change the background for the UIView I would normally do something like this in all my view controllers:
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]
This becomes quite redundant and error-prone when you have like 50 UIViews to manage. And of course clients change their desired background image every 3 days or so. So my next option is to create helper files, eg:
@implementation GuiDefaultsUIView
+ (void) setDefaultProperties:(UIView *) view {
view.backgroundColor = [UIColor groupTableViewBackgroundColor];
And then manually call [GuiDefaultsUIView setDefaultProperties:self.view];
from each view controller. This works, and it's how I'm doing it now but it means that for every UI object (eg UIButton, UITableView) I'd need to call a similar function for every instance of every class.
What I would like to do is to standardize this so that I get a default look and feel which I can overwrite whenever needed. I've considered Subclassing UIView
/ UIButton
/ UITableView
but that does not seem like a right way to do it. Adding categories would be nice but I dont think overriding the default methods (eg: init) would be the Right Way to go either.
So. how开发者_JS百科 would you standardize your look and feel?
This is a relatively simple one ;)
You just create a custom UIViewController Subclass named MyVievController
for example, and inherit ViewControllers from that class.
Then in the init and viewWillAppear etc. of MyViewController, you can do your customization, just make sure to call super in your subclasses.
You can do the same for UITableViewControllers and even for UIViews, to customize drawing or set standard properties.
We do that in our Apps all the time and it works great.Categories are, in some cases, fine too, for example you can override the drawRect-Method of the UINavigationBar.
What you could do (I've done and seen it in some propjects) is make a class where you store all your constants. Then when you need them just import them and use as appropriate.
Why don't you create a Super class for all of your views? set all the properties you need there and then make every new view that you create inherit from this super class. Lets say that you create a UIView called "PreDesignedUIview" that has your design inside like background color etc.
then whenever you create a new view you should set:
@interface NewView : PreDesignedUIview
this will automatically set your design from PreDesignedUIview to the new view.
What is wrong with that ?
Create a Utility class that stores your background colors and images. Then use these methods to get the images/colors. When you are supposed to change, don't go and call different method fro each file, instead change the color that was being returned from the method in Utility class.
精彩评论