2015-12-28 55 views
3

我想實現的是在雨燕2.0 Objective-C的做到了這一點(https://www.youtube.com/watch?v=ILiBXYscsyY)自定義信息窗口教程。我曾嘗試做這只是混合匹配的Objective-C和斯威夫特的代碼,但是我在翻譯自定義信息窗口的標誌谷歌地圖SDK,雨燕2.0

- (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; 
} 

到斯威夫特是不成功的。本教程的這一部分可以在視頻的3:07處找到。

我想在翻譯本教程到Swift 2.0中有一些幫助,或者如果有人知道Swift 2.0的一個很好的教程,將不勝感激。

回答

3

以下是上述的SWIFT代碼:

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 
    } 
4

這裏是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 
}