From 98022c303967f45c7506d173305bbc07068d6523 Mon Sep 17 00:00:00 2001 From: Matthew Ohlman Date: Thu, 30 Apr 2015 13:24:16 -0400 Subject: [PATCH] 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)],