导航栏自定义一个UIBarButtonItem最快的方式

1 + (UIBarButtonItem *)itemWithIcon:(NSString *)icon highIcon:(NSString *)highIcon target:(id)target action:(SEL)action
2 {
3     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
4     [button setBackgroundImage:[UIImage imageWithName:icon] forState:UIControlStateNormal];
5     [button setBackgroundImage:[UIImage imageWithName:highIcon] forState:UIControlStateHighlighted];
6     button.frame = (CGRect){CGPointZero, button.currentBackgroundImage.size};
7     [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
8     return [[UIBarButtonItem alloc] initWithCustomView:button];
9 }

 

你可能感兴趣的:(uibarbuttonitem)