Statement You are welcome to repost this article, but please respect the author's Labor achievements. repost this article and keep the statement in this box. Thank you. Article Source: http://blog.csdn.net/iukey |
The activity indicator (uiactivityindicatorview) informs the user that an operation is in progress. The progress indicator (uiprogressview) also has the same function, and can also tell the user how far it is from the end of the operation.
Both indicators are derived from uiview, so they are views and can be attached to them.
I. uiactivityindicatorview activity indicator
1. Create
UIActivityIndicatorView* activityIndicatorView = [ [ UIActivityIndicatorView alloc ] initWithFrame:CGRectMake(250.0,20.0,30.0,30.0)];
2. attribute settings
Style:
activityIndicatorView.activityIndicatorViewStyle= UIActivityIndicatorViewStyleGray;
The system provides you with three styles:
Uiactivityindicatorviewstylewhitelarge large white indicator
Uiactivityindicatorviewstylewhite standard size white indicator
Uiactivityindicatorviewstylegray gray indicator for white background
Hide automatically
If you want the indicator to be automatically hidden after it is stopped, set the hideswhenstoped attribute to yes. The default value is yes. The indicator will still be displayed after it is set to No.
activityIndicatorView.hidesWhenStoped = NO;
3. Display
It can be attached to any view, such as a table unit or view:
[ self.view addSubview:activityIndicatorView ];
4. Start and Stop
[Activityindicatorview startanimating]; // start [activityindicatorview stopanimating]; // stop
Ii. uiprogressview progress indicator
Uiprogressview is similar to uiactivityindicatorview, but it provides an interface for you to display something similar to a progress bar, so that you can know how much the current operation has completed.
1. Create
UIProgressView* progressView = [ [ UIProgressView alloc ] initWithFrame:CGRectMake(150.0,20.0,130.0,30.0)];
2. attribute settings
Style:
progressView .UIProgressViewStyle= UIProgressViewStyleDefault;
The system provides you with two styles:
Uiprogressviewstyledefault standard progress bar
Uiprogressviewstyledefault dark gray progress bar, used in the toolbar
3. Display
[ self.toolBar addSubview:progressView ];
4. Progress
When it is displayed, your program can update its progress. The property progre is a floating point number between 0.0 and 1.0:
progressView.progress = 0. 5;
3. network activity indicator
When your application uses the network, you should place a network indicator on the iPhone status bar to warn users that they are using the network. In this case, you can use a property named networkactivityindicatorvisible of uiapplication. You can set this to enable or disable the network indicator: uiapplication * APP = [uiapplication sharedapplication]; app. networkactivityindicatorvisible = yes;
Iv. Expansion
Do you think you have learned something new? Yes. But I still have a better recommendation: mbprogresshud https://github.com/jdg/MBProgressHUD a more Nb third-party progress indicator that you can use as it provides examples, very powerful. But one thing I want to remind you is that it is asynchronous, so it cannot block your current program. If you want to block your program, you need to make some modifications to the logic control.