FontHelper.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // FontHelper.m
  3. // CommonLibrary
  4. //
  5. // Created by Alexi on 13-10-22.
  6. // Copyright (c) 2013年 ywchen. All rights reserved.
  7. //
  8. #import "FontHelper.h"
  9. #import "IOSDeviceConfig.h"
  10. @implementation FontHelper
  11. static FontHelper *_sharedInstance = nil;
  12. #if kIsCommonLibraryAppBuild
  13. #define MYRIADPRO_BOLD @"MyriadPro-Bold"
  14. #define MYRIADPRO_LIGHT @"MyriadPro-Light"
  15. #define MYRIADPRO_REGULAR @"MyriadPro-Regular"
  16. #define MYRIADPRO_SEMIBOLD @"MyriadPro-Semibold"
  17. #endif
  18. + (instancetype)shareHelper
  19. {
  20. static dispatch_once_t predicate;
  21. dispatch_once(&predicate, ^{
  22. _sharedInstance = [[FontHelper alloc] init];
  23. });
  24. return _sharedInstance;
  25. }
  26. - (void)configIPadFonts
  27. {
  28. [self configIPhoneFonts];
  29. }
  30. - (void)configIPhoneFonts
  31. {
  32. #if kIsCommonLibraryAppBuild
  33. const CGFloat size = 14;
  34. _titleFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:18];
  35. _subTitleFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  36. _textFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  37. _subTextFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  38. _tipFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  39. _superLargeFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  40. _largeFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  41. _mediumFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  42. _smallFont = [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  43. #else
  44. _titleFont = [UIFont systemFontOfSize:14];
  45. _subTitleFont = [UIFont systemFontOfSize:14];
  46. _textFont = [UIFont systemFontOfSize:14];
  47. _subTextFont = [UIFont systemFontOfSize:14];
  48. _tipFont = [UIFont systemFontOfSize:14];
  49. _superLargeFont = [UIFont systemFontOfSize:14];
  50. _largeFont = [UIFont systemFontOfSize:14];
  51. _mediumFont = [UIFont systemFontOfSize:14];
  52. _smallFont = [UIFont systemFontOfSize:14];
  53. #endif
  54. }
  55. - (id)init
  56. {
  57. if (self = [super init])
  58. {
  59. if ([IOSDeviceConfig sharedConfig].isIPad)
  60. {
  61. [self configIPadFonts];
  62. }
  63. else
  64. {
  65. [self configIPhoneFonts];
  66. }
  67. }
  68. return self;
  69. }
  70. + (UIFont *)fontWithName:(NSString *)name size:(CGFloat)size
  71. {
  72. return [UIFont fontWithName:name size:size];
  73. }
  74. + (UIFont *)fontWithSize:(CGFloat)size
  75. {
  76. #if kIsCommonLibraryAppBuild
  77. return [UIFont fontWithName:MYRIADPRO_REGULAR size:size];
  78. #else
  79. return [UIFont systemFontOfSize:size];
  80. #endif
  81. }
  82. + (UIFont *)boldFontWithSize:(CGFloat)size
  83. {
  84. #if kIsCommonLibraryAppBuild
  85. return [UIFont fontWithName:MYRIADPRO_BOLD size:size];
  86. #else
  87. return [UIFont boldSystemFontOfSize:size];
  88. #endif
  89. }
  90. @end