How do I position views in Interface Builder for both 3.5” and 4” Retina?

前端 未结 3 1211
遇见更好的自我
遇见更好的自我 2021-01-31 23:45

I want to position a UIView so it appears in the centre on both 3.5” and 4” Retina screens. What is the best way to do this? If I turn off all the Autosizing bars I would expect

3条回答
  •  情话喂你
    2021-02-01 00:02

    Here's how you would do it manually (without AutoLayout):

    int screenWidth = [[UIScreen mainScreen] applicationFrame].size.height;
    int screenHeight = [[UIScreen mainScreen] applicationFrame].size.width;
    
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,200)];
    [myView setCenter:CGPointMake(screenWidth/2, screenHeight/2)];
    
    [self.view addSubview:myView];
    

提交回复
热议问题