Add custom image to UITabBarController

你离开我真会死。 提交于 2019-12-11 23:23:37

问题


I'm trying to add custom image to tabview controller, its working fine for me this is code I'm using

[[AppDelegate.Tabctrl.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"Home-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Home.png"]];
    [[AppDelegate.Tabctrl.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"MyTc-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"MyTc.png"]];
    [[AppDelegate.Tabctrl.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"Browse-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Browse.png"]];
    [[AppDelegate.Tabctrl.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"Instore-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Instore.png"]];
    [[AppDelegate.Tabctrl.tabBar.items objectAtIndex:4] setFinishedSelectedImage:[UIImage imageNamed:@"More-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"More.png"]];

the image not fit into the tabbar

out put

there is some design issue is there how can I fix this

Image goes over the tabbar, and some other background image is showing in selected tab (check 2nd tab).

How can I fix this


回答1:


to lower the images in the TabBar could change the imageInsets:

try something like that:

  UITabBarItem *tabBarItem1 = [AppDelegate.Tabctrl.tabBar.items objectAtIndex:0];

  [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"Home-Select.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Home.png"]];

  tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);


来源:https://stackoverflow.com/questions/20812972/add-custom-image-to-uitabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!