美文网首页
iOS - 等待UIActivityIndicatorView

iOS - 等待UIActivityIndicatorView

作者: 小黑Unity_齐xc | 来源:发表于2019-01-18 22:02 被阅读3次

头文件

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    //定义等待控件UIActivityIndicatorView
    UIActivityIndicatorView* _aiv;
}

//定义属性UIActivityIndicatorView
@property(retain,nonatomic)UIActivityIndicatorView* aiv;

@end

源文件

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize aiv = _aiv;

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

-(void) initBtns{
    UIButton* btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn1.frame = CGRectMake(100, 200, 100, 50);
    btn1.backgroundColor = [UIColor greenColor];
    [btn1 setTitle:@"开始" forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(btn1click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
}

bool isStart = false;
-(void) btn1click:(UIButton*) btn{
    isStart = !isStart;
    if(isStart){
        [_aiv startAnimating];
        [btn setTitle:@"停止" forState:UIControlStateNormal];
    }
    else{
        [_aiv stopAnimating];
        [btn setTitle:@"开始" forState:UIControlStateNormal];
    }
}

-(void) initAiv{
    //初始化UIActivityIndivatorView
    _aiv = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _aiv.frame = CGRectMake(100, 100, 100, 100);
    _aiv.color = [UIColor orangeColor];
    _aiv.hidesWhenStopped = NO;
    
    [self.view addSubview:_aiv];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

相关文章

网友评论

      本文标题:iOS - 等待UIActivityIndicatorView

      本文链接:https://www.haomeiwen.com/subject/eomodqtx.html