I am working in a application where i need to add underline in UITabbarItem
.
so i would like to add underline under the selected UITabbarItem
i
Code for Swift 3
In didFininshLaunch call method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UITabBar.appearance().selectionIndicatorImage = getImageWithColorPosition(color: UIColor.blue, size: CGSize(width:(self.window?.frame.size.width)!/4,height: 49), lineSize: CGSize(width:(self.window?.frame.size.width)!/4, height:2))
return true
}
Method:
func getImageWithColorPosition(color: UIColor, size: CGSize, lineSize: CGSize) -> UIImage {
let rect = CGRect(x:0, y: 0, width: size.width, height: size.height)
let rectLine = CGRect(x:0, y:size.height-lineSize.height,width: lineSize.width,height: lineSize.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
UIColor.clear.setFill()
UIRectFill(rect)
color.setFill()
UIRectFill(rectLine)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}