【问题标题】:How can i add a stylish white color uialertview with activity indicator如何添加带有活动指示器的时尚白色 uialertview
【发布时间】:2013-05-21 21:09:52
【问题描述】:

当我按下一个按钮时,我必须显示一个带有活动指示器的白色 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 指示器的东西

【问题讨论】:

    标签: ios objective-c uialertview uiactivityindicatorview


    【解决方案1】:

    你可以像follow一样创建自定义提醒(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
    
    }
    

    【讨论】:

      【解决方案2】:

      更改活动指示器的颜色

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

      制作自定义警报视图

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

      【讨论】:

        【解决方案3】:

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

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

        [activityindicator startanimating];
        
        //put alert code here
        
        // choose when you want to stop the animation:
        //[activityindicator stopanimating];
        

        【讨论】:

        • 代码太复杂了,你想自己写吗?这是第一个..大声笑。这一点都不复杂。阅读说明,您只需在项目中添加 2 块代码。
        猜你喜欢
        • 2015-02-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-19
        • 2011-12-18
        • 1970-01-01
        • 2013-10-28
        相关资源
        最近更新 更多