1

当我按下一个按钮时,我必须显示一个带有活动指示器的白色 uialertview 5 秒钟?我看到了一些代码,然后我选择了以下代码,够了吗?如何更改活动指示器的颜色

 myAlertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:@"\n\n"
                                        delegate:self
                               cancelButtonTitle:@""
                               otherButtonTitles:@"OK", nil];  

UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc]
                initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];   
loading.frame=CGRectMake(150, 150, 16, 16);
[myAlertView addSubview:loading];

我想要这张图片中带有 uiactivity 指示器的东西

在此处输入图像描述

4

3 回答 3

1

您可以创建一个自定义警报,如下所示(PS:我在工作 3 小时后开发了这个自定义警报,它与兼容)iPhone4iPhone5iPad

-(void)showAlert{


alertViewView = [[UIView alloc]initWithFrame:self.window.frame];

UIImageView *alertBackground = [[UIImageView alloc]initWithFrame:CGRectMake(-200, -200, self.window.frame.size.width*2, self.window.frame.size.height*2)];
//   alertBackground.image = [UIImage imageNamed:@"alertBackGround.png"];
[alertViewView addSubview:alertBackground];

alertBackground.backgroundColor = [UIColor blackColor];
alertBackground.alpha = 0.5;
UIImageView *alertImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2, self.window.frame.size.height/2-179/2, 310, 248)];
alertImage.image = [UIImage imageNamed:@"rommanAlertBig.png"];
[alertViewView addSubview:alertImage];[alertBackground release];[alertImage release];


        UIButton *lButton = [UIButton buttonWithType:UIButtonTypeCustom];
        lButton.frame = CGRectMake(self.view.frame.size.width/2-150+40-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
         [lButton setTitle:@"Cancel" forState:UIControlStateNormal];
        [lButton addTarget:self action:@selector(removeAlert) forControlEvents:UIControlEventTouchUpInside];
        [alertViewView addSubview:lButton];


        UIButton *rButton = [UIButton buttonWithType:UIButtonTypeCustom];
        rButton.frame = CGRectMake(self.view.frame.size.width/2-150+170-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
         [rButton setTitle:@"OK" forState:UIControlStateNormal];
        [rButton addTarget:self action:@selector(yesAction) forControlEvents:UIControlEventTouchUpInside];
        [alertViewView addSubview:rButton];





UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2+30, self.window.frame.size.height/2-179/2+75, 260, 40+69)];
lbl.text = @"Description";
lbl.textColor = [UIColor whiteColor];
lbl.textAlignment  =UITextAlignmentCenter;
lbl.numberOfLines = 0;
lbl.font = [UIFont systemFontOfSize:17.0];
lbl.backgroundColor = [UIColor clearColor];
[alertViewView addSubview:lbl];[lbl release];

[self.window addSubview:alertViewView];
alertViewView.alpha = 0;
[UIView animateWithDuration:0.1 animations:^{alertViewView.alpha = 1.0;}];

alertViewView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1.0);

CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
bounceAnimation.values = [NSArray arrayWithObjects:
                          [NSNumber numberWithFloat:0.5],
                          [NSNumber numberWithFloat:1.1],
                          [NSNumber numberWithFloat:0.8],
                          [NSNumber numberWithFloat:1.0], nil];
bounceAnimation.duration = 0.3;
bounceAnimation.removedOnCompletion = NO;
[alertViewView.layer addAnimation:bounceAnimation forKey:@"bounce"];

alertViewView.layer.transform = CATransform3DIdentity;


}


-(void)removeAlert{
for (UIView *v in [alertViewView subviews]) {
    [v removeFromSuperview];
}
[alertViewView removeFromSuperview];
[alertViewView release];


}

-(void)yesAction

{ [self removeAlert];
// Your Code here

}
于 2013-05-21T12:45:10.357 回答
0

更改活动指示器的颜色

在 iOS 5.0 及更高版本中,您可以使用setColor:UIActivityIndi​​catorView 设置自定义颜色。

制作自定义警报视图

在drawrect中创建一个子类在视图部分的顶部绘制白色

于 2013-05-21T12:39:06.887 回答
0

为什么不使用您拍摄照片的班级?https://github.com/m1entus/WCAlertView

对于 ActivityIndi​​cator,您只需用 IB 拖出一个并更改其颜色。然后做类似的事情:

[activityindicator startanimating];

//put alert code here

// choose when you want to stop the animation:
//[activityindicator stopanimating];
于 2013-05-21T12:49:44.007 回答