导航栏的定义操作

导航栏设置透明

UIImage *image = [[UIImage alloc] init];[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    //去掉透明后导航栏下边的黑边

    [self.navigationController.navigationBar setShadowImage:image];

    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

    self.navigationController.navigationBar.translucent = YES;


导航栏背景自定义,去除下方的黑线

@property (nonatomic, strong) UIImageView * navBarHairlineImageView;

- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {

    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {

        return (UIImageView *)view;

    }

    for (UIView *subview in view.subviews) {

        UIImageView *imageView = [self findHairlineImageViewUnder:subview];

        if (imageView) {

            return imageView;

        }

    }

    return nil;

}

- (void)viewWillAppear:(BOOL)animated{

    _navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

    _navBarHairlineImageView.hidden = YES;

    [self.navigationController.navigationBar setBarTintColor:你的颜色];

    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];

    self.tabBarController.tabBar.hidden = YES;

    [self navButton];

}

- (void)viewWillDisappear:(BOOL)animated{

    _navBarHairlineImageView.hidden = NO;

    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithWhite:1 alpha:0.8]];

    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil]];

    self.tabBarController.tabBar.hidden = NO;

}


返回按钮

#pragma mark - 定义导航的按钮

- (void)navButton{

    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];

    leftButton.frame = CGRectMake(0, 0, 25, 25);

    [leftButton setImage:[UIImage imageNamed:@"back_white"] forState:0];

    [leftButton setBackgroundColor:[UIColor clearColor]];

    leftButton.titleLabel.font = [UIFont systemFontOfSize:15];

    [leftButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem * tiem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];

    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]

                                      initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

                                      target:nil action:nil];

    negativeSpacer.width = -10;

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, tiem, nil];


    UIButton * rightButton = [UIButton buttonWithType:UIButtonTypeCustom];

    rightButton.frame = CGRectMake(0, 0, 25, 25);

    [rightButton setImage:[UIImage imageNamed:@"search.png"] forState:0];

    [rightButton setBackgroundColor:[UIColor clearColor]];

    rightButton.titleLabel.font = [UIFont systemFontOfSize:15];

    [rightButton addTarget:self action:@selector(rightButtonClick) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem * tiemRight = [[UIBarButtonItem alloc]initWithCustomView:rightButton];

    UIBarButtonItem *negativeSpacerRight = [[UIBarButtonItem alloc]

                                            initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

                                            target:nil action:nil];

    negativeSpacerRight.width = -10;

    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacerRight, tiemRight, nil];

}

- (void)leftClick{

    [self.navigationController popViewControllerAnimated:YES];

}

- (void)rightButtonClick{


}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 4月03日第5天共读第五天—张润华 在一个惬意的环境中被动地生活所感受到的快乐,远远比不上那种有激情地投入到有价值...
    触心凝眸2020阅读 177评论 0 0
  • 一、目录查询查看根目录文件 二、赋权限 三、修改文件的所有者改为etl用户
    BestFei阅读 148评论 0 0
  • 如果享受雨幕而不能随性作诗写文 那享受美好又有什么意义 重要的不只有感受 还有抒写和记录
    孤烟起朝岚阅读 56评论 0 0