1

I want to have certain views in exact places, and constraints aren't working for me. How can I place, say, a collectionView in the lower 80% of the screen, and an ImageView in the top 20%?

In case it matters, I am planning this app to work only for iPads in landscape view.

Jonathan Allen Grant
  • 3,408
  • 6
  • 30
  • 53

2 Answers2

0

You can use NSLayoutConstraints, it will not take long to get familiar with the system. This way you can customize your views with ease. Bigger applications are made without storyboards. This a good tutorial http://makeapppie.com/2014/07/26/the-swift-swift-tutorial-how-to-use-uiviews-with-auto-layout-programmatically/

applejuiceteaching
  • 1,473
  • 3
  • 13
  • 25
0

Does it have to be programmatically? You could add constraint between the two in the interface builder and achieve the same. To do this,

  1. control drag from the smaller to the larger and select aspect ratio,
  2. then select one of the views and go to the size inspector on the right bar
  3. under Constraints, select the constraint that was just added, double click it
  4. under First Item select shorterView.Height
  5. under Relation select Less Than or Equal
  6. under Second Item select tallerView.Height
  7. make sure Constant is 0 and Priority is 1000
  8. set the Multiplier to 1:4 (I believe this is the correct ratio, but I always just mess around with these numbers until I'm satisfied with the views)

I'm currently using this in one of my projects, and it's working really well, so hopefully it will work for you, too!

(The top answer here might also help :] )

Community
  • 1
  • 1
Rachel Harvey
  • 1,719
  • 2
  • 15
  • 23