views:

348

answers:

2

Hi, this is the code i have taken form.....

  - (void)willPresentAlertView:(UIAlertView *)alertView
    {
        [[[alertView subviews] objectAtIndex:2] setBackgroundColor:[UIColor colorWithRed:0.5 green:0.0f blue:0.0f alpha:1.0f]];
    }

    - (void) presentSheet
    {
        UIAlertView *baseAlert = [[UIAlertView alloc] 
                initWithTitle:@"Alert" message:@"This alert allows the user to choose between a 'safe' and a 'deadly' choice, indicated by button color.\n\n\n\n" 
                delegate:self cancelButtonTitle:nil
                otherButtonTitles:@"Deadly!", @"Safe", nil];
UITextField *txtFld = [[UITextField alloc] initWithFrame:CGRectMake(60,10,240,31)];
[txtFld setDelegate:self];
[txtFld setBackgroundColor:[UIColor clearColor]];
[baseAlert addSubView:txtFld];
[txtFld release];
        [baseAlert show];
    }

my question is If it is allowed to change the basic Look and feel of the apple's provided UIControls, because I dont see any reason that apple should not allow this type of customisation.

+3  A: 

I don't know if Apple will reject an app for accessing undocumented subviews, but they certainly recommend against it. In fact, when I was at the iPhone tech talk last week a developer evangelist specifically said not to do this because the implementations will change and your app will break.

bpapa
Does adding subviews like adding textfields, buttons etc has also some bothering with apple?
Madhup
That, maybe not. For example, you may be able to get away with adding a UITextField as a subview and then sending the bringSubviewToFront: message. But even in that case, you are going to need to "stretch" the rest of the alert view, so you're still going to be mucking with the internals. In the long run you'll probably be better off making your own view.
bpapa
+5  A: 

Alert views have long been standardized to for the same reason things like fire extinguishers and safety signs are standardized i.e. you don't want people to have to puzzle out a new interface while something is going wrong.

In general, it is a bad idea to change something in the interface that has been highly standardized. What benefit will it bring to the end user? Will they think, "Damn, I lost all my data but the alert that told me that sure did look artistic!" More likely, they won't understand that the dialog is actually an alert but rather part of the apps normal functioning.

Having said all that, there is nothing to stop you from creating your own custom view and presenting it modally. That is a far safer and easier route than mucking about under the hood of the Apple API.

TechZen