ios7 - Custom UItabbar has a gap in the bottom

简介:

Im trying to create a custom UITabbar using images for the selected and unselected states.

this is my code:

if([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]){

    tab_01_on_image =[[UIImage imageNamed:@"Tabbar_on_01"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tab_01_off_image =[[UIImage imageNamed:@"Tabbar_off_01"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];}else{
    tab_01_on_image =[UIImage imageNamed:@"Tabbar_on_01"];
    tab_01_off_image =[UIImage imageNamed:N@"Tabbar_off_01"];}[[[self.tabBarController.tabBar items] objectAtIndex:index] setFinishedSelectedImage:tab_01_on_image withFinishedUnselectedImage:tab_01_off_image];

This image shows the problem, the red color is the gap:

enter image description here

EDIT to add the code to create the UITabbar

self.tabBarController =[[BaseTabbarController alloc] init];self.tabBarController.delegate=self;self.tabBarController.viewControllers =@[navControll1, navControll2, navControll3, navControll4, navControll5];self.window.rootViewController =self.tabBarController;

I appreciate any help you guys can offer

share | edit | flag
 
   
   
how high Tabbar_on_01? –   Ilario  Nov 15 at 12:37
   
   
the @2x image is 128x100px I also tried with 128x98px and got the same problem. –   FelipeOliveira  Nov 15 at 12:47 
   
   
Is your view designed with Interface Builder, or do you create it programmatically? –   zbMax  Nov 15 at 13:27
   
   
programmatically zbMax –   FelipeOliveira  Nov 15 at 13:39
   
   
Can you edit your question and add the code creating the tabbar please? By the way, follow this guidelines page for your icon dimension : developer.apple.com/library/ios/documentation/userexperience/… –   zbMax Nov 15 at 13:53
   
add / show 1 more comment
  start a bounty

1 Answer

I finally found the solution. Changing the imageInsets of each tabbarItem did the trick.

tabBarItem1.imageInsets =UIEdgeInsetsMake(6,0,-6,0);
tabBarItem2.imageInsets =UIEdgeInsetsMake(6,0,-6,0);
tabBarItem3.imageInsets =UIEdgeInsetsMake(6,0,-6,0);
tabBarItem4.imageInsets =UIEdgeInsetsMake(6,0,-6,0);
tabBarItem5.imageInsets =UIEdgeInsetsMake(6,0,-6,0);
share | edit | flag
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!





















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/p/3449372.html ,如需转载请自行联系原作者
相关文章
|
iOS开发
iOS中 UITabBarController中自定义UITabBar
1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigationController* ayNav = [[UINavigationCont...
783 0
|
图形学 API C语言
【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记12 Custom Views视图绘制1
这一话来讲解一下视图的绘制,首先介绍一下相关的结构体 视图中的所有coordinate(坐标)的类型都是CGFloat,CGFloat在Swift中是结构体,在处理视图绘制和手势识别的时候我们使用的都是CGFloat,不要用我们常规的Double和Float。
929 0
ios项目常用模板框架之UITabBar+Nav
在实际的项目开发中总是有几个比较常见的模板,小编这几天给大伙出几期常用模板的博客,希望大家多提宝贵的意见! 这几个月最常用的莫过于Nav+UITabBar模板了;在实际的项目中,我比较侧重于纯代码,比较不喜欢拖控件,至于利弊在这里不多说了,言归正传。
822 0
|
Swift iOS开发
swift语言IOS8开发战记4.custom tableViewCell
第三话中讲解了如何利用系统内置的cell格式,这一话来谈谈如何自定义cell格式.在stroyboard中通过拖拽为cell添加内容,并且通过属性检测器修改样式,下面是我简单设置的一个自定义cell。
945 0
|
4天前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
114 3
|
4天前
|
存储 iOS开发
iOS 开发,如何进行应用的本地化(Localization)?
iOS 开发,如何进行应用的本地化(Localization)?
128 2