2012-06-12 11 views

答えて

66

を必要と働いた:

NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil]; 
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions]; 
+5

あなた自身の答えを受け入れるべきです。 –

+0

非常に有用です..ありがとう –

+2

うまく動作します。アクティブなUINavigationBarにテーマを設定する必要がある場合は、次の行を追加してください。 '[yourViewController.navigationController.navigationBar setTitleTextAttributes:textTitleOptions]' –

3

...これらはUIButton方法

ているあなたは、この

[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]]; 
+0

いいえ、動作しません。私はそれがバー自体を着色すると思う。 setBackgroundImage:メソッドを使用してナビゲーションバーの背景を変更しています。そのため、テキストの色を白から濃いグレーに変更して見やすくする必要があります。 – RyJ

+0

申し訳ありませんが、あなたがnavBarのテキストの色を設定しようとしていたことが分かりませんでした。色を変えようとしていると思っていました。 –

2

@ RyJの答えは素晴らしく、私のために働いた。私はと題しレイWenderlichのサイトでは、この上の良いチュートリアルでは、(しゃれを言い訳)があることでチップしようと思いました:

User Interface Customization in iOS 6

はセクションカスタマイズUINavigationBarを参照してください

ここでのコードスニペットですナビゲーションバーのタイトルは、世界的に変更するには:

// Customize the title text for *all* UINavigationBars 
[[UINavigationBar appearance] setTitleTextAttributes: 
[NSDictionary dictionaryWithObjectsAndKeys: 
    [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], 
    UITextAttributeTextColor, 
    [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], 
    UITextAttributeTextShadowColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
    UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:@"Arial-Bold" size:0.0], 
    UITextAttributeFont, 
    nil]]; 

もう一つのマイナーなポイントは、タイトルバー上のデフォルトの影があると思われることであるので、それを取り除くために、単に属性を削除することはできません。代わりに、あなたは影を設定する必要がオフセット:

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0, 0)] 
0

私は、タイトルバーの色を変更するには、次のコードを使用していました。

NSShadow *shadow = [[NSShadow alloc] init]; 
shadow.shadowColor = [UIColor blackColor]; 
shadow.shadowOffset = CGSizeMake(1, 0); 

NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], 
              NSShadowAttributeName:shadow}; 

[[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes]; 
4

はここスウィフトでこれを行う方法の例です:

実際に実行され、現代の構文とコードを使用して
UINavigationBar.appearance().titleTextAttributes = 
    [NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject, 
    NSForegroundColorAttributeName:UIColor.whiteColor()] 
0

、これはあなたのUINavigationBarタイトルテキストのスタイルをグローバルにする方法である:

NSShadow *navigationBarTitleShadow = [[NSShadow alloc] init]; 
navigationBarTitleShadow.shadowColor = [UIColor colorWithWhite:0.5 
                 alpha:0.5]; 
navigationBarTitleShadow.shadowOffset = CGSizeMake(2.0, 2.0); 
[[UINavigationBar appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor], 
                 NSFontAttributeName : [UIFont fontWithName:@"Arial-BoldMT" 
                           size:30.0], 
                 NSShadowAttributeName : navigationBarTitleShadow }]; 

注:NSShadowshadowBlurRadiusプロパティは尊重されません。

注:影はiOS 6です。使用しないでください。

関連する問題