Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding UIToolbar with two UIBarButtonItem to a UINavigationBar: poor UIToolbar and what about iPhone 4
    primarykey
    data
    text
    <p>I'm following the second tip from <a href="http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html" rel="noreferrer">here</a>. In this tip two UIBarButtonItems are put together in a UIToolbar. Finally, the UIToolbar is added to the UINavigationBar. Now to my problems:</p> <p>1) A white line is on top of the UIToolbar. If I increase the size of the UIToolbar, the gradient is wrong. I'm using the following size for the UIToolbar:</p> <pre><code> UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)]; </code></pre> <p>How can I get rid of the white line? See here: <img src="https://i.stack.imgur.com/xTkS4.png" alt="alt text"></p> <p>The problem is that there is a white instead of a grey line. If it would be grey, everything would be perfect.</p> <p>2) What about the difference of the display size of iPhone 3 and iPhone 4? Do I have to check which iPhone is used and then double the size?</p> <p><strong>Edit:</strong></p> <p>The buttons are created like in the following example I took from the above mentioned website:</p> <pre><code>// create a toolbar to have two buttons in the right UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)]; // create the array to hold the buttons, which then gets added to the toolbar NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3]; // create a standard "add" button UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL]; bi.style = UIBarButtonItemStyleBordered; [buttons addObject:bi]; [bi release]; // create a spacer bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; [buttons addObject:bi]; [bi release]; // create a standard "refresh" button bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)]; bi.style = UIBarButtonItemStyleBordered; [buttons addObject:bi]; [bi release]; // stick the buttons in the toolbar [tools setItems:buttons animated:NO]; [buttons release]; // and put the toolbar in the nav bar self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; [tools release]; </code></pre> <p>@ tc.:</p> <p>I tried to subclass <code>UIToolbar</code>.</p> <pre><code>// MyToolbar.h #import &lt;Foundation/Foundation.h&gt; @interface MyToolbar : UIToolbar { } @end // MyToolbar.m #import "MyToolbar.h" @implementation MyToolbar - (void)drawRect:(CGRect)rect { // do nothing } - (id)initWithFrame:(CGRect)aRect { if ((self = [super initWithFrame:aRect])) { self.opaque = NO; self.backgroundColor = [UIColor clearColor]; self.clearsContextBeforeDrawing = YES; } return self; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload