How to position activity indicator to the center of its superview using Auto Layout programmatically?

后端 未结 4 1790
终归单人心
终归单人心 2021-02-12 12:18

Why the following code does not work for positioning activity indicator to the center of its superview:

UIActivityIndicatorView *activityIndicator = [[UIActivity         


        
4条回答
  •  日久生厌
    2021-02-12 13:11

    I centered my activity indicator in its superview by adding it in Interface Builder with an alpha of zero (and an IBOutlet for it in my view controller class). Then I added constraints to center it in the X and Y axes. Finally, I added width and height constraints to it to silence an autolayout error.

    In my view controller's startActivityIndicator method, I set the alpha of the activity indicator to one and call the startAnimating method on it. In my stopActivityIndicator method, I call the stopAnimating method on it and set the alpha of the activity indicator back to zero.

提交回复
热议问题