diff --git a/README.md b/README.md index a747875..d47d8f0 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ All possible properties: pin_color: :red, # Defaults to :red. Other options are :green or :purple or any MKPinAnnotationColor left_accessory: my_button, right_accessory: my_other_button, + detail_accessory: my_custom_view, action: :my_action, # Overrides :right_accessory action_button_type: UIButtonTypeContactAdd # Defaults to UIButtonTypeDetailDisclosure } @@ -119,6 +120,8 @@ Use `:image` to specify a custom image. Pass in a string to conserve memory and Use `:left_accessory` and `:right_accessory` to specify a custom accessory, like a button. +Use `:detail_accessory` to specify a detail accessory that will be positioned below the title, any UIView will work. This will override `:subtitle`. Available from iOS 9.0. + You can access annotation data you've arbitrarily stored in the hash by calling `annotation_instance.params[:your_param]`. The `:action` parameter specifies a method that should be run when the detail button is tapped on the annotation. It automatically adds a `UIButtonTypeDetailDisclosure` button to the `:left_accessory`. In your method you can find out which annotation's accessory was tapped by calling `selected_annotations.first`. diff --git a/lib/ProMotion/map/map_screen_module.rb b/lib/ProMotion/map/map_screen_module.rb index e51367a..d11d409 100644 --- a/lib/ProMotion/map/map_screen_module.rb +++ b/lib/ProMotion/map/map_screen_module.rb @@ -163,6 +163,9 @@ def annotation_view(map_view, annotation) if params[:right_accessory] view.rightCalloutAccessoryView = params[:right_accessory] end + if params[:detail_accessory] + view.detailCalloutAccessoryView = params[:detail_accessory] + end if params[:action] button_type = params[:action_button_type] || UIButtonTypeDetailDisclosure diff --git a/spec/func_map_screen_spec.rb b/spec/func_map_screen_spec.rb index 24c2b8e..9a093a7 100644 --- a/spec/func_map_screen_spec.rb +++ b/spec/func_map_screen_spec.rb @@ -196,6 +196,21 @@ def add_image_annotation v.rightCalloutAccessoryView.should == btn end + it "should allow setting a detailCalloutAccessoryView" do + img = UIImageView.alloc.initWithImage(UIImage.imageNamed("test.png")) + ann = { + longitude: -82.965972900392, + latitude: 35.090648651124, + title: "My Cool Image Pin", + detail_accessory: img + } + map_screen.add_annotation ann + annot = map_screen.annotations.last + annot.should.be.kind_of?(ProMotion::MapScreenAnnotation) + v = map_screen.annotation_view(map_screen.view, annot) + v.detailCalloutAccessoryView.should == img + end + it "should call the correct action when set on an annotation" do ann = default_annotation.merge({ action: :my_action