我想在activity indicator
中使用TableView
文件显示NIB/XIB
,但显示的不是中心,而是放在右侧
我做:
override func viewDidLoad() {
super.viewDidLoad()
let actInd: UIActivityIndicatorView = UIActivityIndicatorView()
actInd.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
actInd.center = self.view.center
actInd.hidesWhenStopped = true
actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
self.view.addSubview(actInd)
actInd.startAnimating()
}
答案 0 :(得分:1)
let actInd: UIActivityIndicatorView = UIActivityIndicatorView()
override func viewDidLoad() {
super.viewDidLoad()
actInd.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
actInd.hidesWhenStopped = true
actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
self.view.addSubview(actInd)
actInd.startAnimating()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
actInd.center = self.view.center
}
/* Following two functions are acceptable also.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
actInd.center = self.view.center
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
actInd.center = self.view.center
}
*/
答案 1 :(得分:1)
你可以:
UIActivityIndicator
hidden
(在故事板中)IBOutlet
spinner.isHidden
。答案 2 :(得分:1)
这种方法对我有用。
if let window = UIApplication.shared.keyWindow {
activityIndicator.frame = CGRect(x: window.frame.width/2, y: window.frame.height/2, width: 0, height: 0)
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.white
window.addSubview(activityIndicator)
}
希望有所帮助:)