Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Holds application wide common theme, all controls use this for base values before their own or subclass customisation
- */
- public class CommonTheme {
- struct appearance {
- var defaultBorderColor: UIColor
- }
- //Defaults, set/changed at app / module startup
- static var appearance: Appearance = Appearance( var defaultBorderColor: UIColor.black)
- }
- /**
- A custom control using cascading theme settings - Common theme, can be overridden by module specific theme, can be overridden by subclass specific theme, can be overriden by IB settings
- */
- public class CustomControl {
- struct Appearance {
- var defaultBorderColor: UIColor
- var backgroundImage: UIImage?
- }
- //Defaults if application specific subclass doesn't override
- var appearance: Appearance {
- return Appearance(
- defaultBorderColor: CommonTheme.appearance.defaultBorderColor
- backgroundImage: nil)
- }
- //If left as default in IB, will use class settings
- @IBInspectable var defaultBorderColor: UIColor!
- @IBInspectable var backgroundImage: UIImage?
- /**
- Use IB override if available, else use class default
- */
- fileprivate func setupDefaults() {
- if defaultBorderColor == nil {
- defaultBorderColor = appearance.defaultBorderColor
- }
- if backgroundImage == nil {
- backgroundImage = appearance.backgroundImage
- }
- }
- //Functionality for control goes here
- }
- /**
- Customise module specific settings for control
- */
- class MoneyAppCustomControl: CustomControl {
- override var appear: Appearance {
- return Appearance(
- defaultBorderColor: super.defaultBorderColor, //No class specific override
- backgroundImage: UIImage(named: "CustomControlBackgroundImage"))
- )
- }
- //Nothing else goes here, this one is just customising the appearance struct
- }
Add Comment
Please, Sign In to add comment