我的開發筆記---UIProgressView的詳細使用


UIProgressView顧名思義用來顯示進度的,如音樂,視頻的播放進度,和文件的上傳下載進度等。

下面以一個簡單的實例來介紹UIprogressView的使用。

 

@interface ActivityViewController : UIViewController

{

    UIProgressView *proView;  

    double proValue;

    NSTimer *timer;

}

 

@property(nonatomic, retainUIProgressView *proView;

-(IBAction)btnStartClick;

 

 

@implementation ActivityViewController

@synthesize proView;

 

#pragma mark - View lifecycle

-(IBAction)btnStartClick

{

    proValue=0;

     timer = [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(changeProgress) userInfo:nilrepeats:YES]; //利用計時器,每隔1秒調用一次(changeProgress)

}

-(void)changeProgress

{

    proValue += 1.0; //改變proValue的值

    if(proValue > 5)

    {

        //停用計時器

        [timer invalidate];        

    }

    else

    {

        [proViewsetProgress:(proValue / 5)];//重置進度條

    }

}

 

- (void)viewDidLoad

{

    proView = [[UIProgressViewalloc] initWithFrame:CGRectMake(100, 100, 150, 20)];

    [proViewsetProgressViewStyle:UIProgressViewStyleDefault]; //設置進度條類型

    [self.viewaddSubview:proView];

    

    [superviewDidLoad];

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM