iOS 11导航栏 左右控件高度问题

iOS11系统 导航栏大改 导航栏上的左右按钮的默认位置基本都会出现高度问题
下面通自定义并对不同的系统设置好位置

rightBarButtonItem

//判断iOS版本是
    if ([UIDevice currentDevice].systemVersion.doubleValue >= 11.0){
        //右
        UIView *barView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 8, 40, 40);
        [btn setImage:[UIImage imageNamed:@"图片名字"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(方法名字) forControlEvents:UIControlEventTouchUpInside];
        [barView addSubview:btn];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:barView];

    }else{
    //ios11系统以下
            self.navigationItem.rightBarButtonItem = [self createBarButtonItem:@"" image:[UIImage imageNamed:@"图片名字"] action:@selector(方法名字)];
    }

leftBarButtonItem的后退按钮位置

if ([UIDevice currentDevice].systemVersion.doubleValue >= 11.0){

        //后退按钮
        UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
        UIButton *leftbtn =[UIButton buttonWithType:UIButtonTypeCustom];
        leftbtn.frame = CGRectMake(0, 0, 40, 40);
        //ic_back为后退的图片名字
        [leftbtn setImage:[UIImage imageNamed:@"ic_back"] forState:UIControlStateNormal];
        [leftbtn addTarget:self action:@selector(popAction) forControlEvents:UIControlEventTouchUpInside];
        [leftView addSubview:leftbtn];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftView];

    }

上面用到的 popAction方法

//后退方法
-(void)popAction{
    [self.navigationController popViewControllerAnimated:YES];
}

你可能感兴趣的:(ios)