From 9c14b9fa6a5b99908a432cad694a9cab5f67dff0 Mon Sep 17 00:00:00 2001 From: Olivier Rousseau Date: Mon, 16 Feb 2015 11:40:48 -0500 Subject: [PATCH] Added a anchorMargin property so we can set this attribute if needed for custom SMCalloutBackgroundView. Default is still 27. --- SMCalloutView.h | 1 + SMCalloutView.m | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SMCalloutView.h b/SMCalloutView.h index a5d9d90..d11515a 100755 --- a/SMCalloutView.h +++ b/SMCalloutView.h @@ -92,6 +92,7 @@ extern NSTimeInterval const kSMCalloutViewRepositionDelayForUIScrollView; @property (nonatomic, assign) BOOL highlighted; // will be set by the callout when the callout is in a highlighted state @property (nonatomic, assign) CALayer *contentMask; // returns an optional layer whose contents should mask the callout view's contents (not honored by SMClassicCalloutView) @property (nonatomic, strong) NSNumber *anchorHeight; //The arrow height, useful for custom background view with custom arrow +@property (nonatomic, assign) CGFloat anchorMargin; // the smallest possible distance from the edge of our control to the "tip" of the anchor, from either left or right @end // Default for iOS 7, this reproduces the "masked" behavior of the iOS 7-style callout view. diff --git a/SMCalloutView.m b/SMCalloutView.m index afab03e..12f5db2 100755 --- a/SMCalloutView.m +++ b/SMCalloutView.m @@ -25,8 +25,6 @@ @interface UIView (SMFrameAdditions) #define SUBTITLE_TOP 28 // the top of the subtitle, when present #define SUBTITLE_HEIGHT 15 // subtitle height, fixed #define BETWEEN_ACCESSORIES_MARGIN 7 // margin between accessories when no title/subtitle is present -#define CONTENT_VIEW_MARGIN 12 // margin around content view when present, can be overridden with contentViewInset -#define ANCHOR_MARGIN 27 // the smallest possible distance from the edge of our control to the "tip" of the anchor, from either left or right #define DEFAULT_ANCHOR_HEIGHT 13 // effective height of the anchor, will be overriden by anchorHeight propertiy of the SMCalloutBackgroundView if asigned. #define TOP_ANCHOR_MARGIN 13 // all the above measurements assume a bottom anchor! if we're pointing "up" we'll need to add this top margin to everything. #define COMFORTABLE_MARGIN 10 // when we try to reposition content to be visible, we'll consider this margin around your target rect @@ -329,8 +327,8 @@ - (void)presentCalloutFromRect:(CGRect)rect inLayer:(CALayer *)layer ofView:(UIV calloutX = constrainedRect.origin.x+constrainedRect.size.width-self.$width; // what's the farthest to the left and right that we could point to, given our background image constraints? - CGFloat minPointX = calloutX + ANCHOR_MARGIN; - CGFloat maxPointX = calloutX + self.$width - ANCHOR_MARGIN; + CGFloat minPointX = calloutX + self.backgroundView.anchorMargin; + CGFloat maxPointX = calloutX + self.$width - self.backgroundView.anchorMargin; // we may need to scoot over to the left or right to point at the correct spot CGFloat adjustX = 0; @@ -588,6 +586,8 @@ - (id)initWithFrame:(CGRect)frame { grayArrowImage = [self image:blackArrowImage withColor:[UIColor colorWithWhite:0.85 alpha:1]]; } + self.anchorMargin = 27; + self.arrowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, blackArrowImage.size.width, blackArrowImage.size.height)]; self.arrowView.alpha = 0.96; self.arrowImageView = [[UIImageView alloc] initWithImage:whiteArrowImage];