Usage of Uiactivityindicatorview activity indicator in IOS development

Source: Internet
Author: User
Tags see definition set background

Software development often encounter half a day before loading out the data, whether the program write rotten, or the original speed is relatively slow, the general will give a hint to let users feel that we are trying to load data, iOS can achieve similar results through Uiactivityindicatorview. Uiactivityindicatorview provides a lightweight view that displays a standard rotational progress wheel, as long as it is added to the program, start and stop in the appropriate place. The start can be adsorbed in the current view, the stop will be removed ~

Activity indicators are typically used when making a network request, because Uiactivityindicatorview is the system's own class, so it is recommended.


Uiactivityindicatorview *activityindicatorview = [[Uiactivityindicatorview alloc] Initwithframe:cgrectmake (0, 0, 40, 40)];//Activity indicator
Activityindicatorview.center = Self.view.center;
Activityindicatorview.activityindicatorviewstyle = Uiactivityindicatorviewstylewhitelarge; Style of activity indicator
There are 3 kinds: uiactivityindicatorviewstylewhitelarge,uiactivityindicatorviewstylewhite, Uiactivityindicatorviewstylegray
[Self.view Addsubview:activityindicatorview];

Isanimating is used to determine whether the rotation
[Activityindicatorview startanimating]; Let the activity indicator turn, typically before the start of a network request
[Activityindicatorview stopanimating]; Corresponds to the startanimating, which is called after the data is obtained


The following code implements the start and stop of the progress wheel:

-(void) viewdidload

{

activity = [[Uiactivityindicatorviewalloc] initwithframe:cgrectmake (0, 0, 30, 30)];//Specify the size of the progress wheel

[Activitysetcenter:cgpointmake (160, 140)];//Specifies the center point of the progress wheel

[activitysetactivityindicatorviewstyle:uiactivityindicatorviewstylewhitelarge];//Set the progress wheel display type

[Self.viewaddSubview:activity];

[Superviewdidload];

}

button click the method that is triggered. Start or close the progress wheel.

-(Ibaction) Startorstop: (ID) sender{

if ([activityisanimating]) {

[Activitystopanimating];

}

Else

[Activitystartanimating];

Click Start Progress Round

Click here to stop the progress round
Loading effect Uiactivityindicatorview

Class
uiactivityindicatorview* indicator = [[Uiactivityindicatorview alloc] Initwithframe:cgrectmake (0, 0, 50, 50)];
Set display style, see definition of Uiactivityindicatorviewstyle
Indicator.activityindicatorviewstyle = Uiactivityindicatorviewstylewhitelarge;
Set Display location
[Indicator Setcenter:cgpointmake (SELF.FRAME.SIZE.WIDTH/2, SELF.FRAME.SIZE.HEIGHT/2)];
Set Background color
Indicator.backgroundcolor = Uicolor.gray.
Set Background transparency
Indicator.alpha = 0.5;
Set the background to rounded rectangles
Indicator.layer.cornerRadius = 6;
Indicator.layer.masksToBuounds = YES;
Add initialized indicator to view
[View Addsubview:indicator];
Start displaying loading animations
[Indicator startanimating];
Stop displaying loading animations
[Indicator stopanimating];
Copy Code
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.