Question

[Button1 setFrame:CGRectMake(0, 0, 50, 0)];
[Button2 setFrame:CGRectMake(0, 0, 120, 0)];
[Button3 setFrame:CGRectMake(0, 0, 50, 0)];


self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button1];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button2];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Button3];

I want to add button in the NavigationBar. NavigationBar have 3 buttons.

Navigation Composition like this.

button 1  button 2          text          button3

But I didn't show that. this like.

          button 2          text          button3

Button1, Button2 and Button3 are an Image.

I thought that Button1 setFrame didn't work.

I think setFrame:CGRectMake(0,0,50,0) works Button1 and setFrame:CGRectMake(0,0,120,0) works Button2. so, Button1 is erased by Button2 setFrame.

How to work this Button1 setFrame ?

Please help me.

Was it helpful?

Solution

It has nothing to do with the setFrame: calls. You cannot assign two buttons to leftBarButtonItem. The second assignment overwrites the first. You should create a blank view, add the two buttons to this view (setting their frames correctly so that they are located side by side), and then create a bar button item with this container view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top