How to add custom image in navigation bar button item?

前端 未结 12 1702
我寻月下人不归
我寻月下人不归 2020-12-13 09:26
 UIBarButtonItem *doneitem=[[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)]autorelease];
           


        
12条回答
  •  伪装坚强ぢ
    2020-12-13 10:17

    To pick up on the answer by Gurpreet Singh. To keep the current status of an already existing button re-use the target and action.

    SEL selector = self.navigationItem.rightBarButtonItem.action;
    id target = self.navigationItem.rightBarButtonItem.target;
    UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_close.png"]
                                                          style:UIBarButtonItemStylePlain
                                                         target:target
                                                         action:selector];
    
    self.navigationItem.rightBarButtonItem = _btn;
    

提交回复
热议问题