@property(nonatomic,strong)UIBarButtonItem *mapBtn;//第一个
@property(nonatomic,strong)UIBarButtonItem *messageBtn;//第二个
//第一个
-(UIBarButtonItem *)mapBtn{
if (!_mapBtn) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e637", 23, __kColorGray)] forState:UIControlStateNormal];
[btn sizeToFit];
_mapBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
return _mapBtn;
}
//第二个
-(UIBarButtonItem *)messageBtn{
if (!_messageBtn) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e69a", 25, __kColorGray)] forState:UIControlStateNormal];
[btn sizeToFit];
_messageBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
return _messageBtn;
}
//显示
- (void)viewDidLoad {
[super viewDidLoad];
//间隙
UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpaceBarButtonItem.width = 12;
self.navigationItem.rightBarButtonItems = @[self.messageBtn,fixedSpaceBarButtonItem,self.mapBtn];
}
感谢:https://www.jianshu.com/p/f874326c6c44
网友评论