技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

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];
}

 

posted on 2014-10-08 20:19  codestyle  阅读(341)  评论(0编辑  收藏  举报