The title pretty much explained it. Is it possible? I have tried to assign it like this:
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveAnnotation:)];
pinView.leftCalloutAccessoryView = leftButton;
I have also tried casting it as a UIButton and as a UIView. The main reason I want this is because I want that little savebutton already intergrated in UIBarButtonSystemItemSave. How may I achieve this?
No, it’s not possible mainly because
UIBarButtonItemis not a subclass ofUIView.Casting it to a
UIButtonorUIViewdoesn’t work because casting does not convert an object from one type to another. It just let’s you inform the compiler that some variable can be treated as some other type (if that variable isn’t really of that other type, you’ll get an exception or it just won’t work).UIBarButtonItemis a subclass ofUIBarItem(which is a subclass ofNSObject) and is designed for use only in aUIToolbarorUINavigationBar.I don’t recommend trying to put a
UIToolbarin a callout just to useUIBarButtonItem.Here’s a look-alike workaround using UISegmentedControl but a segmented control may not look right in a callout either.
I suggest using a regular
UIButtonwith a custom image or with button typeUIButtonTypeContactAdd(blue circle with plus sign).