iOS更改tabbar圖片渲染 —不讓tabbat有藍色的渲染 並修改文字,

來源:互聯網
上載者:User

iOS更改tabbar圖片渲染 —不讓tabbat有藍色的渲染 並修改文字,
方式一 代碼實現 這種要寫很多代碼 ,每個控制器都要寫  UIImage *image=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"];//    不讓tabbar底部有渲染的關鍵代碼     image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    vc01.tabBarItem.selectedImage=image; 更改tabbar下方的文字樣式,大小, 顏色  NSMutableDictionary *atts=[NSMutableDictionary dictionary];// 更改文字大小    atts[NSFontAttributeName]=[UIFont systemFontOfSize:12];// 更改文字顏色    atts[NSForegroundColorAttributeName]=[UIColor darkGrayColor];     NSMutableDictionary *selectedAtts=[NSMutableDictionary dictionary];
    selectedAtts[NSFontAttributeName]=[UIFont systemFontOfSize:12];
    selectedAtts[NSForegroundColorAttributeName]=[UIColor greenColor];    [vc01.tabBarItem setTitleTextAttributes:selectedAtts forState:UIControlStateSelected];  方式二   在 Assets.xcassets檔案夾中更改 改變之後不用代碼  並且在所有的控制器裡面都會被作用到具體操作 appearance屬性//    通過appearance統一設定所有的UITabBarItem的文字屬性//    後面帶有UI_APPEARANCE_SELECTOR的方法,都可以通過appearance同意設定例如UITabBarItem的文字屬性案例; 
    NSMutableDictionary *atts=[NSMutableDictionary dictionary];
    atts[NSFontAttributeName]=[UIFont systemFontOfSize:12];
    atts[NSForegroundColorAttributeName]=[UIColor grayColor];
   
    NSMutableDictionary *selectedAtts=[NSMutableDictionary dictionary];
    selectedAtts[NSFontAttributeName]=atts[NSFontAttributeName];    selectedAtts[NSForegroundColorAttributeName]=[UIColor darkGrayColor];// 在這裡 只要更改,所有的文字都改     UITabBarItem *item=[UITabBarItem appearance];
    [item setTitleTextAttributes:atts forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtts forState:UIControlStateSelected];
   
    //    添加子控制器
    UIViewController *vc01=[[UIViewController alloc]init];
    vc01.view.backgroundColor=[UIColor redColor];
    vc01.tabBarItem.title=@"精華";
    vc01.tabBarItem.image=[UIImage imageNamed:@"tabBar_essence_icon"];
    UIImage *image=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
//    不讓tabbar底部有渲染的關鍵代碼     image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    vc01.tabBarItem.selectedImage=image;// 把控制器 添加到 UITabBarController裡面去    [self addChildViewController:vc01];   
    UIViewController *vc02=[[UIViewController alloc]init];
    vc02.tabBarItem.title=@"新帖";
    vc02.tabBarItem.image=[UIImage imageNamed:@"tabBar_new_click_icon"];
    vc02.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_new_click_icon"];
    vc02.view.backgroundColor=[UIColor cyanColor];
    [self addChildViewController:vc02];
   
    UIViewController *vc03=[[UIViewController alloc]init];
    vc03.view.backgroundColor=[UIColor blueColor];
    vc03.tabBarItem.title=@"關注";
    vc03.tabBarItem.image=[UIImage imageNamed:@"tabBar_friendTrends_icon"];
    vc03.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    [self addChildViewController:vc03];
   
    UIViewController *vc04=[[UIViewController alloc]init];
    vc04.tabBarItem.title=@"我";
    vc04.tabBarItem.image=[UIImage imageNamed:@"tabBar_me_icon"];
    vc04.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_me_click_icon"];
    vc04.view.backgroundColor=[UIColor yellowColor];    [self addChildViewController:vc04];

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.