react-native-navigation的迁移库

RNNTitleOptions.m 1.6KB

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