From 98022c303967f45c7506d173305bbc07068d6523 Mon Sep 17 00:00:00 2001 From: Matthew Ohlman Date: Thu, 30 Apr 2015 13:24:16 -0400 Subject: [PATCH 1/4] Ability to specify custom font --- Coach Marks/DDBubble.h | 3 +++ Coach Marks/DDBubble.m | 23 +++++++++++++---------- Coach Marks/DDCoachMarksView.m | 5 +++-- Coach Marks/ViewController.m | 3 ++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Coach Marks/DDBubble.h b/Coach Marks/DDBubble.h index dd85c3d..3fbd8a9 100755 --- a/Coach Marks/DDBubble.h +++ b/Coach Marks/DDBubble.h @@ -25,8 +25,11 @@ typedef enum { @property (nonatomic) CGRect attachedFrame; @property (nonatomic) BOOL bouncing; @property (nonatomic) BOOL animationShouldStop; +@property (nonatomic) UIFont *font; -(id)initWithAttachedView:(UIView*)view title:(NSString*)title description:(NSString*)description arrowPosition:(CRArrowPosition)arrowPosition andColor:(UIColor*)color; -(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)description arrowPosition:(CRArrowPosition)arrowPosition andColor:(UIColor*)color; +-(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)description arrowPosition:(CRArrowPosition)arrowPosition color:(UIColor*)color andFont:(UIFont *)font; + -(void)animate; @end \ No newline at end of file diff --git a/Coach Marks/DDBubble.m b/Coach Marks/DDBubble.m index adfe343..00d7362 100755 --- a/Coach Marks/DDBubble.m +++ b/Coach Marks/DDBubble.m @@ -13,7 +13,7 @@ #define PADDING 8 // padding between text and border of bubble #define RADIUS 6 #define TEXT_COLOR [UIColor blackColor] -#define TITLE_FONT_SIZE 14 +#define DEFAULT_TITLE_FONT_SIZE 14 @interface DDBubble () { @@ -33,6 +33,11 @@ -(id)initWithAttachedView:(UIView*)view title:(NSString*)title description:(NSSt } -(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)description arrowPosition:(CRArrowPosition)arrowPosition andColor:(UIColor*)color +{ + return [self initWithFrame:frame title:title description:description arrowPosition:arrowPosition color:color andFont:nil]; +} + +-(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)description arrowPosition:(CRArrowPosition)arrowPosition color:(UIColor*)color andFont:(UIFont *)font { self = [super init]; if(self) @@ -42,6 +47,11 @@ -(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)d else self.color=[UIColor whiteColor]; + if (font != nil) + self.font = font; + else + self.font = [UIFont fontWithName:@"HelveticaNeue" size:DEFAULT_TITLE_FONT_SIZE]; + self.attachedFrame = frame; self.title = title; self.bubbleText = description; @@ -49,10 +59,8 @@ -(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)d [self setBackgroundColor:[UIColor clearColor]]; } - UIFont* font = [self font]; - // position bubble - [self setFrame:[self calculateFrameWithFont:font]]; + [self setFrame:[self calculateFrameWithFont:self.font]]; [self fixFrameIfOutOfBounds]; // Make it pass touch events through to the DDCoachMarksView @@ -66,10 +74,9 @@ -(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)d float actualHeight = self.frame.size.height - actualYPosition - PADDING*1.2; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(actualXPosition, actualYPosition, actualWidth, actualHeight)]; - [titleLabel setFont:font]; + [titleLabel setFont:self.font]; [titleLabel setTextColor:TEXT_COLOR]; [titleLabel setAlpha:0.9]; - [titleLabel setFont:font]; [titleLabel setText:title]; [titleLabel setBackgroundColor:[UIColor clearColor]]; [titleLabel setLineBreakMode:NSLineBreakByWordWrapping]; @@ -81,10 +88,6 @@ -(id)initWithFrame:(CGRect)frame title:(NSString*)title description:(NSString*)d return self; } -- (UIFont*) font { - return [UIFont fontWithName:@"HelveticaNeue" size:TITLE_FONT_SIZE]; -} - #pragma mark - Positioning and Size diff --git a/Coach Marks/DDCoachMarksView.m b/Coach Marks/DDCoachMarksView.m index 770552c..9330a7c 100755 --- a/Coach Marks/DDCoachMarksView.m +++ b/Coach Marks/DDCoachMarksView.m @@ -253,6 +253,7 @@ - (void)animateNextBubble NSString *markCaption = [coachMarkInfo objectForKey:@"caption"]; CGRect frame = [[coachMarkInfo objectForKey:@"rect"] CGRectValue]; CGRect poi = [[coachMarkInfo objectForKey:@"POI"] CGRectValue]; + UIFont *font = [coachMarkInfo objectForKey:@"font"]; // remove previous bubble if (self.bubble) { @@ -270,9 +271,9 @@ - (void)animateNextBubble // IF using point of interest (poi) frame use that instead of cutout frame // ELSE use the cutout frame if (CGRectIsEmpty(poi)) { - self.bubble = [[DDBubble alloc] initWithFrame:frame title:markCaption description:nil arrowPosition:CRArrowPositionTop andColor:nil]; + self.bubble = [[DDBubble alloc] initWithFrame:frame title:markCaption description:nil arrowPosition:CRArrowPositionTop color:nil andFont:font]; } else - self.bubble = [[DDBubble alloc] initWithFrame:poi title:markCaption description:nil arrowPosition:CRArrowPositionTop andColor:nil]; + self.bubble = [[DDBubble alloc] initWithFrame:poi title:markCaption description:nil arrowPosition:CRArrowPositionTop color:nil andFont:font]; self.bubble.alpha = 0.0; [self addSubview:self.bubble]; diff --git a/Coach Marks/ViewController.m b/Coach Marks/ViewController.m index ca79b7c..f42b236 100644 --- a/Coach Marks/ViewController.m +++ b/Coach Marks/ViewController.m @@ -28,7 +28,8 @@ - (void)viewDidAppear:(BOOL)animated @{ @"rect": [NSValue valueWithCGRect:CGRectMake(6, 24, 40, 40)], @"caption": @"Synchronize your mail", - @"shape": @"circle" + @"shape": @"circle", + @"font": [UIFont boldSystemFontOfSize:14.0] }, @{ @"rect": [NSValue valueWithCGRect:CGRectMake(275, 24, 40, 40)], From 0f818cf093e16b1bcdc45556de156c4d15dee6f7 Mon Sep 17 00:00:00 2001 From: Matthew Ohlman Date: Thu, 30 Apr 2015 13:34:37 -0400 Subject: [PATCH 2/4] Update README to include new font property --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a642cbc..95489b3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,8 @@ Create a new DDCoachMarksView instance and pass in an array of coach mark defini @"rect": [NSValue valueWithCGRect:CGRectMake(0, 125, 320, 60)], @"caption": @"Swipe for more options", @"shape": @"square", - @"swipe": @"YES" + @"swipe": @"YES", + @"font": [UIFont systemFontOfSize: 14.0] }, ]; From a98f1099afb3f442c95019ce2c6cd3e0a118ee35 Mon Sep 17 00:00:00 2001 From: Matthew Ohlman Date: Thu, 30 Apr 2015 13:38:28 -0400 Subject: [PATCH 3/4] Update README to include new font property --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95489b3..86d0a65 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Create a new DDCoachMarksView instance and pass in an array of coach mark defini @"caption": @"Swipe for more options", @"shape": @"square", @"swipe": @"YES", - @"font": [UIFont systemFontOfSize: 14.0] + @"font": [UIFont systemFontOfSize: 14.0] }, ]; @@ -94,6 +94,8 @@ Text that goes in the bubbles Use "YES" here if you want to show a row swipe gesture on a table view cell. Disabled by default. * `@"direction"` Direction that swipe gestures should animate in. The default is `@"lefttoright"` but you can also specify `@"righttoleft"`. +* `@"font"` + Font for the caption in the bubble. If not specified, defaults to the default HelveticaNeue size 14.0. ## DDCoachMarksViewDelegate From 7d2a50d642ebaecbfbf2094168934bec285ab422 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 30 Apr 2015 13:39:45 -0400 Subject: [PATCH 4/4] Fix spacing in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86d0a65..90e43bf 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Create a new DDCoachMarksView instance and pass in an array of coach mark defini @"caption": @"Swipe for more options", @"shape": @"square", @"swipe": @"YES", - @"font": [UIFont systemFontOfSize: 14.0] + @"font": [UIFont systemFontOfSize: 14.0] }, ];