navigation bar right bar button items spacing

前端 未结 10 2280
执念已碎
执念已碎 2021-01-31 16:47

I have created a with left bar button item added from storyboard, titleView and three right bar button items from code.

Here is the code:

override func         


        
10条回答
  •  情书的邮戳
    2021-01-31 17:32

    This solution is in Objective C

    UIImage *settingImageName = [UIImage imageNamed:@"Menu_Burger_Icon"];
    UIButton * settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [settingButton setImage:settingImageName forState:UIControlStateNormal];
    [settingButton addTarget:self action:@selector(settingsBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    settingButton.frame = CGRectMake(0, 0, 30, 30);
    
    UIBarButtonItem *settingBarButton = [[UIBarButtonItem alloc] initWithCustomView:settingButton];
    
    UIImage *notificationImageName = [UIImage imageNamed:@"NotificationON"];
    UIButton * notificationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [notificationButton setImage:notificationImageName forState:UIControlStateNormal];
    [notificationButton addTarget:self action:@selector(notificationButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    notificationButton.frame = CGRectMake(0, 0, 30, 30);
    UIBarButtonItem *notificationBarButton = [[UIBarButtonItem alloc] initWithCustomView:notificationButton];
    
    self.navigationItem.rightBarButtonItems  = @[settingBarButton,notificationBarButton];
    

    Solution reference by @mikle94. His answer is in Swift.

提交回复
热议问题