ios 右按鈕靠右顯示
閑話少說 大家都知道ios導(dǎo)航欄右按鈕或者左按鈕系統(tǒng)默認(rèn)不是太靠左或者靠右 ?這就需要我們自己調(diào)整,下面就是我項目代目,邏輯不多說 直接上代碼
右按鈕靠右顯示
- (void)rightBtnSava{
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
rightButton.frame=CGRectMake(0, 0, 50, 20);
//? ? [rightButton setBackgroundImage:[UIImage imageNamed:@"message.png"] forState:UIControlStateNormal];
[rightButton setTitle:@"新增" forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(rightSavesAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
rightButton.titleLabel.font = [UIFont boldSystemFontOfSize:15];
//解決按鈕不靠左 靠右的問題.
UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
nagetiveSpacer.width = -10;//這個值可以根據(jù)自己需要自己調(diào)整
self.navigationItem.rightBarButtonItems = @[nagetiveSpacer, rightBar];
}
希望對你有所幫助 也希望喜歡的朋友關(guān)注下我