简体   繁体   English

如何在iPhone SDK中实现UIProgressView

[英]How to Implement UIProgressView in iphone sdk

I have this code in a button click [NSThread detachNewThreadSelector: @selector(spinBegininapp) toTarget:self withObject:nil]; 我在按钮中单击此代码,然后单击[NSThread detachNewThreadSelector: @selector(spinBegininapp) toTarget:self withObject:nil]; to show a activity indicator for user that the background thread is running ,i put this code to enable the activity-indicator 为用户显示后台线程正在运行的活动指示器,我将这段代码启用了活动指示器

- (void)spinBegininapp
{
    _activityindictor.hidden = NO;

}

and it works fine,when i click the button it shows the activity-indictor animating ,when the thread goes it hides the activity-indicator,but my need is to show a progressView instead of activity-indicator,it progresses according to the thread,and if the thread finishes it need to reach progress completely and self hide.is that possible . 并且它工作正常,当我单击按钮时显示活动指示器动画,当线程运行时,它隐藏活动指示器,但是我需要显示一个progressView而不是活动指示器,它根据线程进展,如果线程完成了,则需要完全达到进展并且自隐藏。这是可能的。

#pragma mark - Loading Progress

static float progress = 0.0f;

-(IBAction)showWithProgress:(id)sender {
   progress = 0.0f;
   _progressView.progress = progress;
   [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3];
}

-(void)increaseProgress {
   progress+=0.1f;
   _progressView.progress = progress;    
   if(progress < 1.0f)
     [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3];
   else
    [self performSelector:@selector(dismiss) withObject:nil afterDelay:0.2f];
}

-(void)dismiss {
   [self progressCompleted];
}

now call the following function whenever/where ever you want to show progress 现在,无论何时何地您都想显示进度,请调用以下函数

[self showWithProgress:nil]; 

progress range lies between 0.0 and 1.0 进度范围介于0.0到1.0之间

1.0 means 100% 1.0表示100%

you can add a progress view no doubt but usually it used for definite quantities like time or data.. for eg. 您可以毫无疑问地添加进度视图,但是通常用于确定的数量,例如时间或数据。 If you are downloading a 2mb file then you can always tell how much data you have downloaded and show the in the progress view as a factor. 如果您要下载2mb的文件,则始终可以知道已下载了多少数据,并将其作为进度显示在进度视图中。 So if something similar is happening inside your thread you can use this.. 因此,如果您的线程内发生了类似的事情,您可以使用它。

UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:whateverStyle];
    progressView.progress = 0.75f;
    [self.view addSubview: progressView]
    [progressView release];

you just need to update your progress as the value changes.... hoping this helps. 您只需要在值更改时更新进度即可。...希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM