diff --git a/Source/ARSPopover.h b/Source/ARSPopover.h index 134fe8a..7b3e825 100644 --- a/Source/ARSPopover.h +++ b/Source/ARSPopover.h @@ -40,6 +40,9 @@ /// Use this property to configure where popover's arrow should be pointing. @property (nonatomic, assign) UIPopoverArrowDirection arrowDirection; +/// The bar button item on which to anchor the popover. +@property (nonatomic, assign) UIBarButtonItem *barButtonItem; + /// The view containing the anchor rectangle for the popover. @property (nonatomic, weak) UIView *sourceView; diff --git a/Source/ARSPopover.m b/Source/ARSPopover.m index 60a47cd..66600ce 100644 --- a/Source/ARSPopover.m +++ b/Source/ARSPopover.m @@ -68,8 +68,13 @@ - (void)insertContentIntoPopover:(void (^)(ARSPopover *popover, CGSize popoverPr #pragma mark - Popover Presentation Controller Delegate - (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController { - self.popoverPresentationController.sourceView = self.sourceView ? self.sourceView : self.view; - self.popoverPresentationController.sourceRect = self.sourceRect; + if (self.barButtonItem) { + self.popoverPresentationController.barButtonItem = self.barButtonItem; + } else { + self.popoverPresentationController.sourceView = self.sourceView ? self.sourceView : self.view; + self.popoverPresentationController.sourceRect = self.sourceRect; + } + self.preferredContentSize = self.contentSize; popoverPresentationController.permittedArrowDirections = self.arrowDirection ? self.arrowDirection : UIPopoverArrowDirectionAny;