Add target to stock back button in navigationBar

前端 未结 6 1865
我在风中等你
我在风中等你 2021-01-14 18:48

I am setting the values of the title and back button in the UINavigationBar as follows:

self.navigationItem.title = @\"Post\";
[self.navigationC         


        
6条回答
  •  执笔经年
    2021-01-14 19:08

    First of hide back button

    self.navigationItem.hidesBackButton = YES;

    Then You make the custom button

     UIButton *leftbarButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
     leftbarButton.frame =CGRectMake(70, 3, 65, 32);
     [leftbarButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
     [leftbarButton addTarget:self action:@selector(leftbarbuttonclick) forControlEvents:UIControlEventTouchUpInside];
    
     UIBarButtonItem *newdbutton =[[UIBarButtonItem alloc] leftbarButton];
    

    AND add it to navigation left bar button item

    self.navigationItem.leftBarButtonItem =newbutton;
    

    Now add actions to it

    -(void)leftbarbuttonclick {
        // Your code
    }
    

提交回复
热议问题