开发者

UIAlertView backgroundImage

How can i set a background image in开发者_开发问答 a UIAlertView progrmatically?


There is no method to set the background image for AlertView. We need to set image as subView for alert View.

Try this way it will work:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message 1......\nMessage 2......" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

UIImageView *Image =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ImageName"]];
[alert addSubview:Image];

[Image release];

[alert show];
[alert release];


 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:@"Empty data not Allowed" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];



   UIImage *alertImage = [UIImage imageNamed:@"custom-dialog-background.png"];

   UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:alertImage];

   backgroundImageView.frame = CGRectMake(0, 0, 282, 130);

   backgroundImageView.contentMode = UIViewContentModeScaleToFill;

   [alert addSubview:backgroundImageView];

   [alert sendSubviewToBack:backgroundImageView];


   [alert show];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜