Skip to content

Commit

Permalink
Added a anchorMargin property so we can set this attribute if needed …
Browse files Browse the repository at this point in the history
…for custom SMCalloutBackgroundView. Default is still 27.
  • Loading branch information
rousseauo committed Feb 16, 2015
1 parent b0e8b9c commit 9c14b9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions SMCalloutView.h
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions SMCalloutView.m
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 9c14b9f

Please sign in to comment.