Custom InfoWindow for marker Google Maps SDK, Swift 2.0

流过昼夜 提交于 2020-01-02 08:42:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!