【小笔记】自定义返回按钮

方法一、

- (void)customBack {
    
    //返回 按钮  
    
    UIBarButtonItem *item =
    [[UIBarButtonItem alloc] initWithTitle:@""
                                     style:UIBarButtonItemStylePlain
                                    target:nil
                                    action:nil];
    [self.navigationController.navigationBar
     setTintColor:[UIColor whiteColor]];
    self.navigationItem.backBarButtonItem = item;
    
}

方法二、

- (void)customBack {
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    btn.frame= CGRectMake(0, 0, 20, 40);
    [btn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    
    [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    
    negativeSpacer.width = 0;
    [self.navigationController.navigationBar
     setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];
    
    
} 

-(void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}




展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 撸撸猫 设计师: 设计师小姐姐
应支付0元
点击重新获取
扫码支付

支付成功即可阅读