title: override traitCollection in iOS 13
body: <p>In my initial view controller, I have have a <code>UITabbarController</code> as a child view controller.</p>
  
  <p>I want to have <code>UITabbarController</code> to display its <code>UITabbar</code> with traitCollection having horizontalSizeClass of Compact so that in the tabbar, image and title appears vertically aligned and not side by side.</p>
  
  <p>Overriding the traitCollection getter of UITabbarController is now not supported in iOS13, 
  Xcode gives below warning.</p>
  
  <pre class="lang-swift prettyprint-override"><code>        override var traitCollection: UITraitCollection{
              let current = super.traitCollection
              let compact = UITraitCollection(horizontalSizeClass: .compact)
              return UITraitCollection(traitsFrom: [current, compact])
          }
  </code></pre>
  
  <blockquote>
    <p>Class MyTabbarController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.</p>
  </blockquote>
  
  <p>After researching for appropriate API, I found</p>
  
  <pre class="lang-swift prettyprint-override"><code>open func setOverrideTraitCollection(_ collection: UITraitCollection?, forChild childViewController: UIViewController)
  </code></pre>
  
  <p>After implementing this I am able to override trait collection of myTabbarController but only after the view has changed orientation. This API is only working if I override viewWillTransition to method.</p>
  
  <pre class="lang-swift prettyprint-override"><code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
          super.viewWillTransition(to: size, with: coordinator)
          let currentTC = traitCollection
          let compactTC = UITraitCollection(horizontalSizeClass: .compact)
          let custom = UITraitCollection(traitsFrom: [currentTC, compactTC])
          print("ovverride trait collections before transition")
          setOverrideTraitCollection(custom, forChild: tabController)
      }
  </code></pre>
  
  <p>I am only able to override the traits when the device is rotated. This API is not working if I try to override the trait collection in any other view controller lifecycle method. How do I override the traitCollection when the view is initially loaded?
  I tried using the same code in the <code>viewDidLoad()</code> method of my initial view controller but it has no effect.</p>