I have a storyboard in which there is a separate view controller for a UIView. In that UIView I have to load 10 buttons in a single row in the case of IPad else I have to load 10 buttons in two rows. I have tried using 2 separate xib files and loading them statically but I want to do it programatically using view controllers.
I have added the screenshot of my storyboard.
Can anybody guide me on changing the views dynamically.Here is the code of the new ViewController for the buttons.
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 {
//
//
}
}
}
Thanks in Advance