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.
Asked
Active
Viewed 3.8k times
5 Answers
193
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.
-
This does not work. This changes the colour of the ActivityIndicator text and not the ActivityIndicator spinning Icon that OP is asking about. – Alex Mar 11 '14 at 16:56
-
1@AlexHarvey - it changed the icon for me. What is your code? – Ser Pounce Mar 21 '14 at 23:29
-
In Xcode 6 (but perhaps even earlier), it is possible to change the color and size of the activity view directly in IB. – Luis Delgado Jul 22 '15 at 07:59
-
I'm using Xcode 7.1.1 for iOS9.1 and it works well in IB, changing the color of the activity indicator graphic itself. – idStar Nov 14 '15 at 15:14
5
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
}

M VIJAY
- 149
- 1
- 6
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)

SagarScript
- 1,145
- 11
- 15
1
I recommend doing the following:
UIActivityIndicatorViewStyle.whiteLarge
to make the spinner bigger- pick a color
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)

Pang
- 9,564
- 146
- 81
- 122

brownmagik352
- 398
- 3
- 12
-
Your answer is valid, but it also adds code that is not relevant to the scope of the question (e.g. `hidesWhenStopped`, `center`,...) – elitalon Feb 19 '17 at 08:43
0
You can switch between .gray
, .white
and .whiteLarge
by using the .activityIndicatorViewStyle
property.

elitalon
- 9,191
- 10
- 50
- 86

user643097
- 127
- 2
- 15