import MapKitclass OSMapView: MKMapView, MKMapViewDelegate {override init(frame: CGRect) {super.init(frame: frame)self.setup()self.delegate = self;}required init?(coder aDecoder: NSCoder) {super.init(coder: aDecoder);self.setup()self.delegate = self;}func setup() {let template = "http://tile.openstreetmap.org/{z}/{x}/{y}.png"let overlay = MKTileOverlay(urlTemplate: template)overlay.canReplaceMapContent = trueself.add(overlay, level: .aboveLabels)}func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {guard let tileOverlay = overlay as? MKTileOverlay else {return MKOverlayRenderer()}return MKTileOverlayRenderer(tileOverlay: tileOverlay)}
}
記得要修改info.plist
NSExceptionDomains
沒有留言:
張貼留言