Reputation: 23
I am fairly new at creating iOS apps and I have a question about a common practice regarding central Text & Color styling in a project.
What I want to do is to define a custom "Header" style, custom "ToolBar" style, custom "Body" style etc. and use them in different UIControlViews in my project.
I want to be able to change one of these styles so that every object using that style adjusts accordingly.
As much as I understand there are no CSS-like styling files when designing an iOS app.
What I was thinking to do is to create a Swift file where my styles are defined as constants in some way and add code blocks in all viewDidLoad
methods of UIViewController
s that sets related objects' styles by using these constants.
Is there a better way, or what is the common practice for doing that kind of thing?
Upvotes: 2
Views: 449
Reputation: 1791
I have been using the pod NUI for styling the complete iphone Application. There are couple of other options like UISS.
There are few other commercial options also, but the above two do a fantastic job of externalizing the styling of the application.
I've used NUI and it enables me to provide multiple themes and even allow the end user to switch themes.
Upvotes: 0
Reputation: 39081
Many classes has the protocol UIAppearance
which sets their default properties such as font, textColor, backgroundColor etc.
Ex:
UIButton.appearance().backgroundColor = UIColor.redColor()
List of all classes using UIAppearance
Upvotes: 4
Reputation: 3791
Read about view controller polymorphism and view controller hierarchy.
Base a "parent" view controller on UITableViewController
, and include your common properties and methods.
Then base all the "child" view controllers on that "parent".
For example in Objective C:
"Parent" view controller header file...
#import <UIKit/UIKit.h>
@interface MyParentTableViewController : UITableViewController
@end
"Child" view controller header file...
#import <UIKit/UIKit.h>
@interface MyChildTableViewController : MyParentTableViewController
@end
So in this manner all public properties and methods of the parent become available to the child, and only need be written once, in the parent implementation file.
Upvotes: 0
Reputation: 837
As you said create a configuration.swift file that contains your configuration and returns a view based on configuration and then use this configuration to create a custom view. This is the way I did in my last app. Also, check this snippet to get an actual understanding of what I said http://www.objc.io/snippets/20.html
Upvotes: 2