OGeek|极客世界-中国程序员成长平台

标题: ios - 如何制作这个网格布局 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:38
标题: ios - 如何制作这个网格布局

我需要这个网格布局,带有 Storyboard 的 View 结构。是不是更容易设置,还是我需要计算size/4,乘以index,计算中心X、Y坐标,每次旋转调整NSLayoutConstraint? p>

enter image description here



Best Answer-推荐答案


您可以将 UIStackView 与默认垂直使用并在横向尺寸类中将其轴更改为水平,分布 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
    }

}

关于ios - 如何制作这个网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49388345/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4