forked from joshaber/JAListView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoView.m
87 lines (63 loc) · 1.96 KB
/
DemoView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// DemoView.m
// JAListView
//
// Created by Josh Abernathy on 9/29/10.
// Copyright 2010 Maybe Apps. All rights reserved.
//
#import "DemoView.h"
@interface DemoView ()
- (void)drawBackground;
@property (nonatomic, readonly) NSGradient *gradient;
@end
@implementation DemoView
+ (DemoView *)demoView {
static NSNib *nib = nil;
if(nib == nil) {
nib = [[NSNib alloc] initWithNibNamed:NSStringFromClass(self) bundle:nil];
}
NSArray *objects = nil;
[nib instantiateNibWithOwner:nil topLevelObjects:&objects];
for(id object in objects) {
if([object isKindOfClass:self]) {
return object;
}
}
NSAssert1(NO, @"No view of class %@ found.", NSStringFromClass(self));
return nil;
}
#pragma mark NSView
- (void)drawRect:(NSRect)rect {
[super drawRect:rect];
[self drawBackground];
}
#pragma mark API
- (void)drawBackground {
[self.gradient drawInRect:self.bounds angle:self.selected ? 270.0f : 90.0f];
[[NSColor colorWithDeviceWhite:0.5f alpha:1.0f] set];
NSRectFill(NSMakeRect(0.0f, 0.0f, self.bounds.size.width, 1.0f));
[[NSColor colorWithDeviceWhite:0.93f alpha:1.0f] set];
NSRectFill(NSMakeRect(0.0f, self.bounds.size.height - 1.0f, self.bounds.size.width, 1.0f));
}
- (NSGradient *)gradient {
if(gradient == nil) {
gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceWhite:0.8f alpha:1.0f] endingColor:[NSColor colorWithDeviceWhite:0.85f alpha:1.0f]];
}
return gradient;
}
- (void)setText:(NSString *)newText {
NSString *newValue = [[newText copy] autorelease];
[self.textField setStringValue:newValue];
[self.shadowTextField setStringValue:newValue];
}
- (NSString *)text {
return [self.textField stringValue];
}
- (void)setSelected:(BOOL)isSelected {
selected = isSelected;
[self setNeedsDisplay:YES];
}
@synthesize selected;
@synthesize textField;
@synthesize shadowTextField;
@end