How to change UITabBar Selection color

前端 未结 13 822
遇见更好的自我
遇见更好的自我 2020-12-13 09:02

I need to change the selection color of UITabBar from default blue to red. How do we do this.

13条回答
  •  臣服心动
    2020-12-13 09:35

    I've been searching for a way to set the selected text color of a UITabBarItem and have found a dead simple method, using the UIAppearance protocol.

    [UITabBarItem.appearance setTitleTextAttributes:@{
            UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
    
    [UITabBarItem.appearance setTitleTextAttributes:@{
            UITextAttributeTextColor : [UIColor purpleColor] }     forState:UIControlStateSelected];
    

    Please excuse the awful colors!

提交回复
热议问题