iOS學(xué)習(xí)之導(dǎo)航欄右側(cè)放置兩個(gè)按鈕

@property(nonatomic,strong)UIBarButtonItem *mapBtn;//第一個(gè)

@property(nonatomic,strong)UIBarButtonItem *messageBtn;//第二個(gè)

//第一個(gè)
-(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;
}

//第二個(gè)
-(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];

}

感謝:http://www.lxweimin.com/p/f874326c6c44

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容