ios - 如何更改 objective-c 中的字体样式和颜色或操作表?

标签 ios objective-c uiactionsheet uialertcontroller

我有一个操作表“selectedActionSheet”。我使用 actionsheet

创建了一个 alertcontroller
UIAlertController *alertController = [selectedActionSheet valueForKey:@"_alertController"];    

现在,我按如下方式更改色调颜色:

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];
}    

这会改变色调的颜色,但是当我单击操作表时,我再次看到默认的蓝色。有人可以帮我解决这个问题吗?我是 Objective c 的新手。

最佳答案

只需在 presentViewController 之后设置 alertController tintColor

[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,那么请尝试下面的代码-

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 看起来像这样-

enter image description here

关于ios - 如何更改 objective-c 中的字体样式和颜色或操作表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38320039/

相关文章:

ios - 太多样板代码 switch 语句 - iOS

iphone - 从 iPad 应用程序打开 iBooks

ios - 将数据传递给 UICollectionReusableView

ios - -[SHKActionSheet _presentSheetFromView :above:] 中断言失败

ios - 如何在 iMessage iOS 11(或 iOS10、Macos Sierra)中禁用 URL 链接预览

ios - 在展开可选内容时,将 Parse PFUser 信息快速加载到 View 中失败,并发现 nil

ios - Objective-C sqlite3数据库更改不持久

ios - 如何像 Apple 一样创建带有水平 slider 的 UIAlertController 样式 ActionSheet? (图像)

ios - 在 UIActionSheet 中使用 UIPickerView 是否可以接受?

ios - 证书尚未生效