UIView setFrame Task

I have to do something wrong, but I don’t know what ..

I am trying 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 do not get the expected result

Let me if I am wrong. If I want a 10x10 square view in the center, I need to add the following line:

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

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

+6
source share
4 answers

problem fixed by installation

 self.view.autoresizesSubviews = NO; 
+7
source

if you use autostart, the call setFrame function is not used, try calling setTranslatesAutoresizingMaskIntoConstraints before setFrame

+10
source

The code is a bit unconventional, but I will question it because you set the view frame before adding it as a subtitle. Therefore, the position of the subview is likely to be changed by layoutSubviews before you see it.

So, try putting the second line of code for the last time and see if this does the trick.

0
source

Try using float instead of ints:

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

in

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

Source: https://habr.com/ru/post/893955/


All Articles