iOS-实现Tabbar导航栏效果

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // 1. 创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;

    // 2. 设置根控制器
    UITabBarController *tabbarVc = [[UITabBarController alloc] init];
    self.window.rootViewController = tabbarVc;

    // 3. 设置子控制器属性
    DJHomeViewController *homeVc = [[DJHomeViewController alloc] init];
    [self setChildVc:homeVc withTitle:@"首页" image:@"tabbar_home" selectedImage:@"tabbar_home_selected"];

    DJMessageCenterViewController *messageCenterVc = [[DJMessageCenterViewController alloc] init];
    [self setChildVc:messageCenterVc withTitle:@"消息" image:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];

    DJDiscoverViewController *discoverVc = [[DJDiscoverViewController alloc] init];
    [self setChildVc:discoverVc withTitle:@"发现" image:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];

    DJProfileViewController *profileVc = [[DJProfileViewController alloc] init];
    [self setChildVc:profileVc withTitle:@"我" image:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];

    // 4. 添加子控制器
    [tabbarVc addChildViewController:homeVc];
    [tabbarVc addChildViewController:messageCenterVc];
    [tabbarVc addChildViewController:discoverVc];
    [tabbarVc addChildViewController:profileVc];

    // 5. 显示窗口
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)setChildVc:(UIViewController *)vc withTitle:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage {

    vc.view.backgroundColor = DJRandomColor;
    vc.tabBarItem.title = title;

    // 设置tabbarItem 选中图片
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    // 设置tabarItem 选中颜色
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = DJColor(123, 123, 123);

    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];

    [vc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [vc.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];

}

最终效果:

时间: 2024-08-05 15:45:14

iOS-实现Tabbar导航栏效果的相关文章

iOS 顶部高斯模糊导航栏 + 页面内容穿越底部导航栏效果

(1)如果是使用系统导航栏则设置其translucent属性即可: [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new]; self.navigationController.navigationB

【转】iOS中设置导航栏标题的字体颜色和大小

原文网址:http://www.360doc.com/content/15/0417/11/20919452_463847404.shtml iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的方法,一般人也会采用这样的方式) 就是在导航向上添加一个titleView,可以使用一个label,再设置label的背景颜色透明,字体什么的设置就很简单了.

PagerSlidingTabStrip实现网易新闻导航栏效果

PagerSlidingTabStrip实现网易新闻导航栏效果之前在项目当中有一个需求,实现类似网易新闻标题导航的效果,于是在在github搜索下,找了一个开源PagerSlidingTabStrip,研究了这个空间的使用和一些方法,在此与大家分享,希望能够帮到有需要的朋友,好了废话不多讲,直接上代码. package com.example.textpagerslidingtabstrip.activity; import com.example.textpagerslidingtabstri

php实现三级导航栏效果

首先看看效果图: 1.数据配置文件 db.php <?php return array( array( 'one' => '关于我们', 'two' => array( array( 'three_tit' => '公司介绍', 'three_cont' => array( '企业概况', '组织架构', '发展历程', '企业文化', '服务理念' ) ), array( 'three_tit' => '企业荣誉', 'three_cont' => array(

jquery实现导航栏效果

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <div class="box"> <ul class="menu"> <li

网页定位 - 右侧导航栏效果

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>网页定位导航效果</title> 6 <style> 7 *{ 8 margin: 0; 9 padding: 0; 10 } 11 12 body{ 13 font-size: 12px; 14 line-height: 1

iOS: 状态栏、导航栏、标签栏、工具栏

三种项目栏总结: 工具栏:UIToolBar 导航栏:UINavigationBar 标签栏:UITabBar UIToolBar的按钮单元为:UIBarButtonItem UINavigationBar的按钮单元为:UINavigationItem UITabBar的按钮单元为:UITabBarItem 共同属性和方法: @property(nonatomic,copy)   NSArray   *items;                    //按钮单元数组 - (void)setI

Android之仿今日头条顶部导航栏效果

随着时间的推移现在的软件要求显示的内容越来越多,所以要在小的屏幕上能够更好的显示更多的内容,首先我们会想到底部菜单栏,但是有时候像今日头条新闻客户端要显示的内容太多,而且又想在主界面全部显示出来,所以有加了顶部导航栏. 今日头条顶部导航栏区域的主要部分是一个导航菜单.导航菜单是一组标签的集合,在新闻客户端中,每个标签标示一个新闻类别,对应下面ViewPager控件的一个分页面.当用户在ViewPager区域滑动页面时,对应的导航菜单标签也会相应的被选中,选中的标签通过一个矩形红框高亮显示,红框背

iOS解决隐藏导航栏后,打开照片选择器后导航栏不显示的问题以及更换导航栏背景色

问题描述: 遇到一种情况,在一个控制器上(隐藏了导航栏),打开照片选择器 UIImagePickerController后,照片选择器头部一片空白,且上滑相册时,信息会有错乱效果. 原因分析: 通过查看层次图,发现导航栏其实有的,那么问题是因为导航栏透明了导致的 解决办法: UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceT