Create a custom left back button on UINavigationBar WITH the standard arrow on the left

后端 未结 6 1595
情书的邮戳
情书的邮戳 2021-02-05 03:27

When I create a custom back button, I use the following code:

    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithTitle:@\"Yeah\" style:UIBarButton         


        
6条回答
  •  盖世英雄少女心
    2021-02-05 04:15

    UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
    [backButton setFrame:FRAME_DEFINE
    [backButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [backButton setExclusiveTouch:YES];
    [backButton setImage:[UIImage imageNamed:BACK_BUTTON_DEFAULT_ICON] forState:UIControlStateNormal];
    [backButton setTitle:@"BACK" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *backMenuBarButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = backMenuBarButton;
    

提交回复
热议问题