iPhone development: How to create colored or translucent background for UIActionSheet?

I usually implement the following delegate method:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet

Just to make a sample. In this case I use a stretched png as a background:

- (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];
}

and this is the result:
alt text http://grab.by/4yF1

Leave a Comment