美文网首页iOS开发札记
Navigation 常见使用

Navigation 常见使用

作者: 小布走慢点 | 来源:发表于2016-05-04 10:42 被阅读167次

    全局设置

    self.navigationController.navigationBar.translucent = NO;//    Bar的模糊效果,默认为YES 使用后会下掉64单位
    
    // 去掉navigation 左侧的标题
     [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];
    
    // 设置全局样式
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
        [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    }
    else {
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    }
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, [UIFont boldSystemFontOfSize:18], NSFontAttributeName, nil]];
    
     [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica" size:(18)],NSFontAttributeName,nil]];
    

    系统默认按钮

    //默认图标
    UIBarButtonItem *addMember = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addMember)];
    self.navigationItem.rightBarButtonItem = addMember;
    
    //默认文字
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"导入联系人" style:UIBarButtonItemStylePlain target:self action:@selector(doClickSubmitAction)];
    

    自定义图案

    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"album_add_photo"] style:UIBarButtonItemStylePlain target:self action:@selector(onAddAlbumButtonClicked)];
    

    自定义文字

    UIButton* backButton= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [backButton setTitle:@"Submit" forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(doClickSubmitAction)forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
    

    设置Item颜色

    self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];
    

    设置titleView

    UIButton *navButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200, 44)];
    [navButton setBackgroundColor:[UIColor blackColor]];
    [navButton setTitle:@"Discover" forState:UIControlStateNormal];
    [navButton addTarget:self action:@selector(_actionlocat:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = navButton;
    

    简单的自定义动画

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.navigationController pushViewController:view animated:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];
    

    返回多层

     返回指定的某个vc用下面(通过index定位) 
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
    
    [self.navigationController popToViewController:  [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] animated:YES];
    
    或(通过class定位)
    for (UIViewController *controller in self.navigationController.viewControllers) { 
      if ([controller isKindOfClass:[你要跳转到的Controller class]]) { [self.navigationController popToViewController:controller animated:YES]; }
    }
    

    Item图标大小设计标准

    相关文章

      网友评论

        本文标题:Navigation 常见使用

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