2010-12-13 5 views
0

Je dois personnaliser la couleur d'arrière-plan de l'UIAlertView.iphone UIAlertView - couleur d'arrière-plan personnalisée

J'ai un exemple de code qui fonctionne parfaitement sur iphone 3.x, mais sur l'iphone 4, alertview affiche la couleur bleue par défaut.

UIAlertView *alertView = 
[[[UIAlertView alloc] initWithTitle:@"Alerta" 
     message:msg 
      delegate:nil 
     cancelButtonTitle:@"OK" 
     otherButtonTitles:nil] autorelease]; 

[alertView show]; 

UILabel *theTitle = [alertView valueForKey:@"_titleLabel"]; 
[theTitle setTextColor:[UIColor redColor]]; 

UILabel *theBody = [alertView valueForKey:@"_bodyTextLabel"]; 
[theBody setTextColor:[UIColor whiteColor]]; 

UIImage *theImage = [UIImage imageNamed:@"Background.png"]; 
theImage = [theImage stretchableImageWithLeftCapWidth:0 topCapHeight:0]; 
CGSize theSize = [alertView frame].size; 

UIGraphicsBeginImageContext(theSize); 
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)]; 
theImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

[[alertView layer] setContents:(id)theImage.CGImage]; 
[alertView show]; 

Répondre

1

Bien qu'il soit le plus probable possible, il est recommandé de ne pas modifier ce type de choses, comme une simple mise à jour pourrait casser. Au lieu de cela, essayez de faire votre propre vue d'alerte comme démontré assez bien par Nathan S .:

How can I customize an iOS alert view?

Questions connexes