How to set a picture programmatically in a NavBar?

后端 未结 4 560
温柔的废话
温柔的废话 2020-11-29 14:11

I have a detailview with a navigation bar with a back button and a name for the view. The navigation bar is set programmatically. The name presented is set like this.

<
4条回答
  •  天涯浪人
    2020-11-29 14:57

    UIButton *homeBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 46, 28)];
    [homeBtn setBackgroundImage:[UIImage imageNamed:@"homeBtn.png"] forState:UIControlStateNormal];    
    [homeBtn addTarget:self action:@selector(homeBtnPressed) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *navHomeBtn=[[[UIBarButtonItem alloc] initWithCustomView:homeBtn] autorelease];    
    self.navigationItem.rightBarButtonItem=navHomeBtn;   
    [homeBtn release];
    

提交回复
热议问题