Custom Color in UIAlertView
Hi everyone I was using the below code to give a custom color to the UIAlertView.I was using S.D.K. 3.2.3 and the color was changing to the desired color.But today I updated my S.D.K. now I am using 4.2.1 and also run this code on this S.D.K. it worked.But when I checked again the color of the AlertView didn't change ,but the color which i provided with image,moved to the backward of the alertview.I don't know why this happening. Is there anything wrong that i doesn't work with ios 4.2. Just let me know how to do this in ios 4.2 the code was working good with 3.2.3 sdk. The code is
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开发者_如何学JAVA)];
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];
The only possible reason behind this is, Apple would have changed the layer structure of the AlertView or its implementation. That's why u are not able to see the changed color.
This is the reason why it is suggested not to disturb the look and feel of default controls (like UIAlertView, UIActionSheet, UIPickerView) as apple does not provide published methods for this. And whatever you have done is only the workaround which is now broken.
You are lucky enough that your app is not crashing so dont care about the color not showing on the alert.
Hope you understand the basic user interface guidelines.
Thanks,
Madhup
So does it mean there is no other way to change the color as in my app i have made everything matched with the app color scheme that is red and black but only dialogs are creating mess with their default blue color i am using xcode 4.2 with storyboard, i've made changes to UIActionSheet but unable to change AlertView background color.
精彩评论