Skip to content

Commit

Permalink
Merge pull request #4 from FiveBox/master
Browse files Browse the repository at this point in the history
Ability to specify custom font
  • Loading branch information
ddoria921 committed May 4, 2015
2 parents a8a886e + 7d2a50d commit bffa057
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
},
];

Expand Down Expand Up @@ -93,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

Expand Down

0 comments on commit bffa057

Please sign in to comment.