Guest User

Untitled

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /**
  2. Holds application wide common theme, all controls use this for base values before their own or subclass customisation
  3. */
  4. public class CommonTheme {
  5. struct appearance {
  6. var defaultBorderColor: UIColor
  7. }
  8.  
  9. //Defaults, set/changed at app / module startup
  10. static var appearance: Appearance = Appearance( var defaultBorderColor: UIColor.black)
  11. }
  12.  
  13. /**
  14. 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
  15. */
  16. public class CustomControl {
  17. struct Appearance {
  18. var defaultBorderColor: UIColor
  19. var backgroundImage: UIImage?
  20. }
  21.  
  22. //Defaults if application specific subclass doesn't override
  23. var appearance: Appearance {
  24. return Appearance(
  25. defaultBorderColor: CommonTheme.appearance.defaultBorderColor
  26. backgroundImage: nil)
  27. }
  28.  
  29. //If left as default in IB, will use class settings
  30. @IBInspectable var defaultBorderColor: UIColor!
  31. @IBInspectable var backgroundImage: UIImage?
  32.  
  33. /**
  34. Use IB override if available, else use class default
  35. */
  36. fileprivate func setupDefaults() {
  37. if defaultBorderColor == nil {
  38. defaultBorderColor = appearance.defaultBorderColor
  39. }
  40.  
  41. if backgroundImage == nil {
  42. backgroundImage = appearance.backgroundImage
  43. }
  44. }
  45.  
  46. //Functionality for control goes here
  47. }
  48.  
  49. /**
  50. Customise module specific settings for control
  51. */
  52. class MoneyAppCustomControl: CustomControl {
  53. override var appear: Appearance {
  54. return Appearance(
  55. defaultBorderColor: super.defaultBorderColor, //No class specific override
  56. backgroundImage: UIImage(named: "CustomControlBackgroundImage"))
  57. )
  58. }
  59.  
  60. //Nothing else goes here, this one is just customising the appearance struct
  61. }
Add Comment
Please, Sign In to add comment