softhausHQ / CircleBar

A fun, easy-to-use tab bar navigation controller for iOS.
https://softhaus.org
MIT License
868 stars 64 forks source link

Change IconTintColor #20

Closed Timonator1606 closed 3 years ago

Timonator1606 commented 4 years ago

Is it possible to change the TintColor of the unselected Tabbar Icons? The only thing I get worked is to change the background colors and the color of the selected Icon.

Luccifer commented 4 years ago

Same here

carlos0193 commented 3 years ago

You need to change the class with this

    image?.withRenderingMode(.alwaysTemplate)
    UIColor.white.set() 

or the color that you want

    private func image(with image: UIImage?, scaledTo newSize: CGSize) -> UIImage? {
    image?.withRenderingMode(.alwaysTemplate)
    UIGraphicsBeginImageContextWithOptions(newSize, _: false, _: 0.0)
    UIColor.white.set()
    image?.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
    let newImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()

    return newImage
    }
Timonator1606 commented 3 years ago

Thx Carlos, but this is not working. As you can see in the pics the color is still the same. In the one pic I tried color "red" and in the other one "white". It's still the same dark gray.

IMG_0943 IMG_0942

Timonator1606 commented 3 years ago

Guys, I got it.

Just put this:

tabBar.unselectedItemTintColor = .white

directly under:

tabBar.select(itemAt: index, animated: true)

in the first open override var selectedViewController: UIViewController? { ... in SHCircleBarController.swift in the Pods file.

The beginning of SHCircleBarController.swift should look like this:

`fileprivate var shouldSelectOnTabBar = true private var circleView : UIView! private var circleImageView: UIImageView! open override var selectedViewController: UIViewController? { willSet { guard shouldSelectOnTabBar, let newValue = newValue else { shouldSelectOnTabBar = true return }

        guard let tabBar = tabBar as? SHCircleBar, let index = viewControllers?.firstIndex(of: newValue) else {return}

        tabBar.select(itemAt: index, animated: true)
        tabBar.unselectedItemTintColor = .white
    }`

Have a nice day.

carlos0193 commented 3 years ago

Thx Carlos, but this is not working. As you can see in the pics the color is still the same. In the one pic I tried color "red" and in the other one "white". It's still the same dark gray.

IMG_0943 IMG_0942

to change the color of the image you need

    image?.withRenderingMode(.alwaysTemplate)

or en assets on selected images you can change Render As: template image

Screen Shot 2021-01-26 at 7 51 12
carlos0193 commented 3 years ago

And try this to unselect Item

Chicos, lo tengo.

Solo pon esto:

tabBar.unselectedItemTintColor = .white

directamente debajo de:

tabBar.select(itemAt: index, animated: true)

en el primero open override var selectedViewController: UIViewController? { ...en SHCircleBarController.swift en el archivo Pods.

El comienzo de SHCircleBarController.swift debería verse así:

`fileprivate var shouldSelectOnTabBar = true private var circleView: UIView! private var circleImageView: UIImageView! abrir override var selectedViewController: UIViewController? { willSet { guard shouldSelectOnTabBar, let newValue = newValue else { shouldSelectOnTabBar = true return }

        guard let tabBar = tabBar as? SHCircleBar, let index = viewControllers?.firstIndex(of: newValue) else {return}

        tabBar.select(itemAt: index, animated: true)
        tabBar.unselectedItemTintColor = .white
    }`

Que tengas un buen día.