Search code examples
iosobjective-cxcodeautolayoutuiactivityindicatorview

Activity indicator not centered in landscape mode


I am trying to add an activity indicator on top of my table view such that it is appearing in the center of the screen in both portrait and landscape mode.

The activity indicator is placed inside a view which is a subview of the main view. The table view is included via a view container in the main view.

When I click "Add Missing Constraints", the indicator gets a Center Y alignment constraint and a Horizontal space (141) constraint. As expected this makes things look just fine in portrait mode, but in landscape mode the activity indicator appears to the left instead of being horizontally centered.

I have tried to change the Horizontal space constraint to a Center X alignment constraint, but that does not seem to make the situation any better.

Any suggestions?

enter image description here


Here is a close up:

enter image description here


Solution

  • --> First, add the Spinner View (the yellow one as in screenshot)

    Select it and set constraints as in

    enter image description here

    Pin it to all the four edges

    --> Secondly add the Activity Indicator.

    Select it and set constraints as in

    enter image description here

    Center X and Center Y = 0


    If there is any warning of Misplaced Views, select "Resolve Auto Layout Issues" !

    In the end the constraints look like this

    enter image description here