2011-04-26 185 views

回答

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]; 
+0

的有关消息1 .... \ n和消息2 .... \ n如果我想显示消息1和?来自2个变量的消息2? – 2011-04-26 06:42:33

+0

对不起,我不明白你在说什么? :( – Anand 2011-04-26 08:53:49

+0

noproblem ..我做了一个方法...我想显示每条消息在不同line.just“\ n”为我工作......感谢您的帮助 – 2011-04-26 16:21:35

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];