2009-07-25 5 views

Respuesta

24

que suelo poner en práctica el método siguiente delegado:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet 

sólo para hacer una muestra. En este caso utilizo una estirada PNG como fondo:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet { 
    UIImage *theImage = [UIImage imageNamed:@"detail_menu_bg.png"];  
    theImage = [theImage stretchableImageWithLeftCapWidth:32 topCapHeight:32]; 
    CGSize theSize = actionSheet.frame.size; 
    // draw the background image and replace layer content 
    UIGraphicsBeginImageContext(theSize);  
    [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];  
    theImage = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext(); 
    [[actionSheet layer] setContents:(id)theImage.CGImage]; 
} 

y este es el resultado: alt text http://grab.by/4yF1

+2

¿Podría publicar un enlace a esa imagen?Se ve muy bien, gracias y una gran solución para reemplazar la imagen de fondo! – JonasG

+0

esto no me funciona! – Fay007

0

Me parece negro (nota: usando 2.2.1). La única razón por la que hay un color es por el amarillo detrás de él.

Una opción sería utilizar el fondo negro transparente y conocer el tamaño y la velocidad de la hoja de acción. Luego, cree una vista y anímela al mismo tiempo que muestra la hoja de acción, justo debajo de ella, para darle un matiz diferente al color que se encuentra naturalmente detrás de la hoja de acción. Tendría que hacer que la vista de color también sea translúcida para que pueda ver detrás de eso también.

No estoy seguro si puedes, pero también puedes intentar ajustar la opacidad de la hoja de acción también.

+0

Ajuste de la la opacidad de la hoja de acción afecta los botones también. – Boon

+0

Si echas un vistazo a la aplicación de notas, verás que los botones no son 100% opacos. –

1

Definitivamente puede ajustar la opacidad ajustando el valor alfa. Interface Builder le permite editar el valor directamente, pero en código creo que haría:

[[myActionSheet view] setOpaque:NO]; 
[[myActionSheet view] setAlpha:0.5]; 

No estoy seguro de si necesita la llamada setOpaque o no - Creo que se utiliza para ayudar a optimizar el rendimiento, como el iPhone no intentará mostrar nada oculto por la vista opaca.

5

No es demasiado difícil. Usted puede utilizar el siguiente código:

CGSize mySize = myActionSheet.bounds.size; 
CGRect myRect = CGRectMake(0, 0, mySize.width, mySize.height); 
UIImageView *redView = [[[UIImageView alloc] initWithFrame:myRect] autorelease]; 
[redView setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]]; 
[myActionSheet insertSubview:redView atIndex:0]; 

Sólo asegúrese de que presente la UIActionSheet antes de hacer esto o el tamaño suele ser fijado. Eso hace que sea un poco feo, pero se podría hacer algo como:

[myActionSheet showInView:self.view]; 
if (!redAdded) { 
    redAdded = YES; 
    //THE ABOVE CODE GOES HERE 
} 
+0

Si enlaza el tamaño a la vista, no tendría que hacer la parte posterior. También tuvo que reemplazar xey con alto y ancho: CGSize mySize = self.view.bounds.size; CGRect myRect = CGRectMake (0, 0, mySize.height, mySize.width); – StuartM

+0

Usando - (void) willPresentActionSheet: (UIActionSheet *) actionSheet es un gancho mejor en general –

+0

También puede usar una imagen en lugar de un color configurando un UIImage en el UIImageView: [actionBackground setImage: [UIImage imageNamed: @ "captainplanet. png "]]; – ninehundredt

14

Puede usar el siguiente código:

actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackOpaque; 

o

actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackTranslucent; 
+0

Gracias, esto es exactamente lo que estaba buscando – GeneCode

6
actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackTranslucent; 
Cuestiones relacionadas