iOS:等待控件

定义:

@interface ViewController ()
{
    UIActivityIndicatorView *testActivityIndicator;
}

实例化,开始旋转:

-(void) showWaitStatus
{
    NSLog(@"wait...");
    testActivityIndicator =
            [[UIActivityIndicatorView alloc]
            initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    
    CGRect rect = self.view.frame;
    testActivityIndicator.center = CGPointMake(rect.size.width / 2, rect.size.height / 2);
    [self.view addSubview:testActivityIndicator];
    testActivityIndicator.color = [UIColor redColor]; // iOS5 引入指定颜色
    [testActivityIndicator startAnimating];           // 开始旋转
    [testActivityIndicator setHidesWhenStopped:YES];  // 当旋转结束时隐藏
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self showWaitStatus];
}

停止旋转:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [testActivityIndicator stopAnimating];
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。