• iOS开篇——UI之UINavigationController


    把NavigationController设为根视图控制器

        FirstViewController * firstVC = [[FirstViewController alloc]init];
        
        
        UINavigationController * nc = [[UINavigationController alloc]initWithRootViewController:firstVC];
        
        _window.rootViewController = nc;

    NavigationController之间的跳转

    SecondViewController * secondVC = [[SecondViewController alloc]init];
        
        [self.navigationController pushViewController:secondVC animated:YES];
    //压栈方式跳转
      [self.navigationController popViewControllerAnimated:YES];
    //出栈方式返回

    设置toolBar

        [self.navigationController setToolbarHidden:NO animated:YES];
        //toolBar自定制和navigationBar基本相同 可以参考bar的自定制
        //设置是否透明
        self.navigationController.toolbar.translucent = YES;
        //设置样式
        self.navigationController.toolbar.barStyle = UIBarStyleDefault;

    设置NavigationBar

    //加注释 导航条增高20
        self.navigationItem.prompt = @"这是一个注释";
        
        //设置titleView——>
        UIView *view =[[UIView alloc]initWithFrame:CGRectMake(100, 100, 300, 20)];
        view.backgroundColor = [UIColor redColor];
        
        [UIView animateWithDuration:3 delay:2 options:0 animations:^{
            view.backgroundColor = [UIColor yellowColor];
        } completion:nil];
        self.navigationItem.titleView = view;
    
        //设置导航条样式
        self.navigationBar.barStyle = UIBarStyleBlack;
        
        //设置是否透明
         self.navigationBar.translucent = NO;

    创建BarButtonItem  

    UIBarButtonItem * item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];
    //系统样式
    
     UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        UIBarButtonItem * customItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    //自定义
    
    //iOS7以后 用图片设置barButtonItem时 要用imageWithRenderingMode:设置一直显示图片原来色彩
        UIImage * image = [[UIImage imageNamed:@"1-1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UIBarButtonItem * customItem1  = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStyleDone target:nil action:nil];
    //用图片来创建
  • 相关阅读:
    iOS AppStore个人开发者账号申请
    一个工程多个Target
    React Native环境搭建(iOS、Mac)
    vuex的简单使用
    在vue中使用sass
    一个javascript继承和使用的例子
    在vue中使用Element-UI
    CSS3 Flex布局和Grid布局
    (...)ES6三点扩展运算符
    h5 video切换到横屏全屏
  • 原文地址:https://www.cnblogs.com/gwkiOS/p/4990199.html
Copyright © 2020-2023  润新知