美文网首页
2018-09-12

2018-09-12

作者: ro萝卜先生 | 来源:发表于2018-09-12 14:59 被阅读0次


    ios 开发中的一些小常识  陆续更新

    可以写在define中的一些全局变量

    //导航栏 状态栏 设置gao du
    #define statusRect [[UIApplication sharedApplication] statusBarFrame].size.height
    #define navRect self.navigationController.navigationBar.frame.size.height

    #define topHeight (statusRect + navRect)(这个是获取导航栏和状态栏的高度,不要在继续64了,我们程序员应该精益求精啊)

    获取颜色的rgb 转换

    #define UIColorFromHex(s) [UIColor colorWithRed:(((s & 0xFF0000) >> 16 )) / 255.0 green:((( s & 0xFF00 ) >> 8 )) / 255.0 blue:(( s & 0xFF )) / 255.0 alpha:1.0]

    怎么用??看实例----

    self.navigationController.navigationBar.barTintColor = UIColorFromHex(0X1C86EE);//这样就可以了  把获取的颜色rgb #FFDEAD 前面的#换做0X就可以了  往后的颜色全是你定了,适合那些没有美工支持的集设计与开发一身的二阶程序员

    走一下快速建立tabbar的步骤吧

    建立一个继承与UItabbarcontroller的view  .m文件中写下这些就够了哦,然后Appdelegate里面怎么写,这个就很随意了,温馨提示,在下也是小白,但是经过测试发现  图片用_@3x的简直不要太合适哦

    - (void)viewDidLoad {

        [super viewDidLoad];

        [self setupItem];

        [self setupChildVC];

     

    }

    - (void)setupItem{
        //正常情况下图标下方文字的显示属性
        NSMutableDictionary *normalTextAtts = [NSMutableDictionary dictionary ];
        //文字颜色
        normalTextAtts[NSForegroundColorAttributeName] = [UIColor grayColor];
        //选中情况下文字的颜色属性
        NSMutableDictionary *selectAtts = [NSMutableDictionary dictionary];
        //文字颜色
        selectAtts[NSForegroundColorAttributeName] = UIColorFromHex(0X1C86EE);
       
        //统一设置baritem的属性
        UITabBarItem *tabItem = [UITabBarItem appearance];
        [tabItem setTitleTextAttributes:normalTextAtts forState:UIControlStateNormal];
        [tabItem setTitleTextAttributes:selectAtts forState:UIControlStateSelected];
       
    }
    - (void)setupChildVC{
       
      
        [self setupChildvc:[[mainViewController alloc]init] titile:@"首页" normalImage:@"首页(4)_@3x" selectImage:@"首页(5)_@3x"];
     
        [self setupChildvc:[[ViewController alloc]init] titile:@"个人中心" normalImage:@"我的(4)_@3x" selectImage:@"我的(5)_@3x"];
      
       
    }
    //结构化封装子视图
    - (void)setupChildvc:(UIViewController*)vc titile:(NSString*)title normalImage:(NSString*)image selectImage:(NSString*)simage{
       
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
     
        [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
       
        nav.tabBarItem.title = title;
        nav.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        nav.tabBarItem.selectedImage = [[UIImage imageNamed:simage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //nav.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
        nav.view.backgroundColor = [UIColor whiteColor];
        [self addChildViewController:nav];
       
    }

    相关文章

      网友评论

          本文标题:2018-09-12

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