Can I change the position of navigationbar item?

前端 未结 7 899
无人共我
无人共我 2021-01-31 18:57

Here is the snapshot: \"enter

And the code is here:

UIButton *leftButton =         


        
7条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 19:45

    You can use this code,I think this will be helpful to you. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0,0,50,32); [button setBackgroundImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];

    [button addTarget:self action:@selector(BackBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 32)];
    backButtonView.bounds = CGRectOffset(backButtonView.bounds, -1, -4);
    [backButtonView addSubview:button];
    
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
    //barButtonItem.imageInsets = UIEdgeInsetsMake(-6, 20, 30, 0);
    
    [self.navigationItem setLeftBarButtonItem:barButtonItem];
    

提交回复
热议问题