ios - actionSheet的subviews一直为空 为什么
大家讲道理
大家讲道理 2017-04-17 15:36:27
0
1
663
  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个按钮

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!