How can I change the color of the alert view box from blue to black?
Any one please help!!
How can I change the color of the alert view box from blue to black?
Any one please help!!
No you can't. You'll have to create a custom view and display it using presentModalViewController
Guessing you want somthing like this:
To achieve this I just subclassed the alert view so I could add a bit of my own code in.
I created a background image view that I put a black version of the alert box in.
And when drawRect is called I resize the background image view to be the correct height and width.
Its a bit of a hack, but it doesn't violate any of the guidelines apple has laid out (I have an app in the store right now using this).
To get a good background image I just extracted the images from UI kit (google that and you'll find out how) and just made a black version instead of a blue one.
The buttons are actually transparent and pick up what ever colour is under them. So no need to change them.
Hope that helps.
It is indeed possible. And quite easy as well. All in all about 5 lines of code ;-)
Edit: Ask and yee shall receive
@implementation BlackAlertView
- (void) drawRect:(CGRect) rect
{
//Force our background image to be the right size.
_backgroundImageView.frame = rect;
}
- (void) dealloc
{
ReleaseAndNull(_backgroundImageView);
[super dealloc];
}
- (void)show
{
UIImage *alertBoxImage = [[ImageCache imageNamed:@"UIPopupAlertSheetBackground_black.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:40];
_backgroundImageView = [[UIImageView alloc] initWithImage:alertBoxImage];
[self addSubview:_backgroundImageView];
[self sendSubviewToBack:_backgroundImageView];
[super show];
}
@end
Like I said its not purdy, and in reality its a few more then 5 lines. But it gets the job done.
chris.