Reputation: 2827
Problem: I have three glyphs from the same site (icons8.com) and when I try to set them to the same color, only 1 works properly.
In-Depth: So I am attempting to get some glyphs to change colors. Some work, and some don't.
Here you can see that the glyphs are setting properly to a "yellow" tint
But then when I go to a different view that calls the same color procedure, it doesn't work. The glyphs stay black on the coffee and beer sign (the two that do not work), but the soccer ball sets properly. Reminder, all are being set to yellow.
This is the code I am using the set the glyph color in the cell within the normal cellForRowAt
.
cell.iconView.backgroundColor = eventAnnotation.markerTintColor
cell.iconImageView.image = UIImage(named: eventAnnotation.imageName ?? "")
cell.iconImageView.tintColor = eventAnnotation.glyphTintColor
Here is the view that I am using the create the markers.
class EventMarkerView: MKMarkerAnnotationView {
override var annotation: MKAnnotation? {
willSet {
guard let eventAnnotation = newValue as? EventAnnotation else { return }
canShowCallout = true
calloutOffset = CGPoint(x: -5, y: 5)
rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
markerTintColor = eventAnnotation.markerTintColor
glyphTintColor = eventAnnotation.glyphTintColor
//glyphText = String(event.discipline.first!)
if let imageName = eventAnnotation.imageName {
glyphImage = UIImage(named: imageName)
} else {
glyphImage = nil
}
let detailLabel = UILabel()
detailLabel.numberOfLines = 3
detailLabel.font = detailLabel.font.withSize(12)
detailLabel.text = eventAnnotation.subtitle
detailCalloutAccessoryView = detailLabel
}
}
}
I will also attach the different sets of glyphs I am using.
"Soccer ball outline". Does work .
Upvotes: 1
Views: 502
Reputation: 2827
I found the answer eventually. I had to force the image (note the second line) to always use my template.
cell.iconView.backgroundColor = eventAnnotation.markerTintColor
cell.iconImageView.image = UIImage(named: eventAnnotation.imageName ?? "")?.withRenderingMode(.alwaysTemplate)
cell.iconImageView.tintColor = eventAnnotation.glyphTintColor
Here is the apple documentation for .withRenderingMode.
Upvotes: 1