Is it possible to change an UIActivityIndicatorView color to black in iOS?

I want to change an activity indicator color gray/white to black. Is it possible to change the color to black? If yes, please guide me or give some sample code.


Solution 1:

You can use the .color property in order to change the UIActivityIndicatorView color, e.g.:

// Objective-C
activityIndicator.color = [UIColor greenColor];

// Swift
activityIndicator.color = .green

Note that .color is only available from iOS 5.

Solution 2:

It is very easy in Swift 5

@IBOutlet weak var loadingIndicator: UIActivityIndicatorView!       //Declare the UIActivityIndicatorView

override func viewDidLoad() {
   super.viewDidLoad()
   loadingIndicator.style = .medium     //Just change the indicator Style
   loadingIndicator.color = .black      //and change what is your indicator color
}

Solution 3:

To use a standard system color:

activityIndicator.color = .green

To use a custom RGBA color

activityIndicator.color = UIColor(displayP3Red: 255/255, green: 150/255, blue: 181/255, alpha: 255/255)

Solution 4:

I recommend doing the following:

  1. UIActivityIndicatorViewStyle.whiteLarge to make the spinner bigger
  2. pick a color
  3. pick a backgroundColor to increase contrast

    var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
    activityIndicator.color = UIColor.<YOUR DESIRED COLOR>
    activityIndicator.backgroundColor = UIColor.<YOUR DESIRED BACKGROUND COLOR>
    self.view.addSubview(self.activityIndicator)