iOS开发--一些UITabBarItem属性的设置

作者: 寒桥 | 来源:发表于2015-03-19 12:50 被阅读28264次

    1.改变UITabBarItem 字体颜色

    [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColorwhiteColor],UITextAttributeTextColor,nil]forState:UIControlStateNormal];

    [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorcolorWithHexString:"#00C8D3"],UITextAttributeTextColor,nil]forState:UIControlStateSelected];

    设置tabbarItem选中的颜色为红色

    2.改变UITabBarItem 字体颜色和大小

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateNormal];

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateSelected];

    设置UITabBarItem 字体颜色和大小

        这里需要注意的是在设置字体的时候要选择支持中文的字体,不然的话修改字号是无效的,比如字体设置成“ProximaNova-Semibold”,这种字体本身只支持英语的,不支持中文所以使用该字体并不能调整字体大小

    3.改变UITabBarItem的选中和非选中图片

    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:[[ServiceProviderViewController alloc] init]];

    nav1.tabBarItem.image = [ImageNamed(@"tabicon1_unselect") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    nav1.tabBarItem.selectedImage = [ImageNamed(@"tabicon1_select") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    nav1.tabBarItem.title = @"服务商";

    改变UITabBarItem的选中和非选中图片

    4.改变UITabBarController的颜色

    UIView*mView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,48)];//这是整个tabbar的颜色

    [mViewsetBackgroundColor:[UIColorcolorWithPatternImage:[UIImageimageNamed:@"tabbar.png"]]];

    [tab.tabBarinsertSubview:mViewatIndex:1];

    mView.alpha=0.8;

    设置UITabBar的颜色

    5.如何隐藏系统自带的tabbar

    有时候有的页面并不需要显示tabbar,但是返回的时候要显示tabbar,举个例子A->B 当A push到 B 时需要设置self.navigationController.hidesBottomBarWhenPushed= YES;

    A页面的设置

    同时在B页面要

    - (void)viewWillAppear:(BOOL)animated

    {

    [superviewWillAppear:animated];

    self.tabBarController.tabBar.hidden=YES;

    }

    - (void)viewWillDisappear:(BOOL)animated

    {

    [superviewWillDisappear:animated];

    self.tabBarController.tabBar.hidden=NO;

    }

    设置进到页面时隐藏,退出页面时不隐藏

    相关文章

      网友评论

      • 金蛇郎君木子肆:字体大小不改变
      • 也许________:排版太乱啦 希望博主好好写 :smiley:
        寒桥:@也许________ OK 之前写的没有用Markdown 就是简单记录了一下 之后的慢慢开始使用Markdown来写了
      • 52b47abbb6db:隐藏tabbar那个我赞同此方法,用手势的话效果会比较生硬!push完了 再把属性设置成NO就行了
        self.hidesBottomBarWhenPushed= YES;
        PUSH
        self.hidesBottomBarWhenPushed= NO;
      • 叶舞清风:为什么我报错了啊???Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
        fly大梦想家:@寒桥 我也是按照你的弄得,怎么也是同样的错误,还有就是能不能不用button和label实现tabbaritem中图片和文字横向并排而不是上下结构的效果
        寒桥:@叶舞清风 你是需要改变颜色还是字体
        寒桥:@叶舞清风 是按照我写的弄得吗?

      本文标题:iOS开发--一些UITabBarItem属性的设置

      本文链接:https://www.haomeiwen.com/subject/wpdwxttx.html