您的位置:首页 > 产品设计 > UI/UE

UIBarButtonItem类目-返回一个有图片的导航栏按钮

2015-07-28 14:54 459 查看
/**
* 快速创建一个显示图片的item
*
* @param action 监听方法
*/
+ (UIBarButtonItem *)itemWithIcon:(NSString *)icon highIcon:(NSString *)highIcon target:(id)target action:(SEL)action;

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

为UIBarButtonItem添加类目
使用:

// 左边按钮
self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"navigationbar_friendsearch" highIcon:@"navigationbar_friendsearch_highlighted" target:self action:@selector(findFriend)];

// 右边按钮
self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithIcon:@"navigationbar_pop" highIcon:@"navigationbar_pop_highlighted" target:self action:@selector(pop)];

链接: http://pan.baidu.com/s/14UqrO 密码: i8y8
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS开发