我想創建一個像下面圖的導航條navigationBar :
我知道可以使用UIButton代替導航條中間的標題,但是能不能弄成像這張圖片這樣的?
如上圖,在導航條中有三個不同的button,怎麼在iphone中實現這樣的效果?
如果用UINavigationController:
1.改變導航條背景圖:
[self.navigationController.navigationBar setBackgroundImageForBarMetrics:]
2.左右button的設置:
[self.navigationItem setLeftBarButtonItem:],[self.navigationItem setRightBarButtonItem:]
需要去掉邊框。
3.設置中間的三個button:
UIView *buttonView= [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 40)];
UIButton *button1= [UIButton buttonWithType:UIButtonTypeCustom];
button1.imageView.image= [UIImage imageNamed:@"button1.png"];
button1.frame= CGRectMake(0, 0, 40, 40);
UIButton *button2= [UIButton buttonWithType:UIButtonTypeCustom];
button2.imageView.image= [UIImage imageNamed:@"button2.png"];
button2.frame= CGRectMake(70, 0, 40, 40);
UIButton *button3= [UIButton buttonWithType:UIButtonTypeCustom];
button3.imageView.image= [UIImage imageNamed:@"button3.png"];
button3.frame= CGRectMake(140, 0, 40, 40);
[buttonView addSubview:button1];
[buttonView addSubview:button2];
[buttonView addSubview:button3];
self.navigationItem.titleView= buttonView;
大小自己調。