UIActivityIndicatorView是用於當執行一個複雜作業時,

可使用IndicatorView提示使用者現在正在執行一個複雜作業,

並提示使用者等待此作業完成。

storyboard可設定indicator的樣式、顏色、初始狀態、停止時隱藏等等,

其中的behavior可設定animating屬性與hides when stopped,

本範例為點擊按鈕後啟動indicator,再次點擊則停止。

viewcontroller.m

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *myIndicator;
- (IBAction)toClick:(id)sender;

@end

@implementation ViewController

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

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

- (IBAction)toClick:(id)sender {
    
    if (_myIndicator.isAnimating == YES) {
        
        [_myIndicator stopAnimating];
        
    }else{
        
        [_myIndicator startAnimating];
    }
    
}
@end

 

    文章標籤

    UIActivityIndicatorView iOS

    全站熱搜

    Will 發表在 痞客邦 留言(0) 人氣()