//button click
- (IBAction)btn_Button:(UIButton *)sender {
// プログレスバーを作成
progressView =
[[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
// 表示位置が画面中央になるように、調整しています。
CGSize pSize = progressView.frame.size;
CGSize vSize = self.view.frame.size;
progressView.frame = CGRectMake((vSize.width - pSize.width)/2, (vSize.height-pSize.height)/2, pSize.width, pSize.height);
//progressView.frame = CGRectMake(0, 150, 250, 10);//位置x, 位置y, 幅, 高さ
// プログレスバーをビューに追加
[self.view addSubview:progressView];
// タイマーを生成(0.1秒おきにdoTimer:メソッドを呼び出す)
p = 0;
[NSTimer scheduledTimerWithTimeInterval:0.1f
target:self
selector:@selector(doTimer:)
userInfo:nil
repeats:YES
];
}
/**
* 指定時間後にタイマーから呼ばれる
* @param timer 呼び出し元のNSTimerオブジェクト
*/
- (void)doTimer:(NSTimer *)timer
{
// プログレスバーのバーをのばす
progressView.progress = (float)p / 100.0;
p++;
if (p > 100) {
// タイマーを止める
[timer invalidate];
}
}