gpt4 book ai didi

ios - 如何禁用通过UIAlertViewController添加的操作表上的按钮操作-(iOS 9/10)

转载 作者:行者123 更新时间:2023-12-01 17:28:54 25 4
gpt4 key购买 nike

我制作了一个这样的ActionSheet:

enter image description here

现在,我想更改颜色CancelDelete,以使其具有disabled的感觉。

我可以更改所有按钮的颜色,但不能更改单个按钮的颜色。

我尝试使用类别,但是我一直在获取wariningActionSheetDepreciated。而且代码也不起作用。

我写了这段代码:

      - (void)setButton:(NSInteger)buttonIndex toState:(BOOL)enabled {
for (UIView* view in self.subviews)
{
if ([view isKindOfClass:[UIButton class]])
{
if (buttonIndex == 0) {
if ([view respondsToSelector:@selector(setEnabled:)])
{
UIButton* button = (UIButton*)view;
button.enabled = enabled;
}
}
buttonIndex--;
}
}
}

是否有可能使通过 Action sheet呈现的 AlertViewController的某些按钮显示为禁用状态。

以下是我提供操作表的代码:
 UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Action Sheet" message:@"Using the alert controller" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet.view setTintColor:[UIColor redColor]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

// Cancel button tappped.


[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

// Distructive button tapped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Group 1" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

// Distructive button tapped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

// OK button tapped.

[self dismissViewControllerAnimated:YES completion:^{
}];
}]];


// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];

最佳答案

您可以做的是使用setEnabledUIAlertAction属性。

这将使您的按钮显示为“灰色”。

我已经修改了一部分代码以合并此更改:

UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// OK button tapped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}];

[action setEnabled:NO];
[actionSheet addAction:action];

当然,禁用后,您 无法单击按钮。

其他选项将涉及使用 UIAlertActionStyle
有三种:
UIAlertActionStyleDefault,
UIAlertActionStyleCancel,
UIAlertActionStyleDestructive
UIAlertActionStyleDefault将使用 tintColor呈现您的按钮。
UIAlertActionStyleCancel将在页面底部呈现您的按钮。
UIAlertActionStyleDestructive用“红色”颜色呈现按钮。 (认为​​:“删除”按钮)

关于ios - 如何禁用通过UIAlertViewController添加的操作表上的按钮操作-(iOS 9/10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41675500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com