Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions Classes/ios/MMPopLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef NS_OPTIONS(NSUInteger, MMPopLabelAnimationOptions) {
+ (MMPopLabel *)popLabelWithText:(NSString *)text options:(MMPopLabelAnimationOptions)options;
- (void)addButton:(UIButton *)button;
- (void)popAtView:(UIView *)view;
- (void)popAtView:(UIView *)view forcePosition:(BOOL)upSide;
- (void)popAtBarButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)dismiss;

Expand Down
36 changes: 21 additions & 15 deletions Classes/ios/MMPopLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (id)initWithText:(NSString *)text
self.animatePopLabel = YES;

self.buttons = [@[] mutableCopy];

self.backgroundColor = [UIColor clearColor];
self.hidden = YES;

Expand All @@ -99,7 +99,7 @@ - (id)initWithText:(NSString *)text
self.label.text = text;
self.label.backgroundColor = [UIColor clearColor];
self.label.numberOfLines = 0;

[self addSubview:self.label];
}
return self;
Expand All @@ -112,19 +112,19 @@ - (void)setupAppearance
if (!_labelColor) {
_labelColor = [UIColor blackColor];
}

if (!_labelTextColor) {
_labelTextColor = [UIColor whiteColor];
}

if (!_labelTextHighlightColor) {
_labelTextHighlightColor = [UIColor whiteColor];
}

if (!_labelFont) {
_labelFont = [UIFont systemFontOfSize:_tipSize];
}

self.label.textColor = _labelTextColor;
self.label.font = _labelFont;

Expand All @@ -142,7 +142,7 @@ - (void)setupAppearance

self.label.frame = CGRectMake(0, 0, minWidth, minHeight);
[self.label sizeToFit];

self.targetFrame = self.label.frame;
self.frame = CGRectMake(_targetFrame.origin.x,
_targetFrame.origin.y,
Expand All @@ -154,7 +154,7 @@ - (void)setupAppearance

/* add buttons, if any */
if (_buttons.count == 0) return;

self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
self.frame.size.width,
Expand All @@ -176,7 +176,7 @@ - (void)setupAppearance

[b setTitleColor:_labelTextColor forState:UIControlStateNormal];
[b setTitleColor:_labelTextHighlightColor forState:UIControlStateHighlighted];

[b addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:b];
index ++;
Expand All @@ -196,8 +196,12 @@ - (void)layoutSubviews
[self setupAppearance];
}


- (void)popAtView:(UIView *)view
{
[self popAtView:view forcePosition:false];
}

- (void)popAtView:(UIView *)view forcePosition:(BOOL)upSide
{
if (self.hidden == NO) return;

Expand All @@ -219,7 +223,9 @@ - (void)popAtView:(UIView *)view
position = CGPointMake(center.x + diff, center.y + view.frame.size.height / 2);
}

if (self.frame.origin.y + self.frame.size.height + (self.buttons.count > 0 ? 44 : 0) > [UIScreen mainScreen].applicationFrame.size.height) {
if (self.frame.origin.y + self.frame.size.height + (self.buttons.count > 0 ? 44 : 0) > [UIScreen mainScreen].applicationFrame.size.height
|| upSide
) {
_arrowType = MMPopLabelBottomArrow;
position = CGPointMake(position.x,
(self.frame.origin.y - view.frame.size.height / 2 - kMMPopLabelViewPadding));
Expand Down Expand Up @@ -315,7 +321,7 @@ - (void)drawRect:(CGRect)rect
{
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();

//// Tip Drawing
CGContextSaveGState(context);
if (_arrowType == MMPopLabelBottomArrow) {
Expand All @@ -324,13 +330,13 @@ - (void)drawRect:(CGRect)rect
CGContextTranslateCTM(context, _viewCenter.x, kMMPopLabelTipPadding);
}
CGContextRotateCTM(context, -45 * M_PI / 180);

UIBezierPath* tipPath = [UIBezierPath bezierPathWithRect: CGRectMake(0, 0, 11, 11)];
[_labelColor setFill];
[tipPath fill];

CGContextRestoreGState(context);

//// ViewBackground Drawing
UIBezierPath* viewBackgroundPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(rect.origin.x,
rect.origin.y + kMMPopLabelTipPadding,
Expand Down