UITabbar的几种使用

1.可以用kvc和kvo设置自定义的tabbar

2.需要隐藏本身tabbar的分割线

3.主要点:

//设置tab bar 中间item的图为大图标    
UIViewController* vc = [UIViewController new];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:vc];
[vcs addObject:nav];
nav.tabBarItem.image = [[UIImage imageNamed:@"jdstreetNew_up"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"jdstreetNew_up"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//隐藏tab bar顶部的分隔线。否则顶部的分隔线将压在中间大图标的上面。
{
    //设置tab bar的背景图后setShadowImage才有效。
    {
        CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, 44);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        //CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
        CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:247/255.0
                                                                 green:247/255.0
                                                                  blue:247/255.0
                                                                 alpha:1] CGColor]);
        CGContextFillRect(context, rect);
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        [self.tabBar setBackgroundImage:img];
    }

    //将tab bar顶部的分隔线设置为不可见。
[self.tabBar setShadowImage:[UIImage new]];
}


中间大图标,无封装。下载地址:http://download.csdn.net/detail/sunnysu99/9883288


中间大图标present,有封装。下载地址:http://download.csdn.net/detail/sunnysu99/9883293


仿咸鱼的tabbar,通过hitTest方法拦截。下载地址:http://download.csdn.net/detail/sunnysu99/9883292


你可能感兴趣的:(Objective-C)