使用活动指示器和标签显示警报(可更改)

时间:2013-03-26 10:05:47

标签: iphone ios objective-c

  

我制作一个游戏,开始显示活动指示器和活动指示器底部   显示带文字的UiLable: - 准备 2秒后的文字是: - 设置和之后   2段文字是: - 开始

     

现在我使用3种不同的警报来显示它。

     

我只能使用一个提醒吗

3 个答案:

答案 0 :(得分:0)

UIAlertView *processview;
UILabel *lbl;
NSTimer *enableTimer;
int count;

- (void)enableTimerFired:(NSTimer *)timer
{
    switch (count)
    {
        case 1:
            [lbl setText:@"Ready"];
        break;

        case 2:
            [lbl setText:@"Set"];
        break;

        case 3:
            [lbl setText:@"Go"];
        break;

        case 4:
            [enableTimer invalidate];
            enableTimer = nil;
            [processview dismissWithClickedButtonIndex:-1 animated:YES];
        break;

        default:
        break;

    }
    count++;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    processview =  [[UIAlertView alloc] initWithTitle:@"\n" message:@"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ;

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 90, 30)];
    [lbl setText:@"Ready"];
    [lbl setBackgroundColor:[UIColor clearColor]];
    [lbl setTextColor:[UIColor whiteColor]];
    [lbl setTextAlignment:NSTextAlignmentCenter];
    [processview addSubview:lbl];

    UIActivityIndicatorView *largeActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [largeActivity setFrame:CGRectMake(120, 75, 50, 50)];
    [largeActivity startAnimating];

    [processview addSubview:largeActivity];
    [processview show];

    enableTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(enableTimerFired:) userInfo:nil repeats:YES] retain];
    count = 1;
}

答案 1 :(得分:0)

我认为您需要此类警报enter image description here

这样做试试这个

IN .h文件

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    IBOutlet UILabel *Lable;
    NSTimer *Timer1;
    NSTimer *Timer2;
    UIActivityIndicatorView *Process;
    UIAlertView *Game;
}
-(IBAction)start:(id)sender;

@end

IN .M文件

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
int i;

- (void)viewDidLoad
{
    [super viewDidLoad];
}
-(IBAction)start:(id)sender
{
    i=0;
    Game=[[UIAlertView alloc]initWithTitle:@"Please Wait" message:@"\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    Process=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    Process.frame=CGRectMake(129, 50, 30, 27);
    [Process startAnimating];


    Lable=[[UILabel alloc]initWithFrame:CGRectMake(102, 80, 80, 30)];
    Lable.text=@"Ready";
    Lable.backgroundColor=[UIColor clearColor];
    Lable.textColor=[UIColor whiteColor];
    Lable.textAlignment= UITextAlignmentCenter;
    [Game addSubview:Lable];
    [Game addSubview:Process];
    [Game show];
    Timer1 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(Change) userInfo:nil repeats:NO];
}
-(void)Change{
    Timer2 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(Change) userInfo:nil repeats:NO];
    if (i==0)
        Lable.text=@"Set";
    else
        Lable.text=@"Go";

    i++;
    if (i==3) {
        [Timer2 invalidate];
        Timer2=nil; 
        [Process stopAnimating];
        [Game dismissWithClickedButtonIndex:0 animated:YES];

    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

答案 2 :(得分:0)

下载SVProgressHUD。这将在2-3行代码中为您处理。它工作得很好(它可能没有可更改的消息。如果是这样,请尝试下面的MBProgressHUD)

https://github.com/samvermette/SVProgressHUD

还有MBprogressHUD可以让你在一个过程中途改变消息,但我发现它会在应用程序中引起一些小问题。

https://github.com/jdg/MBProgressHUD