1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I want the view's background color to be black.
gray is very near from black
I mean the spinning wheels should be white or whatever that is.
The view background color should be strictly black.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.