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开发者_Go百科 the color to black? If yes, please guide me or give some sample code.
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.
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
}
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)
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)
You can switch between .gray
, .white
and .whiteLarge
by using the .activityIndicatorViewStyle
property.
精彩评论