导航栏自定义一个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 }

 

posted @ 2015-07-27 00:03  张雄杰vip  阅读(101)  评论(0编辑  收藏  举报