利用UI_APPEARANCE統一設置UITabBarItem樣式

-(void)setupTabBarItemAttributes{
    
    //attributes
    NSMutableDictionary *selectedAttrs= [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];//label字體大小
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];//選中字體顏色
    NSMutableDictionary *attrs= [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = selectedAttrs[NSFontAttributeName];
    attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];//未選中字體顏色
    
    UITabBarItem *item=[UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}
相關文章
相關標籤/搜索