开发者

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/10开发者_开发知识库0 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?


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


problem fixed by setting

self.view.autoresizesSubviews = NO;


The code is a little unconventional, but I'll hazard a guess it's because you are setting the view's frame before you add it as a subview. Hence the subview's position probably gets changed by layoutSubviews before you see it.

So try putting the second line of code last and see if that does the trick.


Try using floats instead of ints:

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

to:

[subMenuView.view setFrame:CGRectMake(10.0f,0.0f,990.0f,100.0f)];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜