在我的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。为什么?
发布于 2014-12-31 14:52:23
尝试这种方式,更改子视图的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];我试过了。它正在工作..。
发布于 2014-12-31 14:42:16
尝试检查子视图数的委托方法:willPresentActionSheet似乎不合适。
在实际呈现操作表之前,将调用willPresentActionSheet。
如果你在didlPresentActionSheet,中检查子视图的数量,这会更合适。
希望这能帮上忙..
https://stackoverflow.com/questions/27716189
复制相似问题