react-native-navigation的迁移库

RNNTitleOptions.m 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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) {
  14. RNNTitleViewHelper* titleViewHelper = [[RNNTitleViewHelper alloc] init:viewController title:self.text subtitle:self.subtitle 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. - (NSDictionary *)subtitleFontAttributes {
  37. NSMutableDictionary* navigationBarTitleTextAttributes = [NSMutableDictionary new];
  38. if (self.subtitleFontFamily || self.subtitleFontSize || self.subtitleColor) {
  39. if (self.subtitleColor) {
  40. navigationBarTitleTextAttributes[NSForegroundColorAttributeName] = [RCTConvert UIColor:self.subtitleColor];
  41. }
  42. if (self.subtitleFontFamily){
  43. if (self.subtitleFontSize) {
  44. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.subtitleFontFamily size:[self.subtitleFontSize floatValue]];
  45. } else {
  46. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.subtitleFontFamily size:14];
  47. }
  48. } else if (self.subtitleFontSize) {
  49. navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.subtitleFontSize floatValue]];
  50. }
  51. }
  52. return navigationBarTitleTextAttributes;
  53. }
  54. @end