How to remove padding next to a UIBarButtonItem

后端 未结 4 1461
说谎
说谎 2021-01-05 13:46

I have added a custom button to the navigation bar\'s custom right bar button item as shown in the image.

I\'m want to be able to remove the space after the button

4条回答
  •  我在风中等你
    2021-01-05 13:51

    You have to create a new view, add button and everything else you want and add it to the titleView as shown.

    - (void)viewDidLoad {
        self.navigationItem.titleView = [self titleView];
    }
    
    - (UIView *)titleView {
        CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
        CGFloat width = 0.95 * self.view.frame.size.width;
        UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, navBarHeight)];
    ..
    // please add what you need here
    ....
    }
    

提交回复
热议问题