views:

706

answers:

2

I am using the code:

  {
        randomstatus=0;
        msg=[[NSString alloc]initWithFormat:@"Good job, do you want to continue?"];
        UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:msg delegate:self cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes" otherButtonTitles:nil];
        [actionSheet showInView:self.view];
        [actionSheet release];
        [msg release];
    }   

I don't want to change the code, but I need the "destructiveButton" to be green instead of red. Is this possible, or do i need to use a different button?

+2  A: 

Unfortunately there aren't any officially provided methods for customizing UIActionSheet buttons.

However you can access the subviews of the UIActionSheet (which could break in a future iPhone OS update), or add a new view with a button that covers the original destructive action button (once again, this may break).

While not directly related to changing the color of a button on a UIActionSheet, this previous question: http://stackoverflow.com/questions/743636/iphone-disabling-uiactionsheet-buttons demonstrates a few ways you could add custom views to a UIActionSheet.

Eric Schweichler
+1  A: 

There is no "standard" way of changing the appearince of the buttons. Any ways you use will essentially be hacks and may break in the future if Apple change the UIActionSheet component. They may also get your app rejected if they upset the App-Store gods.

I think the most future-proof way of acheiving this is to create your own action sheet class from scratch, ie not subclassing UIActionSheet (as this may break in the future). Although this may be a bit more work up-front than some hack, the extra flexibility you'll gain will come in useful in the future.

This shouldn't be too difficult. You'll need a view which is the background for the action sheet, which you can get by taking a screenshot of a standard UIActionSheet and some photoshopping. Then add your custom buttons as sub-views. A bit of animation for bringing up the view and your done.

I would aim to have your class implement all the methods the UIActionSheet does, as well as firing off the methods UIActionSHeetDelegate expects. This way you'll be able to substitue it in anywhere you'd otherwise use a native UIActionSheet

pheelicks