iOS 添加导航按钮

时间:2024-11-27 21:35:56

iOS设置导航按钮
navigationBar中包含了这几个重要组成部分:leftBarButtonItem, rightBarButtonItem, backBarButtonItem, title。
下面是代码

//设置右Btn
UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(, , , )]; [rightBtn setTitle:@"搜索" forState:UIControlStateNormal]; [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn]; [self.navigationItem setRightBarButtonItem:rightItem];