Skip to content

Commit

Permalink
draw string with attr
Browse files Browse the repository at this point in the history
  • Loading branch information
zfdang committed Sep 25, 2014
1 parent 01147f8 commit eb4a878
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions CLCMenuExtra/CLCMenuExtra/CLCMenuExtraView.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ - (void)drawRect:(CGRect)rect
// init the status item popup
if(self.active)
{
[[NSColor selectedMenuItemTextColor] set];
[[NSColor blueColor] set];
} else {
[[NSColor yellowColor] set];
[[NSColor blackColor] set];
}

// to do: draw chinese & digits seperately; save attr for future usage
NSRect smallerRect = NSMakeRect(0, 4, rect.size.width - 2 , rect.size.height - 8);
[[NSBezierPath bezierPathWithRoundedRect:smallerRect xRadius:4 yRadius:4] fill];

NSString *str = [NSString stringWithFormat:@"%d", [self.calendar getDay:nil]];

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setAlignment:kCTTextAlignmentCenter];
NSDictionary *attr = [NSDictionary dictionaryWithObject:style forKey:NSParagraphStyleAttributeName];
NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:
[NSColor whiteColor], NSForegroundColorAttributeName,
[NSFont systemFontOfSize:11], NSFontAttributeName,
style, NSParagraphStyleAttributeName,
nil];
[str drawInRect:smallerRect withAttributes:attr];
}

Expand Down
Binary file not shown.

0 comments on commit eb4a878

Please sign in to comment.