Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 303
Stine Avatar asked Dec 11 '25 20:12

Stine


2 Answers

--> 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

like image 176
Jen Jose Avatar answered Dec 13 '25 13:12

Jen Jose


SWIFT 3.2

try this

self.activityIndicator.center = CGPoint(x:self.view.bounds.size.width/2.0,y: self.view.bounds.size.height/2.0);

activityIndicator.autoresizingMask = (UIViewAutoresizing(rawValue: UIViewAutoresizing.RawValue(UInt8(UIViewAutoresizing.flexibleRightMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleLeftMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleBottomMargin.rawValue) | UInt8(UIViewAutoresizing.flexibleTopMargin.rawValue))))
like image 43
Shishir Umrao Avatar answered Dec 13 '25 15:12

Shishir Umrao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!