UIFont+YH.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // UIFont+YH.m
  3. // WildFireChat
  4. //
  5. // Created by Zack Zhang on 2020/3/15.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "UIFont+YH.h"
  9. @implementation UIFont (YH)
  10. + (UIFont *)pingFangSCWithWeight:(FontWeightStyle)fontWeight size:(CGFloat)fontSize {
  11. if (fontWeight < FontWeightStyleMedium || fontWeight > FontWeightStyleThin) {
  12. fontWeight = FontWeightStyleRegular;
  13. }
  14. NSString *fontName = @"PingFangSC-Regular";
  15. switch (fontWeight) {
  16. case FontWeightStyleMedium:
  17. fontName = @"PingFangSC-Medium";
  18. break;
  19. case FontWeightStyleSemibold:
  20. fontName = @"PingFangSC-Semibold";
  21. break;
  22. case FontWeightStyleLight:
  23. fontName = @"PingFangSC-Light";
  24. break;
  25. case FontWeightStyleUltralight:
  26. fontName = @"PingFangSC-Ultralight";
  27. break;
  28. case FontWeightStyleRegular:
  29. fontName = @"PingFangSC-Regular";
  30. break;
  31. case FontWeightStyleThin:
  32. fontName = @"PingFangSC-Thin";
  33. break;
  34. }
  35. UIFont *font = [UIFont fontWithName:fontName size:fontSize];
  36. return font ?: [UIFont systemFontOfSize:fontSize];
  37. }
  38. @end