2016-06-01 25 views
1

私は多くの記事を読んでいますが、React Nativeにはナビゲーションバーのフォントを変更する機能がないので、何とか手動で行う必要があることを理解しています。私はAppDelegate.mにReactネイティブプロジェクトの次のコードを貼り付けようとしましたReact Native Changeナビゲーションバーフォント

[[UINavigationBar appearance] setTitleTextAttributes: 
      @{NSFontAttributeName : [UIFont fontWithName:@"Bodoni 72" size:22.0], 
      NSForegroundColorAttributeName : [UIColor blueColor]}]; 

これは動作しません。 RCTConvert.mを手動で編集しようと思っていました。しかし、それはうまくいっていませんでした。他に何を試してみるべきか誰にも分かりますか? ありがとう!

+0

これを解決できましたか?もしそうなら、どうですか? –

+0

ナビゲーションバーのレンダリングにはどのコンポーネントが使用されていますか?組み込みのNavigator/NavigatorIOSコンポーネントを使用していますか、または別のものを使用していますか? –

答えて

0

まず、NavigatorIOSを使用していると仮定しています。そうでない場合、以下は適用されません。

残念ながら、ネイティブコードに反してナビゲーションバーの外観が変化するため、あなたのアプローチは機能しません。私はあなたのコードを動作させる小さなパッチを作った。これをReact Nativeに提出するかもしれませんが、まだ決定していません:

--- a/node_modules/react-native/React/Views/RCTWrapperViewController.m 
+++ b/node_modules/react-native/React/Views/RCTWrapperViewController.m 
@@ -115,9 +115,11 @@ static UIView *RCTFindNavBarShadowViewInView(UIView *view) 
    bar.barTintColor = _navItem.barTintColor; 
    bar.tintColor = _navItem.tintColor; 
    bar.translucent = _navItem.translucent; 
- bar.titleTextAttributes = _navItem.titleTextColor ? @{ 
-  NSForegroundColorAttributeName: _navItem.titleTextColor 
- } : nil; 
+ if (_navItem.titleTextColor != nil) { 
+  NSMutableDictionary *newAttributes = bar.titleTextAttributes ? bar.titleTextAttributes.mutableCopy : [NSMutableDictionary new]; 
+  [newAttributes setObject:_navItem.titleTextColor forKey:NSForegroundColorAttributeName]; 
+  bar.titleTextAttributes = newAttributes; 
+ } 

    RCTFindNavBarShadowViewInView(bar).hidden = _navItem.shadowHidden;