Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Made the tab bar gradient colours, and the border colour, configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mz2 committed Dec 21, 2012
1 parent 6e9d0a8 commit d0a29c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions DMTabBar/DMTabBar/DMTabBar.h
Expand Up @@ -33,6 +33,9 @@ typedef void (^DMTabBarEventsHandler)(DMTabBarItemSelectionType selectionType, D
// change selected item by passing a new index { 0 < index < tabBarItems.count }
@property (nonatomic,assign) NSUInteger selectedIndex;

@property (nonatomic,strong) NSColor *gradientColorStart;
@property (nonatomic,strong) NSColor *gradientColorEnd;
@property (nonatomic,strong) NSColor *borderColor;

// Handle selection change events using blocks
- (void) handleTabBarItemSelection:(DMTabBarEventsHandler) selectionHandler;
Expand Down
33 changes: 29 additions & 4 deletions DMTabBar/DMTabBar/DMTabBar.m
Expand Up @@ -13,8 +13,7 @@
// (Colors and gradient from Stephan Michels Softwareentwicklung und Beratung - SMTabBar)
#define kDMTabBarGradientColor_Start [NSColor colorWithCalibratedRed:0.851f green:0.851f blue:0.851f alpha:1.0f]
#define kDMTabBarGradientColor_End [NSColor colorWithCalibratedRed:0.700f green:0.700f blue:0.700f alpha:1.0f]
#define KDMTabBarGradient [[NSGradient alloc] initWithStartingColor: kDMTabBarGradientColor_Start \
endingColor: kDMTabBarGradientColor_End]
#define KDMTabBarGradient

// Border color of the bar
#define kDMTabBarBorderColor [NSColor colorWithDeviceWhite:0.2 alpha:1.0f]
Expand Down Expand Up @@ -42,12 +41,38 @@ @implementation DMTabBar
@synthesize selectedIndex,selectedTabBarItem;
@synthesize tabBarItems;

- (id)initWithFrame:(NSRect)frameRect
{
if (self = [super initWithFrame:frameRect])
{
[self setDefaultColors];
}

return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
[self setDefaultColors];
}
return self;
}

- (void)setDefaultColors
{
self.gradientColorStart = kDMTabBarGradientColor_Start;
self.gradientColorEnd = kDMTabBarGradientColor_End;
self.borderColor = kDMTabBarBorderColor;
}

- (void)drawRect:(NSRect)dirtyRect {
// Draw bar gradient
[KDMTabBarGradient drawInRect:self.bounds angle:90.0];
[[[NSGradient alloc] initWithStartingColor:self.gradientColorStart endingColor:self.gradientColorEnd] drawInRect:self.bounds angle:90.0];

// Draw drak gray bottom border
[kDMTabBarBorderColor setStroke];
[_borderColor setStroke];
[NSBezierPath setDefaultLineWidth:0.0f];
[NSBezierPath strokeLineFromPoint:NSMakePoint(NSMinX(self.bounds), NSMaxY(self.bounds))
toPoint:NSMakePoint(NSMaxX(self.bounds), NSMaxY(self.bounds))];
Expand Down

0 comments on commit d0a29c9

Please sign in to comment.