Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add sub view in center - iPad

Tags:

ipad

I want to add a sub view in current view, this sub view is 300x300. When I add subview using

[self.view addSubview:md.view];

the md.view will appear at position (0,0) is there any way to add subview in center?

Thanks

like image 595
Saurabh Avatar asked Dec 02 '22 05:12

Saurabh


2 Answers

You can set view's center property:

md.view.center = self.view.center;

Or you can explicetly set frame for md.view so that it will be centered as you want.

like image 109
Vladimir Avatar answered Dec 06 '22 23:12

Vladimir


Use

CGRect bounds = self.view.bounds;
md.view.center = CGPointMake(bounds.size.width / 2, bounds.size.height / 2);

before or after that -addSubview: line.

like image 31
kennytm Avatar answered Dec 06 '22 23:12

kennytm