ios 怎么修改uinavigationbar左边返回按钮

2025-05-09 05:13:35
推荐回答(1个)
回答1:

-(void)createNavLeftBtnWithImageName:(NSString *)imageName AndAction:(SEL)Action

{

UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];

btn.frame = CGRectMake(0, 0, 7, 12);

btn.adjustsImageWhenHighlighted = NO;

if (imageName && imageName.length > 0) {

[btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];

}

if (Action) {

[btn addTarget:self action:Action forControlEvents:UIControlEventTouchUpInside];

}

UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:btn];

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

negativeSpacer.width = -8;//ios7以后右边距默认值18px,负数相当于右移,正数左移

self.navigationItem.leftBarButtonItems=@[negativeSpacer,item];

}