在我的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.为什么?
答案 0 :(得分:1)
尝试这种方式,更改子视图的UIColor
:
UIActionSheet * action = [[UIActionSheet alloc]
initWithTitle:@"Title"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"",nil];
[[[action valueForKey:@"_buttons"] objectAtIndex:0] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
我已经尝试过了。它正在......
答案 1 :(得分:-2)
您尝试检查子视图数量的代理方法: willPresentActionSheet 似乎不合适。
在实际呈现操作表之前调用willPresentActionSheet 。
如果您检查 didlPresentActionSheet 中的子视图数量,那将更合适。
希望这会有所帮助..