Change UINavigationBar font properties?

前端 未结 7 395
清酒与你
清酒与你 2020-12-24 05:42

I have an UINavigationBar added to my UIViewController view. I want to change the fonts properties. Note that I want to change a UINavigationBar not controller. In my app wh

相关标签:
7条回答
  • 2020-12-24 06:09

    (This is not possible using the new iOS 5.0 Appearance API).

    Edit:

    iOS >= 5.0 :

    Set the Title Text Attributes for the Navigationbar:

    // Customize the title text for *all* UINavigationBars
    NSDictionary *settings = @{
        UITextAttributeFont                 :  [UIFont fontWithName:@"YOURFONTNAME" size:20.0],
        UITextAttributeTextColor            :  [UIColor whiteColor],
        UITextAttributeTextShadowColor      :  [UIColor clearColor],
        UITextAttributeTextShadowOffset     :  [NSValue valueWithUIOffset:UIOffsetZero]};
    
    [[UINavigationBar appearance] setTitleTextAttributes:settings];
    

    iOS < 5.0

    UINavigationItem doesn't have a property called label or something, only a titleView. You are only able to set the font by setting a custom label as this title view You could use the following code: (as suggested here)

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    label.font = [UIFont fontWithName:@"YOURFONTNAME" size:20.0];
    label.shadowColor = [UIColor clearColor];
    label.textColor =[UIColor whiteColor];
    label.text = self.title;  
    self.navigationItem.titleView = label;      
    [label release];
    
    0 讨论(0)
提交回复
热议问题