问题
I'm trying to implement this (https://www.youtube.com/watch?v=ILiBXYscsyY) Custom InfoWindow tutorial that was done for Objective-C in Swift 2.0. I have tried doing this by just mix-matching Objective-C and Swift code, but I have been unsuccessful in translating
- (UIView *) mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
CustomInfoWindow *infoWindow = [[[NSBundle MainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];
infoWindow.name.text = @"Syndey Opera House";
infoWindow.address.text = @"Bennelong Point, Sydney";
infoWindow.photo.image = [UIImage imageNamed:@"SydneyOperaHouseAtNight"];
return infoWindow;
}
into Swift. This part of the tutorial can be found at 3:07 of the video.
I'd like some help in translating this tutorial into Swift 2.0 or if anyone knows of a good tutorial of this for Swift 2.0 that would be much appreciated.
回答1:
Here is the swift code for the above:
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindow", owner: self, options: nil).first as! CustomInfoWindow
infoWindow.name.text = "Sydney Opera House"
infoWindow.address.text = "Bennelong Point Sydney"
infoWindow.photo.image = UIImage(named: "SydneyOperaHouseAtNight")
return infoWindow
}
回答2:
Here is the code for Swift3:
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let infoWindow = Bundle.main.loadNibNamed("InfoWindow", owner: self, options: nil)?.first as! CustomInfoWindow
infoWindow.name.text = "Sydney Opera House"
infoWindow.address.text = "Bennelong Point Sydney"
infoWindow.photo.image = UIImage(named: "SydneyOperaHouseAtNight")
return infoWindow
}
来源:https://stackoverflow.com/questions/34488506/custom-infowindow-for-marker-google-maps-sdk-swift-2-0