Closed styldimitriou closed 7 years ago
@stelarelas
If you want to achieve a tab bar where the images for selected/default are the same then don't provide Selected Icons
.
You can use:
let tabController = AZTabBarController.insert(into: self, withTabIconNames: icons)
// where icons is an array of string, where each string is the name of the image.
Or
let tabController = AZTabBarController.insert(into: self, withTabIcons: icons)
// where icons is an array of UIImage
As for the color you can set the default icon color and the highlighted icon color to be the same by doing:
let myColor: UIColor = ...
tabController.defaultColor = myColor
tabController.selectedColor = myColor
Thanks for the fast response.
Actually, I do want to display different images for default and selected status but I don't want to apply any color on them because of their design.
Please see the links bellow for better understanding of my issue.
https://www.dropbox.com/s/5usnktbze0s38r0/message-icon.png?dl=0 https://www.dropbox.com/s/va9pg16aaljbhmd/message-icon-selected.png?dl=0
@stelarelas I see, You have an image with a multi color pattern. Well at the moment this doesn't work but I can give you a temporary fix and hopefully in the future I will add this feature.
@stelarelas Replace this function with
private func customizeAsNormalButtonForTabBarWithImage(image: UIImage,highlightImage: UIImage? = nil, selectedColor: UIColor, defaultColor: UIColor? = UIColor.gray) {
// The tint color is the one used for selected state.
self.tintColor = selectedColor
// When the button is not selected, we show the image always with its
// original color.
self.setImage(image.imageWithColor(color: defaultColor!), for: [])
self.setImage(image.imageWithColor(color: defaultColor!), for: .highlighted)
if let hImage = highlightImage {
self.setImage(hImage.imageWithColor(color: selectedColor), for: .selected)
self.setImage(hImage.imageWithColor(color: selectedColor), for: [.selected, .highlighted])
}else{
self.setImage(image.imageWithColor(color: selectedColor), for: .selected)
self.setImage(image.imageWithColor(color: selectedColor), for: [.selected, .highlighted])
}
// We don't want a background color to use the one in the tab bar.
self.backgroundColor = UIColor.clear
}
This function:
private func customizeAsNormalButtonForTabBarWithImage(image: UIImage,highlightImage: UIImage? = nil, selectedColor: UIColor, defaultColor: UIColor? = UIColor.gray) {
// The tint color is the one used for selected state.
self.tintColor = selectedColor
self.setImage(image, for: [])
self.setImage(image, for: .highlighted)
if let hImage = highlightImage {
self.setImage(hImage, for: .selected)
self.setImage(hImage, for: [.selected, .highlighted])
}else{
self.setImage(image, for: .selected)
self.setImage(image, for: [.selected, .highlighted])
}
self.backgroundColor = UIColor.clear
}
Note that I haven't tested this, so this may not work, but it should get the work done.
I just did it a minute ago and it works perfectly!
Thanks a lot for your help!
You're welcome 😄
How can I set tab bar icon images without any default or selected color? I just want their images to be displayed for both default and selected status.