如何以编程方式在UIAlertView中设置背景图像?
答案 0 :(得分:2)
没有方法为AlertView设置背景图像。我们需要将图像设置为警报视图的子视图。
尝试这种方式它会起作用:
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];
答案 1 :(得分:0)
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];