1

我有NavigationBar。当我将按钮添加到导航栏时,它不会显示。UINavigationBar按钮不显示

代码:

UINavigationController *nav=[[UINavigationController alloc]init]; 

    [self.view addSubview:nav.view]; 

    UIImage *info_iphone=[UIImage imageNamed:@"infobtn_iphone.png"]; 
    UIButton *infobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 48, 30)]; 
    [infobtn setBackgroundImage:info_iphone forState:UIControlStateNormal]; 
    [infobtn addTarget:self action:@selector(show_info) forControlEvents:UIControlEventTouchUpInside]; 

    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:infobtn]; 

回答

1
UIButton *tempButton1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
[tempButton1 setFrame:CGRectMake(0, 0, 34, 34)];// your image width and height 
[tempButton1 addTarget:self action:@selector(btnBackClicked:) forControlEvents:UIControlEventTouchUpInside]; 
[tempButton1 setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal]; 
[tempButton1 setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateHighlighted]; 
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:tempButton1]]; 
+0

它不显示栏按钮... – Ram 2013-04-23 06:07:09

+0

难道不是显示静止? – 2013-04-23 06:27:59