react-native-navigation的迁移库

RNNTitleOptions.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. viewController.navigationController.navigationBar.titleTextAttributes = fontAttributes;
  10. if (self.subtitle.text) {
  11. RNNTitleViewHelper* titleViewHelper = [[RNNTitleViewHelper alloc] init:viewController title:self.text subtitle:self.subtitle.text titleImageData:nil isSetSubtitle:NO];
  12. [titleViewHelper setup:self];
  13. }
  14. }
  15. - (NSDictionary *)fontAttributes {
  16. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
  17. if (self.fontFamily || self.fontSize || self.color) {
  18. if (self.color) {
  19. navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.color];
  20. }
  21. if (self.fontFamily){
  22. if (self.fontSize) {
  23. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:[self.fontSize floatValue]];
  24. } else {
  25. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:20];
  26. }
  27. } else if (self.fontSize) {
  28. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.fontSize floatValue]];
  29. }
  30. }
  31. return navigationBarTitleTextAttributes;
  32. }
  33. - (NSNumber *)fontSize {
  34. return _fontSize ? _fontSize : nil;
  35. }
  36. @end