如何修改导航栏上的左右项

时间:2013-12-19 10:14:27

标签: ios uinavigationcontroller uinavigationitem

我想在全局导航栏上编辑左右项目字体。

取消是左项,并将其作为正确的项目。

它需要与中间的标题分开,我已经有如下代码(在app delegate中指定):

    NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
    [titleBarAttributes setValue:[UIFont themeFontNamed:@"viewTitleFont" ofSize:[Constants getTitleFontSize]] forKey:UITextAttributeFont];
    [titleBarAttributes setValue:[UIColor themeColorNamed:@"viewTitleColour"] forKey:UITextAttributeTextColor];
    [[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];

感谢。

1 个答案:

答案 0 :(得分:1)

在didFinishLaunchingWithOptions上的AppDelegate上处理这段代码:

// Change the appearance of back button
    UIImage *backButtonImage = [[UIImage imageNamed:@"button_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    // Change the appearance of other navigation button
    UIImage *barButtonImage = [[UIImage imageNamed:@"button_normal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
    [[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

FOR TEXT:

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.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:@"HelveticaNeue-CondensedBlack" size:21.0], UITextAttributeFont, nil]];

或者您可以使用

修改按钮的文字颜色
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];