自定义TabBar第一种方案

发布时间:2020-06-11 08:03:12 作者:yjf123546
来源:网络 阅读:966

自定义tabBar能够解决自定义图片无法显示(只显示一块颜色)这个弊端,自定义tabBar要继承UITabBarController

原图片:

(1), 自定义TabBar第一种方案 (2), 自定义TabBar第一种方案(3),  自定义TabBar第一种方案(4), 自定义TabBar第一种方案(5)自定义TabBar第一种方案

下面是自定义了一个TabBar ,每个按钮可以显示图片(自定义避免了图片无法显示只显示一块颜色)

效果图:


自定义TabBar第一种方案



代码实现:

- (void)loadViewController

{

    CoverCollectionViewController *coverVC = [[CoverCollectionViewController allocinit];

    coverVC.title = @"每日封面";

    CustomizedNavigationController *coverNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:coverVC];

    coverNaVC.navigationItem.title = @"iDailyWATCh";

    

    NewsTableViewController *newsVC = [[NewsTableViewController allocinit];

    newsVC.title = @"腕表杂志";

    CustomizedNavigationController *newsNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:newsVC];

    

    BrandsTableViewController *brandsVC = [[BrandsTableViewController allocinit];

    brandsVC.title = @"品牌维基";

    CustomizedNavigationController *brandsNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:brandsVC];

    

    VideosCollectionViewController *videosVC = [[VideosCollectionViewController allocinit];

    videosVC.title = @"视频";

    CustomizedNavigationController *videosNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:videosVC];

    

    MoreViewController *moreVC = [[MoreViewController allocinit];

    moreVC.title = @"更多";

    CustomizedNavigationController *moreNaVC = [[CustomizedNavigationController alloc]initWithRootViewController:moreVC];

    

    self.viewControllers = @[coverNaVC, newsNaVC, brandsNaVC, videosNaVC, moreNaVC];

//使用的宏释放内存:(#define RELEASE_SAFE(_Pointer) do{[_Pointer release],_Pointer = nil;}while(0)

)

    RELEASE_SAFE(coverNaVC);

    RELEASE_SAFE(coverVC);

    RELEASE_SAFE(brandsNaVC);

    RELEASE_SAFE(brandsVC);

    RELEASE_SAFE(videosNaVC);

    RELEASE_SAFE(videosVC);

    RELEASE_SAFE(moreNaVC);

    RELEASE_SAFE(moreVC);

}


- (void)loadCustomizedTabBarView

{

    //初始化自定义TabBar背景

    UIImageView *tabBarBG = [[UIImageView allocinitWithFrame:CGRectMake(051932049)];

    tabBarBG.userInteractionEnabled = YES;

    tabBarBG.p_w_picpath = [UIImage p_w_picpathNamed:@"background"];

    [self.view addSubview:tabBarBG];

    [tabBarBG release];

    //初始化自定义TabBarItem -> Button

    for (int index = 0; index < 5; index++) {

        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

        button.backgroundColor = [UIColor whiteColor];

        button.tag = index;

        NSString *p_w_picpathName = [NSString stringWithFormat:@"%d", index + 100];

        [button setBackgroundImage:[UIImage p_w_picpathNamed:p_w_picpathName] forState:UIControlStateNormal];

        button.frame = CGRectMake(3 + 64 * index, 5290 / 539);

        [tabBarBG addSubview:button];

        [button addTarget:self action:@selector(changeViewController:)forControlEvents:UIControlEventTouchUpInside];

    }

}

//实现对应按钮和页面的跳转

- (void)changeViewController:(UIButton *)button

{

    self.selectedIndex = button.tag;

}



推荐阅读:
  1. iOS tabbar视图中隐藏tabbar
  2. 自定义tabBar详解第二种方案

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

自定义 tabbar 第一

上一篇:Django实战1-权限管理功能实现-01:搭建开发环境

下一篇:iOS网络开发(2)使用NSURLConnection

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》