2010-12-01 157 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