Reputation: 12915
Xcode 6 supports the "universal" storyboard. This is very convenient. That means we only need one storyboard for iPhone and iPad if the layout of iPhone and iPad are the same.But here comes a question:
What if most of the layouts of iPhone and iPad are the same, only a few differences in only one or two UIViewControllers? How can we add different UIViewControllers in the same storyboard for iPhone and iPad?
Upvotes: 2
Views: 1448
Reputation: 12915
Here is what I did:
My code: (Add to navigation bar if in iPad. And add to the container view and also set the constants of the constraint to 0)
class ViewController: UIViewController {
var segmentControl : UISegmentedControl!
@IBOutlet weak var segContainer: UIView!
@IBOutlet weak var heightConstrains: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
self.segmentControl = UISegmentedControl(items: ["Personnal", "Department", "Company"]) as UISegmentedControl
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
self.navigationItem.titleView = self.segmentControl
self.heightConstrains.constant = 0
} else {
self.segContainer.addSubview(self.segmentControl)
}
}
My case is quite simple. So it's not difficult to implement in code. But what about the very complicated case?
Upvotes: 1