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; 
相關文章
相關標籤/搜索