react-native-navigation的迁移库

RNNTitleOptions.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #import "RNNTitleOptions.h"
  2. #import "RNNTitleViewHelper.h"
  3. @implementation RNNTitleOptions
  4. - (void)applyOn:(UIViewController *)viewController {
  5. if (self.text) {
  6. viewController.navigationItem.title = self.text;
  7. }
  8. NSDictionary* fontAttributes = [self fontAttributes];
  9. if (fontAttributes.allKeys.count > 0) {
  10. viewController.navigationController.navigationBar.titleTextAttributes = fontAttributes;
  11. }
  12. if (self.subtitle.text) {
  13. RNNTitleViewHelper* titleViewHelper = [[RNNTitleViewHelper alloc] init:viewController title:self.text subtitle:self.subtitle.text titleImageData:nil isSetSubtitle:NO];
  14. [titleViewHelper setup:self];
  15. }
  16. }
  17. - (NSDictionary *)fontAttributes {
  18. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
  19. if (self.fontFamily || self.fontSize || self.color) {
  20. if (self.color) {
  21. navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.color];
  22. }
  23. if (self.fontFamily){
  24. if (self.fontSize) {
  25. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:[self.fontSize floatValue]];
  26. } else {
  27. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:17];
  28. }
  29. } else if (self.fontSize) {
  30. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.fontSize floatValue]];
  31. }
  32. }
  33. return navigationBarTitleTextAttributes;
  34. }
  35. - (NSNumber *)fontSize {
  36. return _fontSize ? _fontSize : nil;
  37. }
  38. @end