字形图像不会改变颜色
Glyph images won't change colors
问题:我有来自同一站点的三个字形 (icons8.com),当我尝试将它们设置为相同的颜色时,只有 1 个可以正常工作。
深入:
所以我试图让一些字形改变颜色。有些有效,有些无效。
在这里您可以看到字形正确设置为 "yellow" 色调
但是当我转到调用相同颜色过程的不同视图时,它不起作用。咖啡和啤酒标志上的字形保持黑色(这两个不起作用),但足球设置正确。提醒一下,全部设置为黄色。
这是我在正常 cellForRowAt
.
单元格中设置字形颜色的代码
cell.iconView.backgroundColor = eventAnnotation.markerTintColor
cell.iconImageView.image = UIImage(named: eventAnnotation.imageName ?? "")
cell.iconImageView.tintColor = eventAnnotation.glyphTintColor
这是我正在使用创建标记的视图。
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
}
}
}
我还将附上我正在使用的不同字形集。
我终于找到了答案。我不得不强制图像(注意第二行)始终使用我的模板。
cell.iconView.backgroundColor = eventAnnotation.markerTintColor
cell.iconImageView.image = UIImage(named: eventAnnotation.imageName ?? "")?.withRenderingMode(.alwaysTemplate)
cell.iconImageView.tintColor = eventAnnotation.glyphTintColor
这是 .withRenderingMode 的苹果文档。
问题:我有来自同一站点的三个字形 (icons8.com),当我尝试将它们设置为相同的颜色时,只有 1 个可以正常工作。
深入: 所以我试图让一些字形改变颜色。有些有效,有些无效。
在这里您可以看到字形正确设置为 "yellow" 色调
但是当我转到调用相同颜色过程的不同视图时,它不起作用。咖啡和啤酒标志上的字形保持黑色(这两个不起作用),但足球设置正确。提醒一下,全部设置为黄色。
这是我在正常 cellForRowAt
.
cell.iconView.backgroundColor = eventAnnotation.markerTintColor
cell.iconImageView.image = UIImage(named: eventAnnotation.imageName ?? "")
cell.iconImageView.tintColor = eventAnnotation.glyphTintColor
这是我正在使用创建标记的视图。
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
}
}
}
我还将附上我正在使用的不同字形集。
我终于找到了答案。我不得不强制图像(注意第二行)始终使用我的模板。
cell.iconView.backgroundColor = eventAnnotation.markerTintColor
cell.iconImageView.image = UIImage(named: eventAnnotation.imageName ?? "")?.withRenderingMode(.alwaysTemplate)
cell.iconImageView.tintColor = eventAnnotation.glyphTintColor
这是 .withRenderingMode 的苹果文档。