2014-05-15 22 views
5

Tôi muốn thay đổi phông chữ và color..so tiêu đề chuyển hướng của, cho rằng tôi đã làm điều này dưới đây code..but nó không làm việc ...UINavigationBar tiêu đề thay đổi văn bản và font size

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { 


    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
               [UIColor whiteColor], 
               NSForegroundColorAttributeName, 
               [UIFont fontWithName:@"MyFavoriteFont" size:20.0], 
               NSFontAttributeName, 
               nil]; 
    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes]; 
    NSLog(@"setTitleTextAttributes"); 
} 

tại sao mã này không hoạt động?

Trả lời

9

Áp dụng thuộc tính cho cá thể Navigationcontroller.

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { 
    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
               [UIColor whiteColor], 
               NSForegroundColorAttributeName, 
               [UIFont fontWithName:@"MyFavoriteFont" size:20.0], 
               NSFontAttributeName, 
               nil]; 
    [self.transitionNavController.navigationBar setTitleTextAttributes:navbarTitleTextAttributes]; 
} 

Hope this helps ...

0
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) 
     { 
      [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault]; 
      [[UINavigationBar appearance] setTitleTextAttributes: 
      @{ 
       UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeTextShadowColor: [UIColor clearColor],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],UITextAttributeFont: [UIFont fontWithName:@"ArialMT" size:18.0f] 
       }]; 
      CGFloat verticalOffset = -4; 
      [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault]; 
     } 
     else 
     { 
      [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]]; 

      // Uncomment to change the color of back button 
      [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 

      // Uncomment to assign a custom backgroung image 
      [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault]; 

      // Uncomment to change the back indicator image 

      [[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@""]]; 
      [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@""]]; 

      // Uncomment to change the font style of the title 

      NSShadow *shadow = [[NSShadow alloc] init]; 
      shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8]; 
      shadow.shadowOffset = CGSizeMake(0, 1); 

      [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:@"ArialMT" size:18.0], NSFontAttributeName, nil]]; 

      CGFloat verticalOffset = 0; 
      [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault]; 
     } 
Các vấn đề liên quan