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