2016-01-23 64 views
1

我目前正在開發React Native,我想更改NavigatorIOS標題的字體,我發現了一些有前途的鏈接:Github issueStack Overflow。然而遺憾的是沒有任何幫助。React Native iOS NavigatorIOS標題字體

目前,我有我的AppDelegate.m

[[UINavigationBar appearance] setTitleTextAttributes:@{ 
NSFontAttributeName : [UIFont fontWithName:@"Avenir-Light" size:22.0], 
NSForegroundColorAttributeName : [UIColor whiteColor] 
}]; 

這也沒有標題欄的字體從NavigatorIOS在開始時給出的字體更改此代碼。

+0

是你能解決這個? –

回答

0

你把這段代碼放在AppDelegate的哪裏?

它最好放在RCT_EXPORT_METHORD,應該從任何js類調用。

在AppDelagete.h

import BridgeModule.h 
Add RCTBridgeModule protocol 

在AppDelegate.m

Add: RCT_EXPORT_MODULE() below implementation 
@implementation AppDelegate 
RCT_EXPORT_MODULE() 

添加新功能

RCT_EXPORT_METHOD(updateNavigationBar){ 

    [[UINavigationBar appearance] setTitleTextAttributes:@{ 
    NSFontAttributeName : [UIFont fontWithName:@"Avenir-Light" size:22.0], 
    NSForegroundColorAttributeName : [UIColor whiteColor] 

}]; 

} 

變化JS

添加以下行

var AppDelegate = require('NativeModules').AppDelegate; 

someJSFunction{ 

    AppDelegate.updateNavigationBar(); 

} 

這將作品。 (代碼只是在這裏鍵入)

+0

無法得到這個工作。 –

0

我不相信由Rahul發佈的答案將工作,因爲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; 

有了這個補丁,你應該能夠做到以下幾點(SWIFT):

UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name:"Avenir-Light", size: 22.0) as Any] 
相關問題