Podążam za drugą wskazówką od here. W tej końcówce dwa elementy UIBarButtonItems są umieszczane na pasku UIToolbar. Ostatecznie pasek UIToolbar jest dodawany do paska UINavigationBar. Teraz do moich problemów:Dodawanie paska UIToolbar z dwoma elementami UIBarButtonItem do paska UINavigationBar: słaby pasek UIToolbar, a co z iPhone 4
1) Biała linia jest na szczycie paska UIToolbar. Jeśli zwiększę rozmiar paska UIToolbar, gradient jest nieprawidłowy. Dla paska UITool używam następującego rozmiaru:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)];
Jak mogę pozbyć się białej linii? Zobacz tutaj:
Problem polega na tym, że zamiast szarej linii jest biały. Gdyby było szaro, wszystko byłoby idealnie.
2) A co z różnicą w rozmiarze wyświetlacza iPhone 3 i iPhone 4? Czy muszę sprawdzić, który iPhone jest używany, a następnie podwoić rozmiar?
Edit:
Przyciski są tworzone tak jak w poniższym przykładzie wziąłem od wyżej wymienionej stronie internetowej:
// 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 .:
Próbowałem podklasy 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
Próbowałem podklasy 'UIToolbar'. Teraz mam czarne tło dla mojego paska narzędzi. Jakie funkcje muszę zaimplementować, aby uzyskać ten sam gradient/styl z 'UINavigationBar'. – testing
Hmmm. Spróbuj dodatkowo ustawić 'self.opaque = NO',' self.backgroundColor = [UIColor clearColor] 'i' self.clearsContextBeforeDrawing = YES' w 'initWithFrame:' lub 'initWithCoder:' odpowiednio. –
Teraz nadpisałem 'initWithFrame:' (zobacz moje edytowane pytanie). To wydaje się działać na pierwszy rzut oka. Nigdy wcześniej nie subklasowałem elementu interfejsu użytkownika. Czy muszę być świadomy czegoś (rzeczy, które nie działają lub coś w tym stylu)? – testing