title: Present a popover from a UITabBarItem in swift
body: <p>I found a lot of examples showing how to present a popover from a UIBarButtonItem, but I want to know how to present it from a UITabBarItem instead. </p>
  
  <p>Here's what I have so far</p>
  
  <pre><code>let selectedItem = self.menuTabBar.items![3]    
  
  let menuViewController: ActivityPopoverViewController = storyboard.instantiateViewControllerWithIdentifier("MenuViewController") as! ActivityPopoverViewController
  presentViewController(menuViewController, animated: true, completion: nil)
  menuViewController.modalPresentationStyle = .Popover
  
  
  if let popoverMenuViewController = menuViewController.popoverPresentationController {
      popoverMenuViewController.permittedArrowDirections = .Any
      popoverMenuViewController.delegate = menuViewController
  
  
  //  popoverMenuViewController.barButtonItem = ?
  }
  </code></pre>
  
  <p>I tried to convert selectedItem which is a UITabBarItem into a UIBarButtonItem but that didn't work. I'm sure it's a simple process, but I can't seem to find any help on how to do it. </p>
  
  <p>My goal is to have this orange popover indicating unread activity. </p>
  
  <p><a href="https://i.stack.imgur.com/4hda3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4hda3.jpg" alt="enter image description here"></a></p>
  
  <p>Update #1. After doing more research, I discovered this strategy to present the view controller</p>
  
  <pre><code>let tabBarItemWidth = Int(self.menuTabBar.frame.size.width) / (self.menuTabBar.items?.count)!
  let x = tabBarItemWidth * 3;
  let newRect = CGRect(x: x, y: 0, width: tabBarItemWidth, height: Int(self.menuTabBar.frame.size.height))
  print(newRect)
  
  let menuViewController: ActivityPopoverViewController = storyboard.instantiateViewControllerWithIdentifier("ActivityPopoverViewController") as! ActivityPopoverViewController
  menuViewController.modalPresentationStyle = .Popover
  
  
  if let popoverMenuViewController = menuViewController.popoverPresentationController {
      popoverMenuViewController.permittedArrowDirections = .Down
      popoverMenuViewController.delegate = menuViewController
      popoverMenuViewController.sourceRect = newRect
      popoverMenuViewController.sourceView = self.menuTabBar
      presentViewController(menuViewController, animated: true, completion: nil)
  
  }
  </code></pre>
  
  <p>and now my popover is being displayed, but the bounds from newRect aren't working. The popover takes over the entire screen instead of being restricted to the new bounds. Does anyone know how to force the new dimensions?</p>
  
  <p>Update #2</p>
  
  <p>Working Code</p>
  
  <pre><code>let tabBarItemWidth = Int(self.menuTabBar.frame.size.width) / (self.menuTabBar.items?.count)!
  let x = tabBarItemWidth * 3;
  let newRect = CGRect(x: x, y: 0, width: tabBarItemWidth, height: Int(self.menuTabBar.frame.size.height))
  print(newRect)
  
  let menuViewController: ActivityPopoverViewController = storyboard.instantiateViewControllerWithIdentifier("ActivityPopoverViewController") as! ActivityPopoverViewController
  menuViewController.modalPresentationStyle = .Popover
  menuViewController.view.frame = newRect
  menuViewController.preferredContentSize = CGSizeMake(150, 150)
  
  if let popoverMenuViewController = menuViewController.popoverPresentationController {
      popoverMenuViewController.permittedArrowDirections = .Down
      popoverMenuViewController.delegate = menuViewController
      popoverMenuViewController.sourceRect = newRect
      popoverMenuViewController.sourceView = self.menuTabBar
  
      presentViewController(menuViewController, animated: true, completion: nil)
  
  }
  </code></pre>