BTUIKAppearance.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #import "BTUIKAppearance.h"
  2. #import "UIColor+BTUIK.h"
  3. @interface BTUIKAppearance ()
  4. @property (nonatomic, strong) UIFont *font;
  5. @property (nonatomic, strong) UIFont *boldFont;
  6. @end
  7. @implementation BTUIKAppearance
  8. static BTUIKAppearance *sharedTheme;
  9. + (instancetype)sharedInstance {
  10. static dispatch_once_t onceToken;
  11. dispatch_once(&onceToken, ^{
  12. sharedTheme = [BTUIKAppearance new];
  13. [sharedTheme setDefaultProperties];
  14. [sharedTheme setLightColors];
  15. });
  16. return sharedTheme;
  17. }
  18. - (void)setDefaultProperties {
  19. sharedTheme.font = [UIFont systemFontOfSize:10];
  20. sharedTheme.boldFont = [UIFont boldSystemFontOfSize:10];
  21. sharedTheme.useBlurs = YES;
  22. sharedTheme.postalCodeFormFieldKeyboardType = UIKeyboardTypeDefault;
  23. }
  24. - (void)setLightColors {
  25. sharedTheme.barBackgroundColor = UIColor.whiteColor;
  26. sharedTheme.formBackgroundColor = [UIColor btuik_colorFromHex:@"EFEFF4" alpha:1.0];
  27. sharedTheme.formFieldBackgroundColor = UIColor.whiteColor;
  28. sharedTheme.primaryTextColor = UIColor.blackColor;
  29. sharedTheme.secondaryTextColor = [UIColor btuik_colorFromHex:@"666666" alpha:1.0];
  30. sharedTheme.placeholderTextColor = UIColor.lightGrayColor;
  31. sharedTheme.lineColor = [UIColor btuik_colorFromHex:@"BFBFBF" alpha:1.0];
  32. sharedTheme.blurStyle = UIBlurEffectStyleExtraLight;
  33. sharedTheme.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
  34. [sharedTheme setDefaultColors];
  35. }
  36. - (void)setDarkColors {
  37. sharedTheme.barBackgroundColor = [UIColor btuik_colorFromHex:@"222222" alpha:1.0];
  38. sharedTheme.formBackgroundColor = [UIColor btuik_colorFromHex:@"222222" alpha:1.0];
  39. sharedTheme.formFieldBackgroundColor = [UIColor btuik_colorFromHex:@"333333" alpha:1.0];
  40. sharedTheme.primaryTextColor = UIColor.whiteColor;
  41. sharedTheme.secondaryTextColor = [UIColor btuik_colorFromHex:@"999999" alpha:1.0];
  42. sharedTheme.placeholderTextColor = [UIColor btuik_colorFromHex:@"8E8E8E" alpha:1.0];
  43. sharedTheme.lineColor = [UIColor btuik_colorFromHex:@"666666" alpha:1.0];
  44. sharedTheme.blurStyle = UIBlurEffectStyleDark;
  45. sharedTheme.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
  46. [sharedTheme setDefaultColors];
  47. }
  48. - (void)setDynamicColors {
  49. if (@available(iOS 13, *)) {
  50. sharedTheme.barBackgroundColor = UIColor.systemBackgroundColor;
  51. sharedTheme.formBackgroundColor = UIColor.systemGroupedBackgroundColor;
  52. sharedTheme.formFieldBackgroundColor = UIColor.secondarySystemGroupedBackgroundColor;
  53. sharedTheme.primaryTextColor = UIColor.labelColor;
  54. sharedTheme.secondaryTextColor = UIColor.secondaryLabelColor;
  55. sharedTheme.placeholderTextColor = UIColor.placeholderTextColor;
  56. sharedTheme.lineColor = UIColor.separatorColor;
  57. sharedTheme.blurStyle = UIBlurEffectStyleSystemMaterial;
  58. sharedTheme.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
  59. sharedTheme.overlayColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
  60. sharedTheme.tintColor = UIColor.systemBlueColor;
  61. sharedTheme.disabledColor = UIColor.systemGrayColor;
  62. sharedTheme.errorForegroundColor = UIColor.systemRedColor;
  63. sharedTheme.switchThumbTintColor = UIColor.whiteColor;
  64. sharedTheme.switchOnTintColor = UIColor.systemGreenColor;
  65. }
  66. }
  67. - (void)setDefaultColors {
  68. sharedTheme.overlayColor = [UIColor btuik_colorFromHex:@"000000" alpha:0.5];
  69. sharedTheme.tintColor = [UIColor btuik_colorFromHex:@"2489F6" alpha:1.0];
  70. sharedTheme.disabledColor = UIColor.lightGrayColor;
  71. sharedTheme.errorForegroundColor = [UIColor btuik_colorFromHex:@"ff3b30" alpha:1.0];
  72. sharedTheme.switchThumbTintColor = UIColor.whiteColor;
  73. sharedTheme.switchOnTintColor = UIColor.greenColor;
  74. }
  75. - (void)setColorScheme:(enum BTUIKColorScheme)colorScheme {
  76. _colorScheme = colorScheme;
  77. switch (colorScheme) {
  78. case BTUIKColorSchemeLight:
  79. [sharedTheme setLightColors];
  80. sharedTheme.keyboardAppearance = UIKeyboardAppearanceLight;
  81. break;
  82. case BTUIKColorSchemeDark:
  83. [sharedTheme setDarkColors];
  84. sharedTheme.keyboardAppearance = UIKeyboardAppearanceDark;
  85. break;
  86. case BTUIKColorSchemeDynamic:
  87. [sharedTheme setDynamicColors];
  88. break;
  89. }
  90. }
  91. - (void)setFontFamily:(NSString *)fontFamily {
  92. _fontFamily = fontFamily;
  93. if (fontFamily != nil) {
  94. _font = [UIFont fontWithName:fontFamily size:10.0];
  95. } else {
  96. _font = [UIFont systemFontOfSize:10.0];
  97. }
  98. }
  99. - (void)setBoldFontFamily:(NSString *)boldFontFamily {
  100. _boldFontFamily = boldFontFamily;
  101. if (boldFontFamily != nil) {
  102. _boldFont = [UIFont fontWithName:boldFontFamily size:10.0];
  103. } else {
  104. _boldFont = [UIFont boldSystemFontOfSize:10.0];
  105. }
  106. }
  107. - (UIColor *)highlightedTintColor {
  108. return [sharedTheme.tintColor colorWithAlphaComponent:0.4];
  109. }
  110. + (void)styleLabelPrimary:(UILabel *)label {
  111. label.font = [[BTUIKAppearance sharedInstance].font fontWithSize:UIFont.labelFontSize];
  112. label.textColor = [BTUIKAppearance sharedInstance].primaryTextColor;
  113. }
  114. + (void)styleLabelBoldPrimary:(UILabel *)label {
  115. label.font = [[BTUIKAppearance sharedInstance].boldFont fontWithSize:UIFont.labelFontSize];
  116. label.textColor = [BTUIKAppearance sharedInstance].primaryTextColor;
  117. }
  118. + (void)styleSmallLabelBoldPrimary:(UILabel *)label {
  119. label.font = [[BTUIKAppearance sharedInstance].boldFont fontWithSize:UIFont.smallSystemFontSize];
  120. label.textColor = [BTUIKAppearance sharedInstance].primaryTextColor;
  121. }
  122. + (void)styleSmallLabelPrimary:(UILabel *)label {
  123. label.font = [[BTUIKAppearance sharedInstance].font fontWithSize:UIFont.smallSystemFontSize];
  124. label.textColor = [BTUIKAppearance sharedInstance].primaryTextColor;
  125. }
  126. + (void)styleLabelSecondary:(UILabel *)label {
  127. label.font = [[BTUIKAppearance sharedInstance].font fontWithSize:UIFont.smallSystemFontSize];
  128. label.textColor = [BTUIKAppearance sharedInstance].secondaryTextColor;
  129. }
  130. + (void)styleLargeLabelSecondary:(UILabel *)label {
  131. label.font = [[BTUIKAppearance sharedInstance].font fontWithSize:UIFont.labelFontSize];
  132. label.textColor = [BTUIKAppearance sharedInstance].secondaryTextColor;
  133. }
  134. + (void)styleSystemLabelSecondary:(UILabel *)label {
  135. label.font = [[BTUIKAppearance sharedInstance].font fontWithSize:UIFont.systemFontSize];
  136. label.textColor = [BTUIKAppearance sharedInstance].secondaryTextColor;
  137. }
  138. + (UILabel *)styledNavigationTitleLabel {
  139. UILabel *tlabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 40)];
  140. tlabel.textAlignment = NSTextAlignmentCenter;
  141. tlabel.textColor = [BTUIKAppearance sharedInstance].navigationBarTitleTextColor;
  142. tlabel.font = [[BTUIKAppearance sharedInstance].boldFont fontWithSize:UIFont.labelFontSize];
  143. tlabel.backgroundColor = UIColor.clearColor;
  144. tlabel.adjustsFontSizeToFitWidth = YES;
  145. tlabel.numberOfLines = 2;
  146. return tlabel;
  147. }
  148. + (float)horizontalFormContentPadding {
  149. return 15.0f;
  150. }
  151. + (float)formCellHeight {
  152. return 44.0f;
  153. }
  154. + (float)verticalFormSpace {
  155. return 35.0f;
  156. }
  157. + (float)verticalFormSpaceTight {
  158. return 10.0f;
  159. }
  160. + (float)verticalSectionSpace {
  161. return 30.0f;
  162. }
  163. + (float)smallIconWidth {
  164. return 45.0;
  165. }
  166. + (float)smallIconHeight {
  167. return 29.0;
  168. }
  169. + (float)largeIconWidth {
  170. return 100.0;
  171. }
  172. + (float)largeIconHeight {
  173. return 100.0;
  174. }
  175. + (NSDictionary*)metrics {
  176. static NSDictionary *sharedMetrics;
  177. static dispatch_once_t onceToken;
  178. dispatch_once(&onceToken, ^{
  179. sharedMetrics = @{@"HORIZONTAL_FORM_PADDING":@([BTUIKAppearance horizontalFormContentPadding]),
  180. @"FORM_CELL_HEIGHT":@([BTUIKAppearance formCellHeight]),
  181. @"VERTICAL_FORM_SPACE":@([BTUIKAppearance verticalFormSpace]),
  182. @"VERTICAL_FORM_SPACE_TIGHT":@([BTUIKAppearance verticalFormSpaceTight]),
  183. @"VERTICAL_SECTION_SPACE":@([BTUIKAppearance verticalSectionSpace]),
  184. @"ICON_WIDTH":@([BTUIKAppearance smallIconWidth]),
  185. @"ICON_HEIGHT":@([BTUIKAppearance smallIconHeight]),
  186. @"LARGE_ICON_WIDTH":@([BTUIKAppearance largeIconWidth]),
  187. @"LARGE_ICON_HEIGHT":@([BTUIKAppearance largeIconHeight])};
  188. });
  189. return sharedMetrics;
  190. }
  191. - (UIColor *)navigationBarTitleTextColor {
  192. return _navigationBarTitleTextColor != nil ? _navigationBarTitleTextColor : _primaryTextColor;
  193. }
  194. @end