iOS 修改导航栏按钮的位置
来源:互联网
UINavigationItem可以理解为Navigation Bar中的内容,通过编辑UINavigationItem,我们可以使得在Navigation Bar中显示想要的东西,比如设置标题、添加按钮等。当我们使用系统原生控件时,有时候不能满足需求,因此需要自定义重写,最近在项目中需要用导航栏的右侧按钮,先是直接用系统原生的控件。代码如下: UIButton *settingButton = [UIButton buttonWithType:UIButtonTypeCustom]; [settingButton setFrame:CGRectMake(0.0, 0.0, 44.0, 44.0)]; [settingButton addTarget:self action:@selector(settingButtonOnClicked:) forControlEvents:UIControlEventTouchUpInside]; [settingButton setImage:[UIImage imageNamed:@"ic_main_setting"] forState:UIControlStateNormal]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:settingButton];效果如图:系统原生按钮位置效果UINavigationItem可以理解为Navigation Bar中的内容,通过编辑UINavi