iphone开发学习,UIAlertView的简单改写,popAlertView

改写的AlertView,有弹出效果,点击任意位置关闭View。

效果图:popAlertView-maxfong

- (IBAction)didPressedClick:(id)sender{
    alert = [[UIAlertView alloc] init];
    alert.delegate = self;
    [alert addSubview:aView];
    bView.layer.cornerRadius = 10;
    bView.layer.masksToBounds = YES;
    [bView.layer setShadowOffset:CGSizeMake(2, 1)];
    [bView.layer setShadowRadius:5];
    [bView.layer setShadowOpacity:1];
    [alert show];
    [alert release];
}
- (IBAction)didPressedClosed:(id)sender{
    [alert dismissWithClickedButtonIndex:0 animated:YES];
}
- (void)willPresentAlertView:(UIAlertView *)alertView{
    alertView.frame = CGRectMake(0, 0, 320, 480);
    for (UIView* view in alertView.subviews ) {
        if ([view isKindOfClass:[UIImageView class]]) {
            UIImageView *img = (UIImageView*)view;
            img.backgroundColor = [UIColor clearColor];
            img.image = nil;
        }
    }
}

创建了一个透明图片作为Button的背景图片,不然点击灰色无效(还不知道为啥,知道的请指点下)。

 

Download Code(popAlertView)

posted @ 2012-09-15 22:28  Maxfong  阅读(410)  评论(0编辑  收藏  举报