我有一个 Storyboard,其中有一个用于 UIView 的单独 View Controller 。在 UIView 中,我必须在单行中加载 10 个按钮,而在 iPad 中,我必须在两行中加载 10 个按钮。我尝试过使用 2 个单独的 xib 文件并静态加载它们,但我想使用 View Controller 以编程方式执行此操作。 我添加了 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/