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
Show all changes
26 commits
Select commit Hold shift + click to select a range
b647f38
Add animated parameter to allow pop animation to be disabled
LucasVidal Feb 11, 2015
357eca3
bump version
LucasVidal Feb 11, 2015
ab0acd8
Allow initializing popup with attributed string
LucasVidal Feb 12, 2015
b7d6633
Merge pull request #1 from restorando/feature/init-with-attributed-st…
LucasVidal Feb 12, 2015
02e3965
bump version
LucasVidal Feb 12, 2015
912897f
Arrow is now a triangle
LucasVidal Feb 12, 2015
9031b43
Merge pull request #2 from restorando/feature/make-arrow-triangle
LucasVidal Feb 12, 2015
994fd10
Update MMPopLabel.m
LucasVidal Feb 19, 2015
3152059
Merge pull request #3 from restorando/bug/fix-triangle-not-being-shown
LucasVidal Feb 19, 2015
17dfe8f
Update MMPopLabel.podspec
LucasVidal Feb 19, 2015
56c6be8
Update MMPopLabel.m
LucasVidal Feb 20, 2015
6423b92
Horrible hack, reading this will cost some sanity points.
GabrielDarioRos Mar 17, 2015
fbcfcc6
Bump version.
GabrielDarioRos Mar 20, 2015
4c7e1e2
Merge pull request #4 from restorando/bug/support-tabbar
GabrielDarioRos Mar 20, 2015
44391d0
hack to support navigation bar
Apr 7, 2015
ebd8bc6
fix bug in if
Apr 7, 2015
b617135
remove dismiss popup when pressed over it
Apr 7, 2015
65f87c9
increase kMMPopLabelViewPadding to 8
Apr 7, 2015
234903e
change font type for OK button
Apr 7, 2015
2b58cd7
move back 1 commit./
Apr 7, 2015
0c65620
change place where setup the appearance.
Apr 20, 2015
16a27a6
fix problem with char type
Apr 20, 2015
1fcd6c9
apply fix patch
LucasVidal Apr 21, 2015
8c3404c
restore color
LucasVidal Apr 21, 2015
86a86ee
version bump
LucasVidal Apr 21, 2015
8845aae
add text setter
LucasVidal Apr 22, 2015
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
10 changes: 10 additions & 0 deletions Classes/ios/MMPopLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@

@property (nonatomic, weak) id<MMPopLabelDelegate> delegate;

+ (MMPopLabel *)popLabelWithAttributedString:(NSAttributedString *)attributedString;

+ (MMPopLabel *)popLabelWithText:(NSString *)text;
- (void)addButton:(UIButton *)button;

- (void)popAtView:(UIView *)view animated: (BOOL) animated;

//Keeping this method without animated boolean for retrocompatibility
//will use animations by default
- (void)popAtView:(UIView *)view;

- (void)setText: (NSString *)text;

- (void)dismiss;


Expand Down
121 changes: 85 additions & 36 deletions Classes/ios/MMPopLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


CGFloat const kMMPopLabelSidePadding = 10.0f;
CGFloat const kMMPopLabelViewPadding = 2.0f;
CGFloat const kMMPopLabelViewPadding = 8.0f;
CGFloat const kMMPopLabelCornerRadius = 6.0f;
CGFloat const kMMPopLabelTipPadding = 8.0f;

Expand Down Expand Up @@ -51,14 +51,45 @@ @interface MMPopLabel ()

@implementation MMPopLabel

+ (MMPopLabel *)popLabelWithAttributedString:(NSAttributedString *)attributedString {
MMPopLabel *popLabel = [[MMPopLabel alloc] initWithAttributedString: attributedString];


return popLabel;

}

+ (MMPopLabel *)popLabelWithText:(NSString *)text
{
MMPopLabel *popLabel = [[MMPopLabel alloc] initWithText:text];

return popLabel;
}

- (instancetype)initWithAttributedString: (NSAttributedString *)attributedString {
if (self = [super initWithFrame:CGRectZero])
{
self.buttons = [@[] mutableCopy];

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

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.tipSize = 24;
} else {
self.tipSize = 12;
}

self.label = [[MMLabel alloc] initWithFrame:CGRectZero];
self.label.textAlignment = NSTextAlignmentCenter;
self.label.attributedText = attributedString;
self.label.backgroundColor = [UIColor clearColor];
self.label.numberOfLines = 0;

[self addSubview:self.label];
}
return self;
}

- (id)initWithText:(NSString *)text
{
Expand All @@ -68,13 +99,13 @@ - (id)initWithText:(NSString *)text

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

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.tipSize = 24;
} else {
self.tipSize = 12;
}

self.label = [[MMLabel alloc] initWithFrame:CGRectZero];
self.label.textAlignment = NSTextAlignmentCenter;
self.label.text = text;
Expand All @@ -86,6 +117,9 @@ - (id)initWithText:(NSString *)text
return self;
}

- (void)setText: (NSString *)text {
self.label.text = text;
}

- (void)setupAppearance
{
Expand All @@ -108,19 +142,19 @@ - (void)setupAppearance

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

/* resize label and view */
CGFloat maxWidth = [UIScreen mainScreen].applicationFrame.size.width * 0.80f;
CGFloat maxHeight = [UIScreen mainScreen].applicationFrame.size.height * 0.80f;

NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:self.label.text
attributes:@{NSFontAttributeName:_labelFont}];
CGRect rect = [attributedText boundingRectWithSize:(CGSize){maxWidth, CGFLOAT_MAX}
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGFloat minWidth = MAX(rect.size.width, 180);
CGFloat minHeight = MIN(rect.size.height, maxHeight);

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

Expand All @@ -132,29 +166,29 @@ - (void)setupAppearance
self.label.frame = CGRectMake(_targetFrame.origin.x,
_targetFrame.origin.y,
minWidth, _targetFrame.size.height + _tipSize * 4);

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

self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
self.frame.size.width,
self.frame.size.height + 33);

NSInteger index = 0;
NSInteger buttonWidth = self.frame.size.width / _buttons.count;
for (UIButton *b in _buttons) {
b.tag = index;
b.frame = CGRectMake(self.bounds.origin.x + (index * buttonWidth),
self.bounds.origin.y + self.bounds.size.height - 44,
buttonWidth, 33);

if (_buttonFont) {
b.titleLabel.font = _buttonFont;
} else {
b.titleLabel.font = [UIFont systemFontOfSize:_tipSize];
}

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

Expand All @@ -177,13 +211,16 @@ - (void)layoutSubviews
[self setupAppearance];
}

- (void)popAtView:(UIView *)view {
[self popAtView:view animated:YES];
}

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

_arrowType = MMPopLabelTopArrow;

CGPoint position = CGPointMake(view.center.x, view.center.y + view.frame.size.height / 2 + kMMPopLabelViewPadding);
self.center = position;
if (position.x + (self.frame.size.width / 2) > [UIScreen mainScreen].applicationFrame.size.width) {
Expand All @@ -194,12 +231,13 @@ - (void)popAtView:(UIView *)view
position = CGPointMake(view.center.x + diff, view.center.y + view.frame.size.height / 2);
}

if (self.frame.origin.y + self.frame.size.height > [UIScreen mainScreen].applicationFrame.size.height) {
if (self.frame.origin.y + self.frame.size.height > [[self superview] frame].size.height) {

_arrowType = MMPopLabelBottomArrow;
position = CGPointMake(position.x,
[UIScreen mainScreen].applicationFrame.size.height - (self.frame.size.height + view.frame.size.height + kMMPopLabelViewPadding));
[[self superview] frame].size.height - (self.frame.size.height + view.frame.size.height + kMMPopLabelViewPadding));
}

CGPoint centerPoint = CGPointMake(position.x, position.y + self.frame.size.height / 2);
self.center = position;

Expand All @@ -212,39 +250,45 @@ - (void)popAtView:(UIView *)view
_viewCenter = CGPointMake(view.center.x - self.frame.origin.x - 8, view.center.y);
[self setNeedsDisplay];

self.transform = CGAffineTransformMakeScale(0, 0);
view.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateKeyframesWithDuration:duration/6.0f delay:delay options:0 animations:^{
self.center = centerPoint;
self.alpha = 1.0f;
self.transform = CGAffineTransformMakeScale(1.2, 1.2);
view.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion:^(BOOL finished) {
[UIView animateKeyframesWithDuration:duration/6.0f delay:0 options:0 animations:^{
self.transform = CGAffineTransformMakeScale(0.9, 0.9);
view.transform = CGAffineTransformMakeScale(0.9, 0.9);
if (animated) {
self.transform = CGAffineTransformMakeScale(0, 0);
view.transform = CGAffineTransformMakeScale(0, 0);

[UIView animateKeyframesWithDuration:duration/6.0f delay:delay options:0 animations:^{
self.center = centerPoint;
self.alpha = 1.0f;
self.transform = CGAffineTransformMakeScale(1.2, 1.2);
view.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion:^(BOOL finished) {
[UIView animateKeyframesWithDuration:duration/6.0f delay:0 options:0 animations:^{
self.transform = CGAffineTransformMakeScale(1, 1);
view.transform = CGAffineTransformMakeScale(1, 1);
self.transform = CGAffineTransformMakeScale(0.9, 0.9);
view.transform = CGAffineTransformMakeScale(0.9, 0.9);
} completion:^(BOOL finished) {
// completion block empty?
[UIView animateKeyframesWithDuration:duration/6.0f delay:0 options:0 animations:^{
self.transform = CGAffineTransformMakeScale(1, 1);
view.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
// completion block empty?
}];
}];
}];
}];
} else {
self.center = centerPoint;
self.alpha = 1.0f;
}
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self dismiss];

}


- (void)dismiss
{
if (self.hidden == YES) return;

[UIView animateWithDuration:0.15f animations:^{
self.alpha = 0.0f;
} completion:^(BOOL finished) {
Expand All @@ -268,10 +312,15 @@ - (void)drawRect:(CGRect)rect
}
CGContextRotateCTM(context, -45 * M_PI / 180);

UIBezierPath* tipPath = [UIBezierPath bezierPathWithRect: CGRectMake(0, 0, 11, 11)];
UIBezierPath *tipPath = [UIBezierPath bezierPath];
[tipPath moveToPoint:CGPointMake( 0, 0)];
[tipPath addLineToPoint:CGPointMake(0, 11)];
[tipPath addLineToPoint:CGPointMake(11, 11)];
[tipPath addLineToPoint:CGPointMake( 0, 0)];
[tipPath closePath];

[_labelColor setFill];
[tipPath fill];

CGContextRestoreGState(context);

//// ViewBackground Drawing
Expand Down
2 changes: 1 addition & 1 deletion MMPopLabel.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MMPopLabel"
s.version = "0.1.1"
s.version = "0.1.9"
s.summary = "MMPopLabel is a tooltip control for iOS, with optional buttons"
s.description = <<-DESC
MMPopLabel is a tooltip control for iOS, useful for tutorials.
Expand Down