Estoy siguiendo el segundo consejo desde here. En este consejo, dos UIBarButtonItems se agrupan en una UIToolbar. Finalmente, la UIToolbar se agrega a UINavigationBar. Ahora a mis problemas:Agregar UIToolbar con dos UIBarButtonItem a un UINavigationBar: pobre UIToolbar y qué pasa con el iPhone 4
1) Una línea blanca está en la parte superior de la barra de UIToolbar. Si aumento el tamaño de la barra de gravedad de UIT, el gradiente es incorrecto. Estoy utilizando el siguiente tamaño para la UIToolbar:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 44.01)];
¿Cómo puedo deshacerme de la línea blanca? Vea aquí:
El problema es que hay una línea blanca en lugar de gris. Si fuera gris, todo sería perfecto.
2) ¿Qué hay de la diferencia del tamaño de pantalla de iPhone 3 y iPhone 4? ¿Tengo que verificar qué iPhone se usa y luego doblar el tamaño?
Editar:
Los botones se crean como en el siguiente ejemplo que hice desde el sitio web mencionado anteriormente:
// 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 .:
me trataron de una subclase 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
Intenté subclasificar 'UIToolbar'. Ahora tengo un fondo negro para mi barra de herramientas. Qué funciones tengo que implementar para obtener el mismo degradado/estilo de 'UINavigationBar'. – testing
Hmmm. Intente configurar adicionalmente 'self.opaque = NO',' self.backgroundColor = [UIColor clearColor] ', y' self.clearsContextBeforeDrawing = YES' en 'initWithFrame:' o 'initWithCoder:' según corresponda. –
Ahora he reemplazado 'initWithFrame:' (vea mi pregunta editada). Esto parece funcionar a primera vista. Nunca subclasicé un elemento UI antes. ¿Tengo que estar consciente de algo (cosas que no funcionan o algo como esto)? – testing