當我們在自定義UIBarButtonItem時,會遇到UIBarButtonItem的位置會距離邊界有一段距離鞍历,看起來很不美觀炸茧,這時候就需要對UIBarButtonItem進行一下設(shè)置乌逐,以達到相應效果。
//這里重新設(shè)置新的返回按鈕
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_back_n"] style:UIBarButtonItemStyleDone target:self action:@selector(backPreviousViewController)];
//設(shè)置返回按鈕的屬性
UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSeperator.width = -23;//此處修改到邊界的距離逻住,請自行測試
//將返回按鈕和對應屬性設(shè)置到導航欄
[self.navigationItem setLeftBarButtonItems:@[negativeSeperator, backBarButtonItem]];
//返回上一層界面事件
-(void)backPreviousViewController{
// 返回上一層界面
[self.navigationController popViewControllerAnimated:YES];
}