iPhone自定义导航栏按钮

通常使用的Navigation Item中有backBarButtonItem/leftBarButtonItem/rightBarButtonItem三个按键,其中backBarButtonItem为只读,不能修改,其他两个都可以自由修改.不但可以防止button,还可以用自定义的view来填充,比方说想在导航栏右侧防止两个按钮,如图所示
 
 
代码如下:
 UIView *rightBarView = [[UIView alloc]initWithFrame:CGRectMake(618, 0, 150, 44)];
 
 UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 [editBtn setFrame:CGRectMake(10, 10, 50, 25)];
 [editBtn addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside];
 [editBtn setTitle:@"编辑" forState:UIControlStateNormal];
 [editBtn setTag:11];
 [rightBarView addSubview:editBtn];
 
 UIButton *submitBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 [submitBtn setFrame:CGRectMake(80, 10, 70, 25)];
 [submitBtn addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
 [submitBtn setTitle:@"提交订单" forState:UIControlStateNormal];
 [submitBtn setTag:12];
 [rightBarView addSubview:submitBtn];
 
 UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithCustomView:rightBarView];
 self.navigationItem.rightBarButtonItem = rightBtn; 
 

你可能感兴趣的:(自定义,iPhone,导航栏,NavigationItem,BarButtonItem)