Browse Source

[iOS] Large title text attributes (#2112)

* Add support for setting larget title text attributes

* Add documentation for setting large text attributes

See https://developer.apple.com/documentation/uikit/uinavigationbar/2919946-largetitletextattributes
Eli Perkins 6 years ago
parent
commit
f7ec9ee840
2 changed files with 16 additions and 1 deletions
  1. 4
    0
      docs/styling-the-navigator.md
  2. 12
    1
      ios/RCCViewController.m

+ 4
- 0
docs/styling-the-navigator.md View File

@@ -95,6 +95,10 @@ this.props.navigator.setStyle({
95 95
   navBarRightButtonColor: 'blue', // Change color of right nav bar button
96 96
   navBarRightButtonFontWeight: '600', // Change font weight of right nav bar button
97 97
 
98
+  navBarLargeTextColor: '#000000', // change the text color of large titles
99
+  navBarLargeTextFontSize: 34, // change the font size of large titles
100
+  navBarLargeTextFontFamily: 'font-name', // Changes the large title font
101
+
98 102
   topBarShadowColor: 'blue' // Sets shadow of the navbar, Works only when topBarElevationShadowEnabled: true
99 103
   topBarShadowOpacity: 0.5, // Sets shadow opacity on the navbar, Works only when topBarElevationShadowEnabled: true
100 104
   topBarShadowOffset: 12, // Sets shadow offset on the navbar, Works only when topBarElevationShadowEnabled: true

+ 12
- 1
ios/RCCViewController.m View File

@@ -362,8 +362,19 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
362 362
     viewController.navigationController.navigationBar.barTintColor = nil;
363 363
   }
364 364
   
365
-  NSMutableDictionary *titleTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"navBarText" baseFont:[UIFont boldSystemFontOfSize:17]];
365
+  NSMutableDictionary *titleTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle
366
+                                                                           withPrefix:@"navBarText"
367
+                                                                             baseFont:[UIFont boldSystemFontOfSize:17]];
366 368
   [self.navigationController.navigationBar setTitleTextAttributes:titleTextAttributes];
369
+
370
+  if ([self.navigationController.navigationBar respondsToSelector:@selector(setLargeTitleTextAttributes:)]) {
371
+    // As defined in Apple's UI Design Resources: https://developer.apple.com/design/resources/
372
+    UIFont *largeBaseFont = [UIFont boldSystemFontOfSize:34];
373
+    NSMutableDictionary *largeTitleTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle
374
+                                                                                  withPrefix:@"navBarLargeText"
375
+                                                                                    baseFont:largeBaseFont];
376
+    [self.navigationController.navigationBar setLargeTitleTextAttributes:largeTitleTextAttributes];
377
+  }
367 378
   
368 379
   NSMutableDictionary *navButtonTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"navBarButton"];
369 380
   NSMutableDictionary *leftNavButtonTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"navBarLeftButton"];