Advertisement
srk72

Tab indicator for tabbar

Jun 2nd, 2022 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.94 KB | None | 0 0
  1. let tabbar = self.tabBarController?.tabBar
  2.         tabbar?.selectionIndicatorImage = UIImage().createSelectionIndicator(color: bColor, size: CGSize(width: (tabbar?.items![0].selectedImage?.size.width)!, height: (tabbar?.frame.height)!), lineWidth: 2.0)
  3.  
  4. extension UIImage
  5. {
  6.     func createSelectionIndicator(color: UIColor, size: CGSize, lineWidth: CGFloat) -> UIImage
  7.     {
  8.         UIGraphicsBeginImageContextWithOptions(size, false, 0)
  9.         color.setFill()
  10.        
  11.         var yFloatValue: CGFloat
  12.        
  13.         if size.height < 80
  14.         {
  15.             yFloatValue = (size.height * 0.90 - lineWidth)
  16.         }
  17.         else
  18.         {
  19.             yFloatValue = (size.height * 0.55 - lineWidth)
  20.         }
  21.        
  22.         UIRectFill(CGRect(x: 0, y: yFloatValue, width: size.width, height: lineWidth))
  23.         let image = UIGraphicsGetImageFromCurrentImageContext()
  24.         UIGraphicsEndImageContext()
  25.         return image!
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement