-2

Hello I've just started programming and I'm trying to write with code instead of using the storyboard, but the constraints I added do not work at different screen sizes How do I solve this problem

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
  • 2
    Possible duplicate of [iOS different constraints for different devices](https://stackoverflow.com/questions/48651057/ios-different-constraints-for-different-devices) – A.Munzer Jul 31 '19 at 14:01

1 Answers1

0

Since you do it in the code, you can check the size class before adding any constraint like this:

if (self.view.traitCollection.horizontalSizeClass == .compact) {
    /* add needed constraints */
}

Also you can implement the traitCollectionDidChange: method to automatically be called when a trait changes due to autorotation.

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278