Reputation: 3012
I have created 4 BarButtons with Image and when i added to navigation bar. It shows large gap in between the items and how can remove the gap between the image.
Upvotes: 0
Views: 93
Reputation: 5183
Fixed Item would help u to maintain ur gap. Add your images to button.
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = 10.;
UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(0., 0., 44., 44)];
UIBarButtonItem *barButton1 = [[UIBarButtonItem alloc]initWithCustomView: button1];
UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(46., 0., 44., 44)];
UIBarButtonItem *barButton2 = [[UIBarButtonItem alloc]initWithCustomView: button2];
UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(95., 0., 44., 44)];
UIBarButtonItem *barButton3 = [[UIBarButtonItem alloc]initWithCustomView: button3];
NSArray *itemArray = [[NSArray alloc] initWithObjects: barButton1, fixedItem, barButton2, fixedItem, barButton3, nil];
self.navigationItem.rightBarButtonItems = itemArray;
Upvotes: 0
Reputation: 1521
You can achieve this by maintaining image insets like this:-
UIBarButtonItem *demoButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"demo.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(saveStyle)];
demoButton.imageInsets = UIEdgeInsetsMake(0.0, 0.0, 0, -60);
Upvotes: 1