UIView Fixed Height is different in iphone 6 plus, iphone 8 plus

Code Block
- (void)viewDidLayoutSubviews{
  [super viewDidLayoutSubviews];
  UIButton* button =[[UIButton alloc] initWithFrame:CGRectMake(0, 200, [UIScreen mainScreen].bounds.size.width, 300)];
  [button setBackgroundColor:[UIColor orangeColor]];
  [button addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}


I just add a UIButton with 300 height. When I run in iphone 6 plus and iphone XR, the UIButton's height in iphone 6 plus is biggger than in iphone XR. Why?

Replies

viewDidLayoutSubviews is not the right place to create objects,
  • you will create new objects each time to have to layout

  • your risk creating infinite recursive loops

you should do it either in viewDidLoad or in viewWillAppear.

How much bigger is the button ?
Does it occur in simulator or device ?