2010-12-01 155 views
1

嗨,大家好我是使用下面的代码给UIAlertView.I自定义颜色使用S.D.K. 3.2.3和颜色正在变成所需的颜色。但今天我更新了我的S.D.K.现在我正在使用4.2.1,并在此S.D.K上运行此代码。它工作。但是当我再次检查AlertView的颜色没有改变,但我提供的图像的颜色,移动到alertview的后方。我不知道为什么会发生这种情况。 是否有任何问题,我不与ios 4.2一起工作。 只是让我知道如何做到这一点在iOS 4.2代码与3.2.3 sdk工作良好。 代码是UIAlertView自定义颜色

UIAlertView *ForgotPassalert= [[UIAlertView alloc]initWithTitle:@"Status" message:@"An Email has sent to your Account Containing User Name and Password " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel",nil]; 

     CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 
-120.0); 
     [ForgotPassalert setTransform: moveUp]; 
     [ForgotPassalert show]; 

    #pragma mark (AlertView Custom Color)  
     UIImage *theImage = [UIImage imageNamed:@"Untitled-1.png"];  
     theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16]; 
     CGSize theSize = [ForgotPassalert frame].size; 
     UIGraphicsBeginImageContext(theSize); 

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

     UIGraphicsEndImageContext(); 
     [[ForgotPassalert layer] setContents:(id)theImage.CGImage]; 

     //[[Passalert layer]setBackgroundColor:[[UIColor colorWithRed:179.0f/255.0f green:21.0f/255.0f blue:17.0f/255.0f alpha:1.0f]CGColor]]; 
     [[ForgotPassalert layer]setCornerRadius:7.3F]; 
     [ForgotPassalert release]; 

回答

0

这背后的唯一可能的原因是,苹果就已经改变了AlertView或其执行的层结构。这就是为什么你无法看到变化的颜色。

这就是为什么建议不要打扰默认控件的外观和感觉(如UIAlertView,UIActionSheet,UIPickerView)的原因,因为苹果公司没有为此提供发布的方法。而你所做的只是现在被打破的解决方法。

你很幸运,你的应用程序不会崩溃,所以不关心警报中没有显示的颜色。

希望你能理解基本user interface guidelines.

感谢,

Madhup

+0

好吧,是的,我也在想同样的。感谢 – Sabby 2010-12-06 04:07:07

0

所以它的意思是有没有其他的方法来改变颜色在我的应用我做了一切与应用相匹配颜色方案是红色和黑色,但只有对话框创建混乱与他们的默认蓝色我正在使用xcode 4.2故事板,我已经对UIActionSheet进行了更改,但无法更改AlertView背景颜色。

+1

然后,您可以使用自定义的alertview和actionsheet,只需google通过,你会发现示例代码....我回答很晚......但可能有帮助一些其他人 – Sabby 2013-07-09 06:38:58