Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

ActivityIndicator View

ActivityIndicator is a kind of content view that can be used to show that a task is in progress. It is mainly used in-network calls. We can control the ActivityIndicator View by using methods defined in UIActivityIndicatorView class. UIActivityIndicatorView is the subclass of UIView.

We can start the animation by calling the startAnimating() method of UIActivityIndicatorView class. Similarly, the stopAnimating() method can be used to stop the animation. The two methods are used in combination to show and hide the activity indicator in the iOS application.

Adding UIActivityIndicatorView to interface

  1. Search for UIActivityIndicatorView in the object library and drag the result to the storyboard.
  2. Define the Auto Layout rules to govern the size and position of activity indicator on the different size devices.
  3. Create an action outlet of ActivityIndicator in ViewController class.
  4. Use the methods and properties defined in the UIActivityIndicatorView class to start and stop the animation accordingly.

Methods and properties

SN Method or property Description
1 func startAnimating() This method is used to start the animation of the activity indicator.
2 func stopAnimating() This method is used to stop the animation of the activity indicator.
3 var isAnimating : Bool This is a boolean property that indicates whether the activity indicator is animating or not.
4 var hidesWhenStopped() : Bool This is a Boolean property that controls whether the receiver is hidden when the animation is stopped.
5 var style:UIActivityIndicatorView.style It is the basic appearance of the activity indicator.
6 var color:UIColor It determines the color of the Activity Indicator.

Example 1

This is a simple example that visualizes the activity indicator view on the screen.

Interface Builder

In this example, we will first add the ActivityIndicatorView to the storyboard. For this purpose, we will search for the UIActivityIndicatorView in the object library and drag the result to the storyboard.

iOS ActivityIndicator View

Define the auto-layout rules for the activity indicator and create the connection outlet in the view controller.

iOS ActivityIndicator View

ViewController.swift

Output:

iOS ActivityIndicator View

Example 2

In Example1, we have displayed an uncontrolled UIActivityIndicatorView. In this example, we will create two buttons to start and stop the animation of the activity indicator. In the action outlet of the start button, we will start the animation, whereas, in the action outlet of the stop button, we will stop the animation.

Interface Builder

The following image shows the storyboard we will create in the example. This is similar to example 1 to most of the extent. In this example, we will also add the buttons to control the behavior of the Activity indicator view.

iOS ActivityIndicator View

ViewController.swift

Output:

iOS ActivityIndicator View
Next TopicImageView





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA