2012-03-16 31 views
0

我有一个iphone应用程序,我使用波纹管代码自定义我的alertview。它在模拟器中工作正常。但是当我将它添加到我的iphone时,它显示的是同一个蓝色的。不是我定制的视图。是否有人可以帮助我?定制的UIAlertview不显示在iphone中?

UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"title" message:@"canceled" 
                 delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
//[alert setUIColor:[UIColor brownColor]]; 
/*[alert show]; 
[alert release];*/ 

//UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"canceled" 
                 //delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 

[theAlert show]; 

UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"]; 
[theTitle setTextColor:[UIColor whiteColor]]; 

UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"]; 
[theBody setTextColor:[UIColor whiteColor]]; 
theBody.font = [UIFont boldSystemFontOfSize:16.0]; 
UIImage *theImage = [UIImage imageNamed:@"pop_up.png"];  
theImage = [theImage stretchableImageWithLeftCapWidth:28 topCapHeight:28]; 
CGSize theSize = [theAlert frame].size; 

UIGraphicsBeginImageContext(theSize);  
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];  
theImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext(); 

//[[theAlert layer] setContents:[theImage CGImage]]; 
[[theAlert layer] setContents:(id)[theImage CGImage]]; 
[theAlert release]; 

回答

0

以下是针对同一主题的旧对话,可以帮助您。 Can I customise the UIAlertView [iPhone iOs 4]?

我建议您不要自定义它,因为在期货发行版中,您可能会遇到兼容性问题。 如果您强烈需要使用另一个AlertView创建一个新的AlertView,如果不是,为什么不使用本机效果很好的。万一,它不能正常工作,不要担心他们将在下一个版本。