Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-17-2009, 02:17 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 15
minsi is on a distinguished road
Default Change color for UIAlert

Hi,

How do I change the color of the pop up message box using UIAlert?
minsi is offline   Reply With Quote
Old 08-17-2009, 06:28 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 459
NewiPhoneDeveloper is on a distinguished road
Default

Quote:
Originally Posted by minsi View Post
Hi,

How do I change the color of the pop up message box using UIAlert?
I don't think you can do that. You will have to create your own custom "Alert". For example: Do all the needed graphics and then use a UIView to display them when needed.
__________________
Websites:
Friendlydeveloper - Coding Blog
Codingsessions - Live iOS Training

iPhone Apps:
TextPal - Powerful group messaging,
icePhone

Find me on LinkedIn
NewiPhoneDeveloper is offline   Reply With Quote
Old 08-18-2009, 03:14 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 15
minsi is on a distinguished road
Default

Quote:
Originally Posted by NewiPhoneDeveloper View Post
I don't think you can do that. You will have to create your own custom "Alert". For example: Do all the needed graphics and then use a UIView to display them when needed.
Hi,
Thank you for your prompt reply.
What are the needed graphics for creating a custom "Alert"?
Thanks!
minsi is offline   Reply With Quote
Old 08-18-2009, 03:25 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 10
oxigen is on a distinguished road
Default

Background of AlertView is an image And you can change this image

Quote:
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention"
message: @"YOUR MESSAGE HERE", nil)
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];

[theAlert show];

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

UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];

UIImage *theImage = [UIImage imageNamed:@"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;

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

[[theAlert layer] setContents:[theImage CGImage]];
oxigen is offline   Reply With Quote
Old 08-18-2009, 04:04 AM   #5 (permalink)
iPhone Developer
 
kohjingyu's Avatar
 
Join Date: May 2009
Location: Singapore
Posts: 326
kohjingyu is on a distinguished road
Default

Wow cool. I didn't know that. Btw, you can also change the position of the UIAlertView with transform.

EDIT: Is this allowed by Apple?
__________________
Bacteria Bash
Cheese Collect
Jokestar
Follow me on Twitter for news about my apps:
(Website|Twitter)

Last edited by kohjingyu; 08-18-2009 at 04:10 AM.
kohjingyu is offline   Reply With Quote
Old 08-18-2009, 04:33 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 15
minsi is on a distinguished road
Default

Quote:
Originally Posted by oxigen View Post
Background of AlertView is an image And you can change this image
Thank you. It works!
Where is the Background.png image stored?
minsi is offline   Reply With Quote
Old 08-18-2009, 04:40 AM   #7 (permalink)
iPhone Developer
 
Join Date: Jul 2009
Location: Eugene, Oregon
Posts: 97
williamsbm2000 is on a distinguished road
Default

Quote:
Originally Posted by minsi View Post
Thank you. It works!
Where is the Background.png image stored?
It should be stored in the project folder of your app. If you drag the Background.png file into your XCode project, it should allow you to copy it to the project folder while also adding it to your project. Hope this helps...
Brian
williamsbm2000 is offline   Reply With Quote
Old 08-18-2009, 09:07 AM   #8 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
drewag is on a distinguished road
Default

Quote:
Originally Posted by kohjingyu View Post
Wow cool. I didn't know that. Btw, you can also change the position of the UIAlertView with transform.

EDIT: Is this allowed by Apple?
Yes, from my experience it is allowed to move an alert view. Or at least they had no problem when I moved it out of the way of the keyboard which may be a different story :-P, but I don't think they would have a problem with it.
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 08-18-2009, 09:17 AM   #9 (permalink)
iPhone Developer
 
kohjingyu's Avatar
 
Join Date: May 2009
Location: Singapore
Posts: 326
kohjingyu is on a distinguished road
Default

Quote:
Originally Posted by drewag View Post
Yes, from my experience it is allowed to move an alert view. Or at least they had no problem when I moved it out of the way of the keyboard which may be a different story :-P, but I don't think they would have a problem with it.
I meant is changing the color allowed by Apple?
__________________
Bacteria Bash
Cheese Collect
Jokestar
Follow me on Twitter for news about my apps:
(Website|Twitter)
kohjingyu is offline   Reply With Quote
Old 09-05-2009, 07:07 AM   #10 (permalink)
iOS Dev
 
Join Date: Aug 2009
Location: Chandigarh
Posts: 39
Jango is on a distinguished road
Send a message via Skype™ to Jango
Question Warning Message

Hi,

I'm using the similar code to change the color of the UIAlertView.

Just that I'm getting an warning message that goes something like this:

no method definition found for setContents

Messages without a matching signature method will be assumed to return id....

can anyone suggest something...
Jango is offline   Reply With Quote
Old 09-05-2009, 10:16 AM   #11 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
drewag is on a distinguished road
Default

Quote:
Originally Posted by Jango View Post
Hi,

I'm using the similar code to change the color of the UIAlertView.

Just that I'm getting an warning message that goes something like this:

no method definition found for setContents

Messages without a matching signature method will be assumed to return id....

can anyone suggest something...
Please show us the code where you are getting the warning.
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 09-07-2009, 11:02 AM   #12 (permalink)
iOS Dev
 
Join Date: Aug 2009
Location: Chandigarh
Posts: 39
Jango is on a distinguished road
Send a message via Skype™ to Jango
Default code

Quote:
Originally Posted by drewag View Post
Please show us the code where you are getting the warning.
I'm allocating the UIAlertView as per my requirement in the code.

- (void)willPresentAlertViewUIAlertView *)alertView // before animation and showing view
{
UIImage *theImage2 = [UIImage imageNamed:@"box 2.png"];
CGSize theSize = [alertView frame].size;

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

[[alertView layer] setContents:[theImage2 CGImage]];
// Getting a warning message here that says,no '-setContents method found
}

It works fine, just that I'm getting a warning that I dont know about...
Jango is offline   Reply With Quote
Old 12-03-2009, 05:24 PM   #13 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 33
IVSCEO is on a distinguished road
Default

Quote:
Originally Posted by oxigen View Post
Background of AlertView is an image And you can change this image
How do you change the color of the button text?????
IVSCEO is offline   Reply With Quote
Old 12-03-2009, 05:26 PM   #14 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 33
IVSCEO is on a distinguished road
Default

Quote:
Originally Posted by oxigen View Post
Background of AlertView is an image And you can change this image
How do you change the color of the button text?
IVSCEO is offline   Reply With Quote
Old 09-16-2010, 07:35 AM   #15 (permalink)
iPhone dev
 
Join Date: Aug 2010
Location: islamabad, Pakistan
Posts: 2
tenveer is on a distinguished road
Default

FIrst you have to get the array that holds the buttons :

NSMutableArray *buttonArray = [alert valueForKey:@"_buttons"];

Then you call:

[alert show];

After that, and you do have to do it in this order, you call:

[[buttonArray objectAtIndex:0] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

Of course you can change '0' to the index of the button you want to affect and use whichever UIColor you want.
tenveer is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 311
12 members and 299 guests
chiataytuday, coolman, givensur, glenn_sayers, guusleijsten, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0