I've created UIAlertView
with multiple buttons with the following code:
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
alert.tag = TAG_ALERT0;
alert.title = @"Notes";
alert.delegate = self;
[alert addButtonWithTitle:@"Add Note"];
[alert addButtonWithTitle:@"Show Notes"];
[alert addButtonWithTitle:@"Cancel"];
[alert show];
I'm wondering if it is possible to add a different background color to each button?
Yes, you can but should not modify the look of UIAlertView
since Apple hates that shit.
Instead, create your own UIView
that mimics the alertView
.
Also... does the initWithFrame
method even make a difference?
Example... Try:
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
It won't make a difference.
So... I'd suggest:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notes"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Add Note",@"Show Notes",nil];
[alert setTag:TAG_ALERT0];
[alert show];
But since you asked for sample code, the following example will be simple and to the point:
Example:
-(void)willPresentAlertView:(UIAlertView *)alertView
{
UILabel *theTitle = [alertView valueForKey:@"_titleLabel"];
[theTitle setTextColor:[UIColor orangeColor]];
NSMutableArray *arrButtons = [alertView valueForKey:@"_buttons"];
for (UIView *vwCurrent in arrButtons) {
[vwCurrent setBackgroundColor:[UIColor redColor]];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.