これにより、アプリがクラッシュします。
[[UINavigationBar appearance] setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
外観を使用してこれを行う方法はありますか?
これにより、アプリがクラッシュします。
[[UINavigationBar appearance] setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
外観を使用してこれを行う方法はありますか?
これはうまくいきました:
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];
Swift でこれを行う方法の例を次に示します。
UINavigationBar.appearance().titleTextAttributes =
[NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject,
NSForegroundColorAttributeName:UIColor.whiteColor()]
UINavigationBar にタイトルまたは状態がない前に、アプリがクラッシュします...これらは UIButton メソッドです
あなたが必要
[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];
@RyJの回答は素晴らしく、私にとってはうまくいきました。これについては、Ray Wenderlich のサイトに次のようなタイトルの優れたチュートリアルがあることを知っておいてください。
セクション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]];
もう 1 つのマイナーな点は、タイトル バーに既定の影があるように見えることです。そのため、属性を削除するだけでは影を取り除くことができません。代わりに、シャドウ オフセットを設定する必要があります。
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(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];
実際に実行される最新の構文とコードを使用して、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 }];
注:NSShadow
のshadowBlurRadius
プロパティは考慮されません。
注: 影は iOS 6 用です。使用しないでください。