Skip to content

Commit

Permalink
Ability to specify custom font
Browse files Browse the repository at this point in the history
  • Loading branch information
mohlman3 committed Apr 30, 2015
1 parent a8a886e commit 98022c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Coach Marks/DDBubble.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 13 additions & 10 deletions Coach Marks/DDBubble.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand All @@ -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)
Expand All @@ -42,17 +47,20 @@ -(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;
self.arrowPosition = arrowPosition;
[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
Expand All @@ -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];
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions Coach Marks/DDCoachMarksView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion Coach Marks/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down

0 comments on commit 98022c3

Please sign in to comment.