0

I am currently developing an educational app, the first view controller displays the main categories and the second one (almost like Pinterest) displays the several subcategories. The Auto layout that I used works perfectly for the iPhone 6, 7, 8 and X however the Plus models of those are a little bit distorted

This is how it looks in models 6, 7, 8 and X

enter image description here

enter image description here

However when I run it in the Plus models, it looks like the following:

enter image description here

enter image description here

I have the following Auto Layout Code

This Auto Layout corresponds to the first View Controller, I am using a Stack View so the ScrollView's height can adjust depending on the content of the stack view. enter image description here

This Auto Layout corresponds to the Pinterest-like sub categories view controller. I am using the code employed by Ryan Wenderlich, however instead of using images, in both view controllers i'm using buttons so the user can go to the corresponding section. I add them programatically but always connected to the cell item prototype.

How can I make it so the Auto layout works for the Plus models? enter image description here

Vahid
  • 3,352
  • 2
  • 34
  • 42
Francisco Ruiz
  • 209
  • 3
  • 12

1 Answers1

1

I found your issue:

Every button have a title of Button and you should remove default title. that title pushed the button's image and because of title white color, you didn't see it.

You also can control image of UIButtons by Control > Alignment section look at the screen shot that I attached.

enter image description here

By the way, I recommend you to use UIImageView + UIButton over it instead of using UIButton's image content.

Edit

CollectionView is a totally mess! It will be eat a lot of RAM. You have a lot of cells over each other.

enter image description here

by the way, seems like your second view controller issue related to the stackviews that is not set constraint.

    cell.addSubview(stackView)

    NSLayoutConstraint(item: stackView, attribute: .centerX, relatedBy: .equal, toItem: cell, attribute: .centerX, multiplier: 1, constant: 0).isActive = true
    NSLayoutConstraint(item: stackView, attribute: .centerY, relatedBy: .equal, toItem: cell, attribute: .centerY, multiplier: 1, constant: 0).isActive = true

I just centered one of the stackviews and I founded out It's related to the constraint.

look at this like for setting Constraint programatically: Swift | Adding constraints programmatically

Vahid
  • 3,352
  • 2
  • 34
  • 42
  • Thanks a lot! It really helped me so much! and what about the second view controller? where there is a scroll view with a collection view like Pinterest? When I use it in the iPhone 8S and 7S models, it also looks very distorted – Francisco Ruiz May 23 '18 at 15:14