ios - Navigation bar plus image or text button

 

//Add the right button to the navigation bar (the system comes with deletion)

    // self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(selectMore:)];

    

    

   // set to image

    

     self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc] initWithTitle:nilstyle:UIBarButtonItemStylePlaintarget:selfaction:@selector(selectMore:)];

    [self.navigationItem.rightBarButtonItemsetImage : [ UIImageimageNamed:@"sytb"]];

    

    // set to text

//    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithTitle:@"文字" style:UIBarButtonItemStylePlain target:self action:@selector(selectText:)];

//    

    self.navigationItem.rightBarButtonItem.tintColor=[UIColorwhiteColor];



#pragma mark - select the item on the right

-(void)selectMore:(id)paramSender{

    

    

    NSLog ( @"More button clicked" );

}






    //Add a custom button on the left

    LocationBtn *btn=[[LocationBtnalloc]init];

    [btn setImage:[UIImage imageNamed:@"下拉"] forState:UIControlStateNormal];

    [btn setTitle:city forState:UIControlStateNormal];

    [btn setTitleColor : [ UIColor darkGrayColor ] forState : UIControlStateNormal ];

    [btn sizeToFit ];

    [btn addTarget:self action:@selector(ClickScanCode:) forControlEvents: UIControlEventTouchUpInside];

    UIBarButtonItem * leftItemBtn = [[ UIBarButtonItem alloc ] initWithCustomView : btn];

    self.navigationItem.leftBarButtonItem=leftItemBtn;




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325427360&siteId=291194637