这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions lib/ProMotion/map/map_screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, will this raise a No Method error in iOS earlier than 9.0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. it actually kind of works using UIImageView.alloc.initWithImage(UIImage.imageNamed("Default-568h"))as the view
screen shot 2016-04-15 at 18 22 12

end

if params[:action]
button_type = params[:action_button_type] || UIButtonTypeDetailDisclosure
Expand Down
15 changes: 15 additions & 0 deletions spec/func_map_screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down