I need to display the Activity Indicator in a TableViewController so that when scrolling it is in the middle of the screen. TableViewController I boot from XIB/NIB

 let activity = UIActivityIndicatorView() override func viewDidLoad() { super.viewDidLoad() activity.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0) activity.hidesWhenStopped = true activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge self.view.addSubview(activity) activity.bringSubview(toFront: self.view) activity.startAnimating() } 

It works and shows but in x:0, y:0 coordinates x:0, y:0 that is, the very top left. But I need it to be fixed in the middle of the screen when the TableView is scrolling.

Xcode 8.2, Swift 3

    1 answer 1

    Add line:

     activity.center = view.center