What is the iOS equivalence for Android RelativeLayout / LinearLayout?

How to control the relative position of the views, especially I want my application to work on a 3.5-inch display and a 4-inch display without problems?

+4
source share
4 answers

Take a look: iOS 6 apps - how to deal with the screen size of the iPhone 5? and How to add iPhone 5 large screen support for iOS apps in Xcode?

But this was done for you, for the most part, with automatic layout. Click on your project in Xcode and go to the Summary tab to add another screen launch screen for your application.

+1
source

As with iOS 9, you can use UIStackView , which is very similar to LinearLayout : you add views, and the stack view arranges them as needed based on your size parameter - if you use Interface Builder, you can experiment with each option so that see which one suits your needs. You can also set the distance between the views in the stack view by adding some extras.

WARNING When adding views of stack children in your code, you should always use addArrangedSubview() as follows:

 stackView.addArrangedSubview(someView) 

If you try to use the plain old addSubview() , it will not work correctly because the stack view will not know to organize it.

As for deletion, you need to be careful to use stackView.removeArrangedSubview(someView) and someView.removeFromSuperview() , otherwise the view will not be deleted correctly.

You can find the helpful UIStackView tutorial .

+4
source

There are no equivalent or relative and linear layouts. User interface elements have autoresist masks that determine how they will move / stretch when the supervisor resizes (for example, when the screen rotates). You can also use layout restrictions for positioning if you plan to create your application for iOS 6+. If you cannot solve the permutation problem with these tools, you must change the frames of the user interface elements in your code.

+2
source

Auto Layout System "RelativeLayout

UIStackView ≈ LinearLayout

IMO. UIStackView was not well designed

  • cannot easily add additional restrictions between subviews / subview and superview
  • too often to create constraint conflicts

    x IOS 9+ only

So, I wrote AutoLinearLayoutView, replacing UIStackView.

Demo screenshot

Extract from Github AutoLinearLayoutView

-one
source

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


All Articles