我正在尝试使用 UIKit 设置地图,使用 SF 符号作为注释。到目前为止,一切都很好。
问题是符号是黑色的,我想将颜色更改为白色。
annotationView.image = UIImage(systemName: "23.circle.fill")!.withTintColor(.white, renderingMode: .alwaysTemplate)
Run Code Online (Sandbox Code Playgroud)
不做这项工作。事实上,如果我使用普通的 Pin 图,我就可以改变颜色。
它只是不适用于 SF Symbols。
这是我的代码
annotationView.image = UIImage(systemName: "23.circle.fill")!.withTintColor(.white, renderingMode: .alwaysTemplate)
Run Code Online (Sandbox Code Playgroud)
我还尝试使用以下代码通过 UIImage 扩展更改它:
import SwiftUI
import MapKit
import UIKit
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let myMapView = MKMapView(frame: .zero)
return myMapView
}
func updateUIView(_ view: MKMapView, context: Context) {
let coordinate = CLLocationCoordinate2D(latitude: 49.289912, longitude: 19.764172)
let span = MKCoordinateSpan(latitudeDelta: 0.027, longitudeDelta: 0.027)
let region = MKCoordinateRegion(center: coordinate, span: span) …Run Code Online (Sandbox Code Playgroud)