Compose UIBarButtonItem changes position slightly when coming into view

后端 未结 7 2064
星月不相逢
星月不相逢 2021-02-13 15:21

When presenting a new view with a UIBarButtonSystemItemCompose button in the navigation bar, the position is slightly off and adjusts after the view has come into view.

7条回答
  •  终归单人心
    2021-02-13 16:07

    I think this is problem of UIBarButtonSystemItemCompose. need some correction from apple developer team. Untill apple don't get resolve this bug. you can create your custom button and set it to rightBarButtonItem using following code.

    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"compose.png"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
        [button setFrame:CGRectMake(0, 0, 53, 31)];
    
        UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
        self.navigationItem.rightBarButtonItem = barButton;
    
    -(void)buttonAction:(id)sender{
        NSLog(@"Click");
    }
    

    Hope this help you.

提交回复
热议问题