2015-10-21 9 views
7

मैंने पारंपरिक लाल पिन की बजाय व्यक्तिगत छवि डाली। जब मैं पिन प्रदर्शित करने के लिए मानचित्र खोलता हूं, तो छवि पूरे मानचित्र को कवर करती है। क्या पिन छवि का अधिकतम आकार है या आकार मानक क्लासिक पिन फिट करने के लिए कोड में कुछ कैसे एकीकृत किया जाए?आकार छवि पिन एनोटेशन

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
    if annotation is MKUserLocation { 
     return nil 
    } 

    let annotationIdentifier = "SomeCustomIdentifier" // use something unique that functionally identifies the type of pin 

    var annotationView: MKAnnotationView! = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) 

    if annotationView != nil { 
     annotationView.annotation = annotation 
    } else { 
     annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) 

     annotationView.image = UIImage(named: "pin maps.png") 

     annotationView.canShowCallout = true 
     annotationView.calloutOffset = CGPointMake(-8, 0) 

     annotationView.autoresizesSubviews = true 
     annotationView.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView 
    } 

    return annotationView 
} 

उत्तर

19

पिन छवि का अधिकतम आकार नहीं है। आपको UIImage का आकार बदलने की जरूरत है।

let annotationIdentifier = "SomeCustomIdentifier" 
    var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) 
    if annotationView == nil { 
     annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) 
     annotationView?.canShowCallout = true 

     // Resize image 
     let pinImage = UIImage(named: "pin maps.png") 
     let size = CGSize(width: 50, height: 50) 
     UIGraphicsBeginImageContext(size) 
     pinImage!.drawInRect(CGRectMake(0, 0, size.width, size.height)) 
     let resizedImage = UIGraphicsGetImageFromCurrentImageContext() 
     UIGraphicsEndImageContext() 

     annotationView?.image = resizedImage 

     let rightButton: AnyObject! = UIButton(type: UIButtonType.DetailDisclosure) 
     annotationView?.rightCalloutAccessoryView = rightButton as? UIView 
    } 
    else { 
     annotationView?.annotation = annotation 
    } 
+0

यह कहता है ** CGRectMake ** pinImage.draw (में: CGRect (एक्स: 0, y: 0, चौड़ाई: size.width, ऊंचाई: size.height)) swft – Saneth

+0

में नहीं है –

+0

मैं करूंगा उपयोग करें: anView? .frame.size = CGSize (चौड़ाई: 30, ऊंचाई: 40) सभी drawContext सामग्री के बजाय –

संबंधित मुद्दे