I want to display more than 2 lines of data in a callout. I now know that both the annotation title and subtitles are limited to 1 line each.
Reading the following Apple documentation implies if you subclass MKAnnotationView and override leftCalloutAccessoryView you can create a custom callout view. This works but it seems like the height of the callout is fixed to some value. For example no matter how big I make height
the height of the call out is limited.
Am I missing something here? If not what is a good alternative way to display some addition info? I know about the rightCalloutAccessory, but I would rather not have to hit the annotation and then hit the accessory just to get a couple more lines of info.
import UIKit
class MyMKAnnotationView: MKAnnotationView {
override var leftCalloutAccessoryView: UIView! {
get {
let height: CGFloat = 100.0
return UIView(frame: CGRectMake(0,0,50,height))
}
set {
}
}
}
Subclassing Notes You can use the MKAnnotationView class as is or subclass it to provide custom behavior as needed. The image property of the class lets you set the appearance of the annotation view without subclassing directly. You might also create custom subclasses as a convenience and use them to put the annotation view in a known state. For example, the MKPinAnnotationView subclass initializes the contents of the annotation view to a pin image.
There are no special requirements for subclassing MKAnnotationView. However, the following list includes some reasons you might want to subclass and some of the methods you would override to implement the desired behavior:
To put the annotation view into a consistent state, provide a custom initialization method. Your custom initialization method would then call initWithAnnotation:reuseIdentifier: to initialize the superclass.
To provide custom callout views, override the leftCalloutAccessoryView method and use it to return the views.
If you support draggable annotation views in iOS 4.0 and later, your subclass is responsible for changing the value in the dragState property to appropriate values at key transition points in the drag operation. For more information, see the description of that property.