János
János

Reputation: 35050

How to make this grid layout

I need this grid layout, view structure with Storyboard. Is it an easier way to set up, or I need to calculate size / 4, and multiply it by the index, and calculate the center X, Y coordinates, and adjust NSLayoutConstraint at each rotation?

enter image description here

Upvotes: 2

Views: 76

Answers (2)

MD. Rejaul Hasan
MD. Rejaul Hasan

Reputation: 176

The above answer is perfect but we can also handle it by using storyboard.To explain I get 3 UIView into a stack view with below property.

enter image description here

Now when I go to landscape from portrait mode the height of the screen is converting to compact from regular.So we can change stack view axis from vertical to horizontal according to height change of the screen.below gif explain you visually.

enter image description here

for further information you can visit this link.

Upvotes: 0

Shehata Gamal
Shehata Gamal

Reputation: 100503

You can use UIStackView with default vertical and change it's axis to horizontal in landscape size class , with distribution Fill-Equally

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

    if UIDevice.current.orientation == .portrait
    {
        self.stackV.axis = .vertical
    }
    else
    {            
        self.stackV.axis = .horizontal
    }

}

Upvotes: 3

Related Questions