1

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

代码:

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];
4

1 回答 1

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]];
于 2013-04-23T06:02:12.400 回答