見程式碼
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 44, 44);
btn.adjustsImageWhenHighlighted = NO;
[btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[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 = -12;//ios7以後右邊距預設值18px,負數相當於右移,正數左移
self.navigationItem.leftBarButtonItems=@[negativeSpacer,item];
見程式碼
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 44, 44);
btn.adjustsImageWhenHighlighted = NO;
[btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[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 = -12;//ios7以後右邊距預設值18px,負數相當於右移,正數左移
self.navigationItem.leftBarButtonItems=@[negativeSpacer,item];