0

I try to set a indicator line on the top of the item tab bar, I set tabBar.frame.minY and sum line height but I can't get it.

class TabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()

      self.tabBar.selectionIndicatorImage = UIImage().createSelectionIndicator(color: UIColor.secondary, size:  CGSize(width: tabBar.frame.width/CGFloat(tabBar.items!.count), height: tabBar.frame.height), lineHeight: 2.0)

  }
}

extension UIImage {
  func createSelectionIndicator(color: UIColor, size: CGSize, lineHeight: CGFloat) -> UIImage {
    UIGraphicsBeginImageContextWithOptions(size, false, 0)
    color.setFill()
    UIRectFill(CGRect(origin: CGPoint(x: 0,y : size.height - lineHeight ), size: CGSize(width: size.width, height: lineHeight)))
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image!
  }
}

What is the way to do that ?

I expected something like this:

enter image description here

LgSus97
  • 93
  • 9

0 Answers0