Tabbarcontroller of the use system for swift development

Source: Internet
Author: User

Use the system's Tabbar to solve the picture problem.
Using SB to use the system's Tabbar, and found that the picture is always blue, not the original picture, after the Internet to check data, ask colleagues, with the following code, make a mark.
In Appdelegate
Func application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]?)- > Bool {
Inittabbarselecteditem ()
return True
}
Func Inittabbarselecteditem ()
{
var Rootcontroller = Self.window?. Rootviewcontroller as Uitabbarcontroller
var TabBar = Rootcontroller.tabbar

    var Homeitem = Tabbar.items? [0] as uitabbaritem var selectedimg = UIImage (named: "Home")?  Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal) If Homeitem.tag = = {Homeitem.selectedimage = Selectedimg homeitem.settitletextattributes ([NSForegroundColorAttributeName:UIColor.redColor (), NSFontAttributeName:UIFont.systemFontOfSize], ForState:UIControlState.Normal)} var orderitem = Tabbar.items? [1] as uitabbaritem var orderitemimg = UIImage (named: "Order")?.  Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal) If Orderitem.tag = = 101 {orderitem.selectedimage = Orderitemimg Orderitem.settitletextattributes ([NSForegroundColorAttributeName:UIColor.redColor ()], Forstate:uic ontrolstate.selected)} var releaseitem = Tabbar.items? [2] as uitabbaritem var releaseitemimg = UIImage (named: "Publish")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal) If Releaseitem.tag = = 102 {ReleaseItem.selectedI MagE = releaseitemimg Releaseitem.image = releaseitemimg releaseitem.settitletextattributes ([NSForegroundColorAttri ButeName:UIColor.redColor ()], forState:UIControlState.Selected)} var myitem = Tabbar.items? [3] as uitabbaritem var myitemimg = UIImage (named: "My")?. Imagewithrenderingmode (uiimagerenderingmode.alwaysoriginal) if Myitem.tag = = 103 {myitem.selectedimage = MyI Temimg myitem.settitletextattributes ([NSForegroundColorAttributeName:UIColor.redColor ()], forstate: uicontrolstate.selected)}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Tabbarcontroller of the use system for swift development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.