views:

84

answers:

1

I am trying to change the background of the uialertview. Everything works fine except the background image i am adding to the uialert view won't scale inside the alertview. So basically you see only part of my background image based on the current size. Is there any way to make it so that the image scales inside the alerview until it fits?

UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:title 
                                                    message:msg
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles: nil];
    [theAlert show];

    UIImage *theImage = [UIImage imageNamed:@"bg.jpg"];
    theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
    CGSize theSize = [theAlert frame].size;

    UIGraphicsBeginImageContext(theSize);
    [theImage drawInRect:CGRectMake(0, 0, theAlert.frame.size.width, theAlert.frame.size.height)];
    theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    theAlert.layer.contents = (id)[theImage CGImage];
    [theAlert release];
+4  A: 

Hi, please take a look at: http://joris.kluivers.nl/iphone-dev/?p=CustomAlert

They explain how to do it by subclassing UIAlertView. Good luck!

Karasutengu
thanks a lot great link
aryaxt