ios - 在 iPad 上用单 StackView 替换双 StackView?

标签 ios swift uiviewcontroller stackview

我有一个 Storyboard,其中有一个用于 UIView 的单独 View Controller 。在 UIView 中,我必须在单行中加载 10 个按钮,而在 iPad 中,我必须在两行中加载 10 个按钮。我尝试过使用 2 个单独的 xib 文件并静态加载它们,但我想使用 View Controller 以编程方式执行此操作。 Storyboard Image 我添加了 Storyboard的屏幕截图。

任何人都可以指导我动态更改 View 。这是按钮的新 ViewController 的代码。

import Foundation

 class TNPSRatingsViewController: UIViewController {

    var selectedScoreButton: TNPSScoreButton?
    var scoreSelectedOnce = false

    @IBOutlet var buttons: [TNPSScoreButton]!


    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.modifyPositionOfTNPSButton()
    }

    override func viewWillTransition(to size: CGSize,
                                     with coordinator: UIViewControllerTransitionCoordinator) {
        coordinator.animate(alongsideTransition: nil, completion: ({ [unowned self] _ in
            self.modifyPositionOfTNPSButton()

        }))
    }


    // MARK: - Private functions
    fileprivate func modifyPositionOfTNPSButton() {
        if UIApplication.shared.delegate?.window??.traitCollection.horizontalSizeClass == .compact {
            //
            //
        } else {
            //
            //

        }
    }



}

提前致谢

最佳答案

使用 UICollectionView 怎么样?

在 iPad 上,使用 1 行,每行 10 个项目 在 iPhone 上使用 2 行,每行 5 个项目

您可以坚持 View Controller 包含,或直接使用您的第一个屏幕作为委托(delegate)/数据源来实现 uicollectionview。

关于ios - 在 iPad 上用单 StackView 替换双 StackView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49269477/

相关文章:

ios - 应用程序无法安装在 iOS 7 上

ios - 基于一个订购两个 NSMutableArrays

mysql - Vapor MySQL - 未显示为导入值

ios - 如何自动更新应用程序 iOS 应用程序

ios - 嵌入 segue - 动态切换初始 UIViewController 和包含的 UIViewController

ios - 呈现新的 ViewController 后 Deinit UITabBarController

ios - Objective-C : Segue back to root from NSObject class

ios - 带有大图像的 UITableViewCell 不流畅

android - 第一次使用 jquery mobile 加载页面后事件不起作用

arrays - 如何扩展 Array<Double>?