在iOS7中自定义导航栏标题视图?
您好,我只想通过在iOS7中的导航栏上添加三个按钮来自定义导航栏的标题视图,下面是我的代码,但什么都没有发生在iOS7中自定义导航栏标题视图?,ios7,uinavigationcontroller,uinavigationbar,Ios7,Uinavigationcontroller,Uinavigationbar,您好,我只想通过在iOS7中的导航栏上添加三个按钮来自定义导航栏的标题视图,下面是我的代码,但什么都没有发生 -(void)addCutomButtonsToNavigationController:(UINavigationController *)navigationController { UIView *customNavigationTitleView=[[UIView alloc] initWithFrame:CGRectMake(20, 0, 250, 44)];
-(void)addCutomButtonsToNavigationController:(UINavigationController *)navigationController
{
UIView *customNavigationTitleView=[[UIView alloc] initWithFrame:CGRectMake(20, 0, 250, 44)];
[customNavigationTitleView setBackgroundColor:[UIColor blackColor]];
UIButton *friendRequestButton=[UIButton buttonWithType:UIButtonTypeCustom];
UIButton *messagesButton=[UIButton buttonWithType:UIButtonTypeCustom];
UIButton *notificationsButton=[UIButton buttonWithType:UIButtonTypeCustom];
[friendRequestButton setImage:[UIImage imageNamed:@"ic_clients.png"] forState:UIControlStateNormal];
[messagesButton setImage:[UIImage imageNamed:@"ic_location.png"] forState:UIControlStateNormal];
[notificationsButton setImage:[UIImage imageNamed:@"ic_message.png"] forState:UIControlStateNormal];
[friendRequestButton setFrame:CGRectMake(0, 10, 40, 40)];
[customNavigationTitleView addSubview:friendRequestButton];
[customNavigationTitleView addSubview:messagesButton];
[customNavigationTitleView addSubview:notificationsButton];
navigationController.navigationItem.titleView =customNavigationTitleView;
}
试试这个
-(void)addCutomButtonsToNavigationController:(UINavigationController *)navigationController
{
UIView *customNavigationTitleView=[[UIView alloc] initWithFrame:CGRectMake(40, 0, 160, 44)];
UIButton *friendRequestButton=[UIButton buttonWithType:UIButtonTypeCustom];
UIButton *messagesButton=[UIButton buttonWithType:UIButtonTypeCustom];
UIButton *notificationsButton=[UIButton buttonWithType:UIButtonTypeCustom];
[friendRequestButton setImage:[UIImage imageNamed:@"ic_clients.png"] forState:UIControlStateNormal];
[messagesButton setImage:[UIImage imageNamed:@"ic_location.png"] forState:UIControlStateNormal];
[notificationsButton setImage:[UIImage imageNamed:@"ic_messsage.png"] forState:UIControlStateNormal];
[friendRequestButton setFrame:CGRectMake(10, 0, 40, 40)];
[messagesButton setFrame:CGRectMake(60, 0, 40, 40)];
[notificationsButton setFrame:CGRectMake(110, 0, 40, 40)];
[customNavigationTitleView addSubview:friendRequestButton];
[customNavigationTitleView addSubview:messagesButton];
[customNavigationTitleView addSubview:notificationsButton];
self.navigationItem.titleView =customNavigationTitleView;
}