Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

uikit

iphone

When you try deleting a note in iPhone's Notes application, an UIActionSheet pops up. The sheet is translucent (but not black translucent). How is that achieved? Is it possible to make the background of UIActionSheet a certain color?

like image 737
Boon Avatar asked Jul 25 '09 05:07

Boon


3 Answers

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

like image 140
marcio Avatar answered Nov 16 '22 02:11

marcio


You can use the code below:

actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackOpaque;

or

actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
like image 21
raaz Avatar answered Nov 16 '22 01:11

raaz


actionSheetObj.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
like image 20
Kassem Avatar answered Nov 16 '22 00:11

Kassem