-(void )SetNavBarView{
searchBarBtn.hidden=YES;
UIView *NavBarView ;
NavBarView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
btn1.titleLabel.font=[UIFont systemFontOfSize:14];
[btn1 setBackgroundImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateSelected];
[btn1 setBackgroundImage:[UIImage imageNamed:@"nine_grid.png"] forState:UIControlStateNormal];
btn1.tag=10;
[btn1 addTarget:self action:@selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn1];
UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(45, 0, 44, 44)];
btn2.titleLabel.font=[UIFont systemFontOfSize:14];
[btn2 setBackgroundImage:[UIImage imageNamed:@"map.png"] forState:UIControlStateNormal];
btn2.tag=11;
[btn2 addTarget:self action:@selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn2];
UILabel *labtitle=[[UILabel alloc]initWithFrame:CGRectMake(95, 0, 120, 44)];
labtitle.text=NSLocalizedString(@"people_nearby", nil);
labtitle.textColor=[UIColor whiteColor];
labtitle.backgroundColor=[UIColor clearColor];
labtitle.textAlignment=UITextAlignmentCenter;
labtitle.font=[UIFont boldSystemFontOfSize:20.0];
[NavBarView addSubview:labtitle];
UIButton *btn3 = [[UIButton alloc] initWithFrame:CGRectMake(135, 0, 95, 44)];
btn3.tag=12;
[btn3 addTarget:self action:@selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn3];
arrowImage=[[UIImageView alloc]initWithFrame:CGRectMake(75, 16, 10, 10)];
arrowImage.image=[UIImage imageNamed:@"arrow_down.png"];//arrow_down.png
[btn3 addSubview:arrowImage];
UIButton *btn4 = [[UIButton alloc] initWithFrame:CGRectMake(230, 0, 44, 44)];
btn4.titleLabel.font=[UIFont systemFontOfSize:14];
[btn4 setBackgroundImage:[UIImage imageNamed:@"ic_action_search.png"] forState:UIControlStateNormal];
btn4.tag=13;
[btn4 addTarget:self action:@selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn4];
// [bubble stretchableImageWithLeftCapWidth:20 topCapHeight:14]
UIButton *btn5 = [[UIButton alloc] initWithFrame:CGRectMake(275, 0, 44, 44)];
btn5.backgroundColor=[UIColor redColor];
[btn5 setBackgroundImage:[UIImage imageNamed:@"location.png" ] forState:UIControlStateNormal];
btn5.tag=14;
[btn5 addTarget:self action:@selector(btnBarClick:) forControlEvents:UIControlEventTouchUpInside];
[NavBarView addSubview:btn5];
NavBarView.hidden=NO;
// [self.view addSubview:NavBarView];
self.navigationItem.titleView=NavBarView;
}
我有一个UINavigationItem
,它有五个按钮。第五个按钮btn5
只能点击左侧,但btn5
的右侧无法点击。 (按钮的大小为44 x 44)
答案 0 :(得分:0)
这是因为UINavigationBarItem的大小,默认情况下会在两侧留下14px。如果您为第一个按钮指定背景颜色,那么您会看到该空格。