Is there a way to change the height of leftCalloutAccessoryView for MKAnnotationView?

I want to display more than 2 rows of data in a callout. Now I know that both the name of the annotation and the subtitles are limited to one line each.

Reading the following Apple documentation implies that if you subclass MKAnnotationView and override leftCalloutAccessoryView, you can create a custom callout view. This works, but it seems that the leader height is tied to some value. For example, no matter how big I do height , the call height is less.

Am I missing something? If not, what is a good alternative way to display additional information? I know about rightCalloutAccessory, but I would prefer not to hit the annotation and then click on the accessory to get a couple more lines of information.

 import UIKit class MyMKAnnotationView: MKAnnotationView { override var leftCalloutAccessoryView: UIView! { get { let height: CGFloat = 100.0 return UIView(frame: CGRectMake(0,0,50,height)) } set { } } } 

Subclass notes You can use the MKAnnotationView class as is or the subclass to provide custom behavior as needed. The class image property allows you to specify the appearance of the annotation without subclassing directly. You can also create custom subclasses as a convenience and use them to place annotations in a known state. For example, a subclass of MKPinAnnotationView initializes the contents of a pin image annotation view.

There are no special requirements for the MKAnnotationView subclass. However, the following list lists some reasons why you might want to subclass and some of the methods that you would override to implement your desired behavior:

To place the annotation view in a consistent state, provide a custom initialization method. Then your custom initialization method call initWithAnnotation: reuseIdentifier: to initialize the superclass.

To provide custom views, override leftCalloutAccessoryView and use it to return views.

If you support draggable annotations in iOS 4.0 and later, the subclass is responsible for changing the value in the dragState property to the corresponding values ​​at key transition points when dragging and dropping. See the description of this property for more information.

+5
source share

All Articles