Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UIView in the center of the screen

I need to add a simple loading animation on top a my view..and want it to be in the center of screen(visible aria)..can anybody point me to the right direction.? how to get the center of the window so that i can addSubview..?

like image 905
Ajith Avatar asked Oct 25 '10 07:10

Ajith


2 Answers

Check center property of UIView. You can set your view center to viewControllers root view for example:

yourView.center = self.view.center;
like image 99
Vladimir Avatar answered Nov 15 '22 10:11

Vladimir


If you may want to control the center alignment of axis's separately, consider the below answer.

Center/align along the X axis

yourView.center = CGPointMake(self.view.center.x,self.yourView.center.y);

Center/align along the Y Axis

yourView.center = CGPointMake(self.yourView.center.x, self.view.center.y);
like image 10
A. Adam Avatar answered Nov 15 '22 08:11

A. Adam