Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView setFrame problem

I must do something wrong, but dont know what..

I try to add a subView with this code:

subMenuView = [[UISubMenuViewMainController alloc] init];

[subMenuView.view setFrame:CGRectMake(10,0,990,100)];

subMenuView.view.backgroundColor  = [UIColor whiteColor];

[self.view addSubview:subMenuView.view];

I want my view to be at (10,0) and have 990/100 in width/height

but i dont get the expected result

Let me if I m wrong, If I want a 10x10 square view at the center i have to add the following line:

[subMenuView.view setFrame:CGRectMake(512,384,10,10)];

That s not what I get, the position is correct, but the width/height are wrong, any ideas?

like image 570
Nico AD Avatar asked Jul 30 '11 20:07

Nico AD


2 Answers

if you use autolayout,the call setFrame have no use,try call setTranslatesAutoresizingMaskIntoConstraints before setFrame

like image 73
user1923254 Avatar answered Jan 04 '23 05:01

user1923254


problem fixed by setting

self.view.autoresizesSubviews = NO;
like image 22
Nico AD Avatar answered Jan 04 '23 05:01

Nico AD