ios 怎么修改uinavigationbar左边返回按钮
展开全部
-(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];
}
{
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];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询