【发布时间】:2014-12-31 04:38:13
【问题描述】:
在我的 iOS 8 应用程序中,我使用的是 UIActionSheet。我尝试在willPresentActionSheet委托方法中更改按钮标题的颜色,但它没有将按钮识别为其子视图。
我这样构造UIActionSheet:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select an Option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
popup.tag = 2;
[popup addButtonWithTitle:@"Add Tag To Chat"];
[popup addButtonWithTitle:@"Remove Tag From Chat"];
[popup addButtonWithTitle:@"Terminate"];
[popup addButtonWithTitle:@"Cancel"];
[popup showInView:self.view];
代表是:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"%d",[actionSheet.subviews count]);
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}
按钮正在显示,我可以单击并执行操作。但它说 count = 0。为什么?
【问题讨论】:
-
Action sheet 不像在 iOS 7 中那样可定制。尝试任何一种开源替代品,因为您只是在尝试破解您的方式,这可能只会使其在其他操作系统版本中崩溃。跨度>
-
在 iOS 8 下,
UIActionSheet是用新的UIAlertController实现的,它完全不同,不能以任何方式自定义。您需要创建或使用支持您想要的自定义实现。 -
这将对您有所帮助。它对我有用:) stackoverflow.com/questions/24154889/…
标签: ios objective-c uiactionsheet uiactionsheetdelegate