UIActionSheet *myActionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles: @"分享",@"删除",@"举报",nil];
[myActionSheet showInView:self.view];
}
-(void)willPresentActionSheet:(UIActionSheet *)actionSheet{
NSLog(@"actionSheet.subviews:%@",actionSheet.subviews);
for (UIView *view in actionSheet.subviews) {
if (view.tag == 2) {
UIButton *button = (UIButton *) view;
//改变背景
[button setBackgroundImage:[button backgroundImageForState:UIControlStateHighlighted] forState:UIControlStateNormal];
//改变颜色
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//btn的选择状态,否则选择后不变背景
[button setSelected:YES];
}
}
}
打印出来`actionSheet.subviews:(
)`
为什么为空啊 明明有3个按钮
UIAlertView used to be able to get the subview, but later it was no longer possible.
The purpose of Apple is to not let developers define these Views.
So, you can definitely get the View inside by calling the subviews method.
For Apple to do this, I guess there are two ways:
1. There is no subview at all, and which buttons use Layer or redraw.
2. Overload the subviews methods of these classes so that they return empty arrays. (This is the most likely)
Apple has restricted the way of customization, so this may be a bit fiddly.
You can try this library, which supports custom View: JGActionSheet