Hinzufügen UIToolbar mit zwei UIBarButtonItem eine UINavigationBar: schlechte UIToolbar und was ist mit iPhone 4

Ich bin nach dem zweiten Tipp von hier. In diesem Tipp zwei UIBarButtonItems sind zusammen in einer UIToolbar. Endlich, die UIToolbar ist Hinzugefügt, um die UINavigationBar. Nun zu meinen Problemen:

1) Eine weiße Linie auf der Oberseite des UIToolbar. Wenn ich erhöhen Sie die Größe der UIToolbar, der Farbverlauf ist falsch. Ich bin mit der folgenden Größe für die UIToolbar:

    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)];

Wie kann ich loswerden der weißen Linie? Siehe hier:
Hinzufügen UIToolbar mit zwei UIBarButtonItem eine UINavigationBar: schlechte UIToolbar und was ist mit iPhone 4

Das problem ist, dass es einen weißen statt einem grauen Linie. Wäre es Grau, alles wäre perfekt.

2) Was ist der Unterschied der display-Größe von iPhone 3 und iPhone 4? Muss ich prüfen, welche das iPhone verwendet und dann doppelt so groß?

Edit:

Den Schaltflächen erstellt werden, wie im folgenden Beispiel, ich nahm aus der oben genannten Webseite:

//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];

@ tc.:

Ich versuchte Unterklasse UIToolbar.

//MyToolbar.h

#import <Foundation/Foundation.h>


@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
InformationsquelleAutor testing | 2010-09-24
Schreibe einen Kommentar