UIActivityIndicatorView not showing up in iOS UIViewController
我想在视图中心的视图控制器中显示一个灰色的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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() } } |
仅当我将视图控制器的视图设置为类似白色(不包括黑色)的颜色时,才会显示活动指示器视图。
我怎样才能让它显示出来?
改变背景为
1 | view.backgroundColor = .green // for example |
或
1 | activityIndicatorView.style = .white |
然后你会看到它,因为它几乎是指示器和背景视图之间的颜色匹配