0

>イラストは多くの言葉よりも優れています

ご覧のとおり、タイトルの左側に 217 ピクセル、反対側に 242 ピクセルがあります。

この問題は iOS 6 でのみ発生します。タイトルは古いバージョンに完全に集中しています。ナビゲーションバーを作成する方法は次のとおりです。

- (void)initNavigationBar
{
    //Background
    UIImage *navBarBackground = [UIImage imageNamed:@"navigationBar"];
    [[UINavigationBar appearance] setBackgroundImage:navBarBackground forBarMetrics:UIBarMetricsDefault];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
        [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

    //Title
    NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
    [titleBarAttributes setValue:[UIFont fontWithName:@"NeutrafaceText-Bold" size:20] forKey:UITextAttributeFont];
    [titleBarAttributes setValue:[UIColor colorWithRed:17.0/255.0 green:83.0/255.0 blue:144.0/255.0 alpha:1] forKey:UITextAttributeTextShadowColor];
    [titleBarAttributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0, 1.5)] forKey:UITextAttributeTextShadowOffset];

    [[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];    

    //Buttons
    //Back
    NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
    [attributes setValue:[UIFont fontWithName:@"NeutrafaceText-Demi" size:14] forKey:UITextAttributeFont];
    [attributes setValue:[UIColor colorWithRed:161.0/255.0 green:203.0/255.0 blue:238.0/255.0 alpha:1] forKey:UITextAttributeTextColor];
    [attributes setValue:[UIColor colorWithRed:10.0/255.0 green:54.0/255.0 blue:92.0/255.0 alpha:1] forKey:UITextAttributeTextShadowColor];
    [attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0, 1.5)] forKey:UITextAttributeTextShadowOffset];

    [[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
    UIImage *backButtonBackground = [[UIImage imageNamed:@"backButtonBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 12, 1, 12)];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonBackground forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2.5f, 0.0f) forBarMetrics:UIBarMetricsDefault];

    //Right
    UIImage *rightButtonBackground = [[UIImage imageNamed:@"rightButtonBackground"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 10, 1, 10)];
    [[UIBarButtonItem appearance] setBackgroundImage:rightButtonBackground forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

誰かが何か考えを持っていれば、私が間違っていることを本当に知りません...

他の質問ですが、私のタイトルの位置 (今回は y 軸上) を設定する方法を知っていますか?

編集: 一時的な解決策はここにあります。

4

2 に答える 2

0

resizableImageWithCapInsets値を変更して、タイトルが左右にどのように移動するかを確認することをお勧めします。私が考えているのは、テキストは「テキスト領域内」の中央に配置されていますが、サイズ変更可能な画像のためにテキスト領域がオフセットされているということです。

于 2013-02-25T19:38:16.240 に答える
0

私は同じ問題を抱えていましたが、私の解決策は影のオフセットをなくすことでした。つまり、次の行です。

[titleBarAttributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0, 1.5)] forKey:UITextAttributeTextShadowOffset];

実際には、タイトル属性を個別に設定しませんでしたが、このコード ブロックを使用します (コメント行を抑制します)。

[[UINavigationBar appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor colorWithRed:248.0/255.0 green:235.0/255.0 blue:227.0/255.0 alpha:1.0], UITextAttributeTextColor,
      [UIColor colorWithRed:67.0/255.0 green:32.0/255 blue:12.0/255.0 alpha:0.8], UITextAttributeTextShadowColor,
      //CGSizeMake(0, 1), UITextAttributeTextShadowOffset,
      [UIFont fontWithName:@"DIN-Bold" size:16.0], UITextAttributeFont,nil]];

理由はわかりませんが、これで問題は解決し、タイトルは iOS6 で完璧に見えます。タイトルには、デフォルトのシャドウ オフセットもありました。これが誰かに役立つことを本当に願っています。この単純な問題は、私を何時間も夢中にさせます。

于 2013-12-03T00:08:36.870 に答える