I want to make Tab bar like app store UIKit

86 Views Asked by At

enter image description here

I want the same color as in App Store. Gradient and background color and selected color and unselected color all the same.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    tabBar.barTintColor = .clear
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.lightGray.withAlphaComponent(0.5)], for: .normal)
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white.withAlphaComponent(0.7)], for: .selected)
    if #available(iOS 13.0, *) {
        var appearance = tabBar.standardAppearance

        // Set a more transparent background with a blur effect
        appearance.backgroundEffect = UIBlurEffect(style: .systemMaterial)

        // Set tab bar item colors
        setTabBarItemColors(appearance.stackedLayoutAppearance)
        setTabBarItemColors(appearance.inlineLayoutAppearance)
        setTabBarItemColors(appearance.compactInlineLayoutAppearance)

        // Set tab bar item badge appearance
        setTabBarItemBadgeAppearance(appearance.stackedLayoutAppearance)
        setTabBarItemBadgeAppearance(appearance.inlineLayoutAppearance)
        setTabBarItemBadgeAppearance(appearance.compactInlineLayoutAppearance)

        tabBar.standardAppearance = appearance
    } else {
        // Fallback for earlier iOS versions if needed
    }
}

@available(iOS 13.0, *)
private func setTabBarItemColors(_ itemAppearance: UITabBarItemAppearance) {
    // Set colors for normal and selected states
    itemAppearance.normal.iconColor = .systemGray
    itemAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.systemGray.withAlphaComponent(0.5)]

    itemAppearance.selected.iconColor = .label
    itemAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.label.withAlphaComponent(0.7)]
}

@available(iOS 13.0, *)
private func setTabBarItemBadgeAppearance(_ itemAppearance: UITabBarItemAppearance) {
    // Set badge background color, text color, and position adjustment
    itemAppearance.normal.badgeBackgroundColor = .systemRed
    itemAppearance.normal.badgeTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    itemAppearance.normal.badgePositionAdjustment = UIOffset(horizontal: 1, vertical: -1)
}

I want a tab bar like app store but with this code I am getting it. enter image description here

0

There are 0 best solutions below