效果如图:
代码:
self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithNormalImage:@"MainTagSubIcon" hignlightImage:@"MainTagSubIconClick" target:self action:@selector(leftButtonClick)];
+ (instancetype)itemWithNormalImage:(NSString *)normalImage hignlightImage:(NSString*)hignlightImage target:(id)target action:(SEL)action{
UIButton *buttonItem = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonItem setImage:kImage(normalImage) forState:UIControlStateNormal];
[buttonItem setImage:kImage(hignlightImage) forState:UIControlStateHighlighted];
[buttonItem addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[self alloc]initWithCustomView:buttonItem];
}
原因:customView没有指定尺寸(位置不用指定)
加了句:
buttonItem.size = buttonItem.currentImage.size;
效果如图: