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

IosIphoneUiactivityindicatorview

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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 - Ios

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 - Ios

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 - Ios

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)
    

Solution 5 - Ios

You can switch between .gray, .white and .whiteLarge by using the .activityIndicatorViewStyle property.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPugalmuniView Question on Stackoverflow
Solution 1 - IosCesarView Answer on Stackoverflow
Solution 2 - IosM VIJAYView Answer on Stackoverflow
Solution 3 - IosSagar PatelView Answer on Stackoverflow
Solution 4 - Iosbrownmagik352View Answer on Stackoverflow
Solution 5 - Iosuser643097View Answer on Stackoverflow