开发者

Changing color of alert views

How can I change the color of the alert view box from blue to black?

Any one please help!开发者_StackOverflow中文版!


Guessing you want somthing like this:

Black Alert View http://img.skitch.com/20100405-n2ka11en1u63kcpfu6x7et29mc.jpg

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 = [[UIImage 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.


No you can't. You'll have to create a custom view and display it using presentModalViewController

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜