react-native-navigation的迁移库

RNNTitleOptions.m 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. #import "RNNTitleOptions.h"
  2. @implementation RNNTitleOptions
  3. - (void)applyOn:(UIViewController *)viewController {
  4. if (self.text) {
  5. viewController.navigationItem.title = self.text;
  6. }
  7. if (self.fontFamily || self.fontSize || self.color) {
  8. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
  9. if (self.color) {
  10. navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:[self valueForKey:@"color"]];
  11. }
  12. if (self.fontFamily){
  13. if(self.fontSize) {
  14. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:[self.fontSize floatValue]];
  15. } else {
  16. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:20];
  17. }
  18. } else if (self.fontSize) {
  19. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.fontSize floatValue]];
  20. }
  21. viewController.navigationController.navigationBar.titleTextAttributes = navigationBarTitleTextAttributes;
  22. if (@available(iOS 11.0, *)){
  23. viewController.navigationController.navigationBar.largeTitleTextAttributes = navigationBarTitleTextAttributes;
  24. }
  25. }
  26. }
  27. @end