iphone - 使用事件指示器和标签显示警报(可变)

标签 iphone ios objective-c

i make a game that start display Activity indicator And activity indicator bottom display UiLable with text is :-Ready after 2 Sec lable text is:-Set And After 2 Sec lable text is:- Go.

now i use a 3 different alert to display this.

Can i do this with only one alert

最佳答案

我想你想要这种类型的警报 enter image description here

做这个试试这个

在 .h 文件中

#import <UIKit/UIKit.h>

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

@end

在 .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

关于iphone - 使用事件指示器和标签显示警报(可变),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15634236/

相关文章:

iphone - 将 URL(作为字符串)添加到数组时出现问题

ios - 将实体的自定义字段与 NSPredicate 一起使用

iphone - 如何使用陀螺仪计算步数?

iOS使用框架从swift导入swift类

IOS 在字符串中设置错误消息以在警报中显示

objective-c - 将 NSNumber 舍入到特定数量的有效数字

ios - 如何在给定的时间内显示 NSArray

c++ - 为 iphone 应用程序编译/使用 unrar C++ 源代码?

iOS 在使用后端服务器时处理本地 SKPaymentTransaction

objective-c - 如何自定义Mapbox主题