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

我有同样的问题,我的解决方案是消除阴影偏移。我的意思是,这条线:

[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 回答
0

我建议改变你的resizableImageWithCapInsets价值观,看看你的标题是如何向左或向右移动的。我认为正在发生的事情是您的文本居中“在文本区域内”,但是由于您的可调整大小的图像,文本区域正在偏移。

于 2013-02-25T19:38:16.240 回答