react-native-navigation的迁移库

RNNFontAttributesCreator.m 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #import "RNNFontAttributesCreator.h"
  2. #import "RCTConvert+UIFontWeight.h"
  3. @implementation RNNFontAttributesCreator
  4. + (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
  5. NSMutableDictionary* titleTextAttributes = [NSMutableDictionary new];
  6. return [self createWithDictionary:titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:defaultFontSize fontWeight:fontWeight color:color defaultColor:defaultColor];
  7. }
  8. + (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
  9. NSMutableDictionary* titleTextAttributes = [NSMutableDictionary new];
  10. return [self createWithDictionary:titleTextAttributes fontFamily:fontFamily fontSize:fontSize fontWeight:fontWeight color:color];
  11. }
  12. + (NSDictionary *)createWithDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
  13. return [self createWithDictionary:attributesDictionary fontFamily:fontFamily fontSize:fontSize ?: defaultFontSize fontWeight:fontWeight color:color ?: defaultColor];
  14. }
  15. + (NSDictionary *)createWithDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
  16. NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];
  17. if (fontFamily || fontSize || color || fontWeight) {
  18. CGFloat resolvedFontSize = fontSize ? fontSize.floatValue : 17;
  19. if (color) {
  20. titleTextAttributes[NSForegroundColorAttributeName] = color;
  21. }
  22. if (fontWeight) {
  23. titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
  24. } else if (fontFamily){
  25. titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:resolvedFontSize];
  26. } else {
  27. titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize];
  28. }
  29. }
  30. return titleTextAttributes;
  31. }
  32. @end