UINavigationBar UIBarButtonItems much larger click area than required

后端 未结 8 1475
遇见更好的自我
遇见更好的自我 2020-12-08 09:40

hopefully someone can help me out- iv\'e scoured the net for the answer and cannot find one-

the UIBarButtonItems added to UINavigationBar have a much larger click a

8条回答
  •  半阙折子戏
    2020-12-08 10:31

    This is the only solution I found. Create a container of the custom button:

    //Create a container for the button
    UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 44)];
    
    //Create a smaller button
    UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 55, 25)];
    [closeButton setTitle:@"Cancel" forState:UIControlStateNormal];
    //center the title
    closeButton.titleEdgeInsets = UIEdgeInsetsMake(23, 0, 0, 0);
    
    [buttonContainer addSubview:closeButton];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonContainer];
    

提交回复
热议问题