Reputation: 9409
I want to display a gray UIViewIndicatorView
in a view controller at the center of the view but this piece of code isn't showing anything:
class MyViewController: UIViewController {
var activityIndicatorView = UIActivityIndicatorView()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
displayActivityIndicator()
}
func displayActivityIndicator() {
view.addSubview(activityIndicatorView)
activityIndicatorView.style = .gray
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
activityIndicatorView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
activityIndicatorView.widthAnchor.constraint(equalToConstant: 40).isActive = true
activityIndicatorView.heightAnchor.constraint(equalToConstant: 40).isActive = true
activityIndicatorView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
activityIndicatorView.startAnimating()
}
}
This only shows up the activity indicator view when I set the view controller's view to a color like white (excluding black).
How can I make it show up?
Upvotes: 1
Views: 998
Reputation: 100503
Change background to
view.backgroundColor = .green // for example
or
activityIndicatorView.style = .white
then you' ll see it , as it's nearly a color match between the indicator and the background view
Upvotes: 1