style objective alertas iphone objective-c cocoa-touch uikit uialertview

iphone - objective - uialertcontroller styles



¿Cambiar el color de fondo de un UIAlertView? (12)

Quiero cambiar el color de fondo de mi UIAlertView, pero esto no parece tener un atributo de color.


Agregue el marco QuartzCore a la aplicación e incluya #import "QuartzCore / CALayer.h" en el archivo fuente.



Bueno, he resuelto el problema de una manera diferente. Busqué el UIImageView que contiene la imagen de fondo y cambio la imagen.

... bueno, mostrar no es la mejor solución para alterar la vista ...

@implementation CustomAlertView - (void)show { [super show]; for (UIView *view in self.subviews) { NSLog(@"%@ with %i children", view, [view.subviews count]); // change the background image if ([view isKindOfClass:[UIImageView class]]) { UIImage *theImage = [UIImage imageNamed:@"password entry bg - default.png"]; ((UIImageView *)view).image = [theImage resizableImageWithCapInsets:UIEdgeInsetsMake(49, 8, 8, 8)]; } } } @end


El fondo de AlertView es una imagen Y puedes cambiar esta imagen

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention" message: @"YOUR MESSAGE HERE", nil) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; [theAlert show]; UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"]; [theTitle setTextColor:[UIColor redColor]]; UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"]; [theBody setTextColor:[UIColor blueColor]]; UIImage *theImage = [UIImage imageNamed:@"Background.png"]; theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16]; CGSize theSize = [theAlert frame].size; UIGraphicsBeginImageContext(theSize); [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)]; theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [[theAlert layer] setContents:[theImage CGImage]];



Esto no es algo que es posible.

O necesita crear su propia vista de tipo de alerta (incluida la provisión de la animación, etc.) o usar el UIAlertView predeterminado suministrado por Apple.

Apple tiende a no exponer cosas como el color de UIAlertView para que la interfaz de usuario tenga una sensación común en todas las aplicaciones. Cambiar el color de la aplicación a la aplicación sería confuso para el usuario.


No creo que exista un método o propiedad expuesta para hacer esto. Establecer el backgroundColor de UIAlertView (como UIView) simplemente pone un fondo rectangular de color detrás de la vista de alerta.

Diría que probablemente vaya en contra de la interfaz común del iPhone para alterar este color, así que no creo que sea un comportamiento recomendado (de la misma manera que cambiar el color de fondo de una vista de alerta en Mac OS X no es recomendado).




Simplemente use este código,

UIImage *theImage = [UIImage imageNamed:@"imageName.png"]; UIView *view=[alert valueForKey:@"_backgroundImageView"]; //Set frame according to adustable UIImageView *image=[[UIImageView alloc] initWithImage:theImage]; [image setFrame:CGRectMake(0, 0, 280, 130)]; [view addSubview:image];


También encuentro una solución casi idéntica y, en mi caso, funciona mejor. Usando la salida de oxígeno he descubierto un resultado pobre en la pantalla y el contexto se vuelve borroso. En lugar de crear una subclase de UIAlertView, implemento:

- (void)willPresentAlertView:(UIAlertView *)alertView;

así que ... solo copie y pegue

- (void)willPresentAlertView:(UIAlertView *)alertView { blah blah blah... [[alertView layer] setContents:(id)theImage.CGImage]; // to avoid the warning }


Tienes que usar esto:

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"You are Select Row of" message:@"Human" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; alert.backgroundColor=[UIColor redColor]; [alert show]; [alert release];

cambiará el color de fondo de UIAlertView.