I add two custom buttons on the navigation bar. one on the left and the other on the right. I successfully dealt with this,
but I was not able to reduce the space between the starting point and the frame of the buttons.
I tried a lot, also gave a negative value of x, still did not help. Here is the code for the buttons
-(void)addLeftButton { UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]; aButton.backgroundColor = [UIColor redColor]; [aButton setTitle:@"H" forState:UIControlStateNormal]; aButton.frame = CGRectMake(0.0, 0.0, 40, 40); [aButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton]; [aButton addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.navigationItem setLeftBarButtonItem:aBarButtonItem]; } -(void)addRightButton { UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]; aButton.backgroundColor = [UIColor greenColor]; [aButton setTitle:@"B" forState:UIControlStateNormal]; aButton.frame = CGRectMake(0.0, 0.0, 40, 40); [aButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton]; [aButton addTarget:self action:@selector(backBtnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.navigationItem setRightBarButtonItem:aBarButtonItem]; }
Also tried using
aBarButtonItem.width = -16;
but it didn’t help.
How to achieve this ...? Thanks in advance...
Here are some links that I preferred but didn't help much How to edit a blank space on the left, on the right UIBarButtonItem in UINavigationBar [iOS 7]
How to edit blank space on left, right UIBarButtonItem in UINavigationBar [iOS 7]

ios xcode navigationbar
Sagar
source share