react-native-navigation的迁移库

RNNLargeTitleOptions.m 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #import "RNNLargeTitleOptions.h"
  2. #import "RNNTitleViewHelper.h"
  3. @implementation RNNLargeTitleOptions
  4. - (void)applyOn:(UIViewController *)viewController {
  5. if (@available(iOS 11.0, *)) {
  6. viewController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
  7. if ([self.visible boolValue]){
  8. viewController.navigationController.navigationBar.prefersLargeTitles = YES;
  9. viewController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways;
  10. } else {
  11. viewController.navigationController.navigationBar.prefersLargeTitles = NO;
  12. }
  13. NSDictionary* fontAttributes = [self fontAttributes];
  14. viewController.navigationController.navigationBar.largeTitleTextAttributes = fontAttributes;
  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:20];
  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