How can I correctly change the way a UITabBar appears using the appearance proxy?

余生长醉 提交于 2019-12-25 01:15:43

问题


Since I am developing an iOS >= 5.0 application, I am trying to change the appearance of the main UI components through the appearance proxies.

When dealing with the UITabBar component, I correctly changed its tintColor to a light shade of gray trough the [[UITabBar appearance] setTintColor:] method. But doing this, the UITabBarItems included in the bar are quite impossible to see, since they retain the old gray/white color in their title label.

I tried to change their appearance through the [UITabBarItem appearance] proxy, but there is no way to make them visible.

Can anyone suggest me a way to solve this problem? Thank you!


回答1:


Hi this will work for what you want to do

// Customize the UIBarButtonItem
    UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"] 
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
    UIImage *button24 = [[UIImage imageNamed:@"button_textured_24"] 
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];

    [[UITabBarItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UITabBarItem appearance] setBackgroundImage:button24 forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];

    [[UITabBarItem appearance] setTitleTextAttributes:
      [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor colorWithRed:82.0/255.0 
                      green:82.0/255.0
                       blue:82.0/255.0
                      alpha:1.0],                     UITextAttributeTextColor,
      [UIColor colorWithRed:242.0 
                      green:237.0 
                       blue:237.0 
                      alpha:1.0],                     UITextAttributeTextShadowColor,
      [NSValue valueWithUIOffset:UIOffsetMake(0,1)],  UITextAttributeTextShadowOffset,
      [UIFont fontWithName:@"Helvetica" size:0.0],    UITextAttributeFont,nil]
                                         forState:UIControlStateNormal];

Happy Coding :)



来源:https://stackoverflow.com/questions/11329366/how-can-i-correctly-change-the-way-a-uitabbar-appears-using-the-appearance-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!