Swift lets the tab bar button uitabbaritem the picture (no text)

Source: Internet
Author: User

For the tab bar (Uitabbar), when the Tabbaritem does not need title as long as the image, the image below will occupy a space.
We can set the offset by tabbaritem.imageinsets so that the image icon is centered.
(Note: Top and bottom are set to the opposite number, otherwise the image size will change.) )

Import Uikit

Class Maintabviewcontroller:uitabbarcontroller
{
Override Func Viewdidload ()
{
Super.viewdidload ()
Contains two views altogether
Let Qqview = Qqviewcontroller ()
Qqview.title = ""
Let Skypeview = Skypeviewcontroller ()
Skypeview.title = ""

Declare two view controllers separately
Let QQ = Uinavigationcontroller (Rootviewcontroller:qqview)
Qq.tabBarItem.image = UIImage (named: "QQ")
Qq.tabBarItem.imageInsets = Uiedgeinsetsmake (6, 0,-6, 0);

Let Skype = uinavigationcontroller (Rootviewcontroller:skypeview)
Skype.tabBarItem.image = UIImage (named: "Skype")
Skype.tabBarItem.imageInsets = Uiedgeinsetsmake (6, 0,-6, 0);

Self.viewcontrollers = [Qq,skype]
}
}

Uitabbaritem display Real custom pictures instead of color fills

Let Tabbaritem show the true appearance of the picture we set, need to look at the following setting method in AppDelegate.h, get all item then unified set to Custom picture is checked and unchecked, for iOS7


_tabbarcontroller = [[Uitabbarcontroller alloc]init];
[_tabbarcontroller Setviewcontrollers:@[recnav,feednav,postnav,loginnav]];
Get Tabbar and get the item you want.
Uitabbar *tabbar = _tabbarcontroller.tabbar;
Uitabbaritem *item0 = [Tabbar.items objectatindex:0];
Uitabbaritem *item1 = [Tabbar.items objectatindex:1];
Uitabbaritem *item2 = [Tabbar.items objectatindex:2];
Uitabbaritem *item3 = [Tabbar.items objectatindex:3];
Set the appropriate picture for item
Item0.selectedimage = [[UIImage imagenamed:@ "Recognize-1"] Imagewithrenderingmode: Uiimagerenderingmodealwaysoriginal];;
Item0.image = [[UIImage imagenamed:@ "recognize"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Item1.selectedimage = [[UIImage imagenamed:@ "life-1"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];;
Item1.image = [[UIImage imagenamed:@ "Life"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Item2.selectedimage = [[UIImage imagenamed:@ "edit-1"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];;
Item2.image = [[uiimage imagenamed:@ ' edit '] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Item3.selectedimage = [[UIImage imagenamed:@ "Setting-1"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal ];;
Item3.image = [[UIImage imagenamed:@ "setting"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

The above code to set up the 4 item picture set up, of course, can also be in the corresponding controller set up, but it is recommended that the unified set to modify the more convenient, if you need to click on the item has a very bright animation or other styles, it requires a high degree of customization to achieve

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.