Search code examples
iosobjective-cxcodexib

XIB: Centering elements


I have an XIB file containing a simple activity indicator that I want to be vertically and horizontally centered. In XCode I can center it in w:compact and h:compact, but when I run it on the device its not centered (is offset). I have searched and I found suggestions on constraints or disabling auto layout, but when I do any of these my activity indicator is not shown in the view anymore.
I'd appreciate if you can help me with this. Thanks.


Solution

  • Add Activity indicator and select it and add constraints like in image.

    Autolayout constaraints

    P.S - Learning curve of auto layout is very tricky and require patience. The more you practice, more you improve. Read online tutorials, youth videos..Implement!