skip to Main Content

Is it right to make the interface via CGRect? I hardly use constraints. For the most part, my interface consists of labels spread across the entire width of the screen.

2

Answers


  1. When you want to use CGRect you should be aware of autoresizingMask,
    Both auto layout(constraints) and auto Autoresizing mask used for layout iOS and macOS Apps, both of them has cons and pros.
    I suggest you to read apple document about autoresizing mask:
    https://developer.apple.com/documentation/uikit/uiview/1622559-autoresizingmask

    and then read this article about cons and pros of both of these and also usage to know when it’s better to use auto layout or autoresizingMask:
    https://www.advancedswift.com/autolayout-vs-autoresizing-masks/

    Login or Signup to reply.
  2. If you are gonna use CGReact then you can face some serious issues with layout when switching between landscape and portrait, yes you can optimize the app for both portraits and landscape with CGreact but trying constraint will give you a lot more flexibility and control over your UI, but if you are only focusing on either landscape or portrait then it will not impact that much

    but keep in mind you may get confused while making constraints programmatically if you are doing this then please don’t forget to mention this line

    (targetView).translatesautoresizingmaskintoconstraints = false

    and you can define constraint programmatically for eg

    (targetView).topAnchor.constraint(equalTo : view.topAnchor).isActive = true

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search