Reputation: 19
I have a action sheet 'selectedActionSheet'. I created a alertcontroller
with actionsheet
UIAlertController *alertController = [selectedActionSheet valueForKey:@"_alertController"];
Now, I change the tint color as follows:
if ([alertController isKindOfClass:[UIAlertController class]])
{
alertController.view.tintColor = [UIColor colorWithRed:0.0/255.0 green:99.0/255.0 blue:65.0/255.0 alpha:1.0];
}
This changes the color of the tint but when I click on the action sheet, Again i see the default blue color. Can somebody help me resolving this? I am new to Objective c.
Upvotes: 0
Views: 3565
Reputation: 757
Try this code
UIActionSheet
actually uses UIAlertController
in iOS 8, and it has a private property _alertController
.
SEL selector = NSSelectorFromString(@"_alertController");
if ([actionSheet respondsToSelector:selector])
{
UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];
if ([alertController isKindOfClass:[UIAlertController class]])
{
alertController.view.tintColor = [UIColor blueColor];
}
}
To change all buttons colour
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];
Thanks
Upvotes: 0
Reputation: 2423
For font to set to alert view controller below is code...
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Your Alert Title" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Your alert description..."];
[hogan addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:50.0]
range:NSMakeRange(24, 11)];
[alertVC setValue:hogan forKey:@"attributedTitle"];
For UIAlertController tint color...
alertVC.view.tintColor = [UIColor colorWithRed:1.0/255.0 green:99.0/255.0 blue:265.0/255.0 alpha:1.0];
Upvotes: 0
Reputation: 1778
Just set the alertController
tintColor
after the presentViewController
i.e.
[self presentViewController:alertController animated:YES completion:nil];
alertController.view.tintColor = [UIColor colorWithRed:0.0/255.0 green:99.0/255.0 blue:65.0/255.0 alpha:1.0];
this will change default as well as highlighted color. Hope this will solved your problem.
If you simply want to present actionSheet, then please try below code-
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Hello Dear" message:@"I'm an actionSheet!" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
//add code to make something happen once tapped
}];
[alertController addAction: ok];
UIAlertAction *Cancel = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action){
//add code to make something happen once tapped
}];
[alertController addAction: Cancel];
[self presentViewController:alertController animated:YES completion:nil];
alertController.view.tintColor = [UIColor colorWithRed:0.0/255.0 green:99.0/255.0 blue:65.0/255.0 alpha:1.0];
actionSheet will look like this-
Upvotes: 1