Я следую второму совету от здесь . В этом совете два UIBarButtonItem объединяются в UIToolbar. Наконец, UIToolbar добавляется к UINavigationBar. Теперь к моим проблемам:
1) Белая линия находится поверх UIToolbar. Если я увеличу размер UIToolbar, градиент будет неправильным. Я использую следующий размер для UIToolbar:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)];
Как избавиться от белой линии? Посмотреть здесь:
Проблема в том, что вместо серой линии идет белая линия. Если бы он был серым, все было бы идеально.
2) А как насчет разницы в размере дисплея iPhone 3 и iPhone 4? Нужно ли мне проверять, какой iPhone используется, а затем увеличивать его вдвое?
Редактировать:
Кнопки создаются, как в следующем примере, который я взял с вышеупомянутого веб-сайта:
// 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.:
Я попытался создать подкласс UIToolbar
.
// MyToolbar.h
#import
@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