2012-04-23 27 views
13

Tôi đã tùy chỉnh giao diện TabBar nhưiOS5 TabBar Fonts và màu

UIImage *tabBackground = [[UIImage imageNamed:@"tab-bar-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[[UITabBar appearance] setBackgroundImage:tabBackground]; 
[[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:@"activetab.png"]]; 

Làm thế nào để xác định phông chữ tùy chỉnh và màu sắc văn bản được chọn và không được chọn?

Cảm ơn,

+1

Có một cái nhìn tại http://stackoverflow.com/a/8412083/886407 – JiaYow

+0

Oh ác! Tôi đã cố gắng tìm kiếm, rõ ràng là không đủ cứng! Cảm ơn! –

Trả lời

18
[[UITabBarItem appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor blackColor], UITextAttributeTextColor, 
     [UIFont fontWithName:@"font" size:0.0], UITextAttributeFont, 
     nil] 
              forState:UIControlStateHighlighted]; 
+1

Lưu ý rằng tính năng này chỉ hoạt động trong iOS 5 trở lên –

+0

cách đặt cạnh cho tiêu đề? –

+0

@BurhanuddinSunelwala setTitlePositionĐiều chỉnh: (Điều chỉnh UIOffset) – JerryZhou

13
[[UITabBarItem appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor blackColor], UITextAttributeTextColor, 
     [UIFont fontWithName:@"ProximaNova-Semibold" size:0.0], UITextAttributeFont, 
     nil] 
              forState:UIControlStateHighlighted]; 


    [[UITabBarItem appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor grayColor], UITextAttributeTextColor, 
     [UIFont fontWithName:@"ProximaNova-Semibold" size:0.0], UITextAttributeFont, 
     nil] 
              forState:UIControlStateNormal]; 
1

Câu trả lời ở trên đang làm việc cho tôi.

Nhưng tôi nghĩ rằng hầu hết mọi người nên thay đổi forState:UIControlStateHighlighted-forstate:UIControlStateSelected

Các vấn đề liên quan