我想在视图中心的视图控制器中显示灰色UIViewIndicatorView
,但是这段代码没有显示任何内容:
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()
}
}
仅在将视图控制器的视图设置为白色(不包括黑色)之类的颜色时,才会显示活动指示器视图。
如何显示它?
答案 0 :(得分:1)
将背景更改为
view.backgroundColor = .green // for example
或
activityIndicatorView.style = .white
然后您将看到它,因为它几乎是指示器和背景视图之间的颜色匹配