5 // Created by Mike Mayo on 6/20/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "LBTitleView.h"
10 #import "LoadBalancer.h"
11 #import <QuartzCore/QuartzCore.h>
14 @implementation LBTitleView
16 @synthesize loadBalancer, statusDot, nameLabel, connectedLabel, bwInLabel, bwOutLabel;
19 self.frame = CGRectMake(0, 0, 320, 74);
20 self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
23 self.clipsToBounds = NO;
24 [self.layer setShadowColor:[[UIColor blackColor] CGColor]];
25 [self.layer setShadowRadius:2.0f];
26 [self.layer setShadowOffset:CGSizeMake(1, 1)];
27 [self.layer setShadowOpacity:0.8f];
30 self.statusDot.frame = CGRectMake(10, 18, 13, 13);
31 self.statusDot.image = [self.loadBalancer imageForStatus];
32 //self.statusDot.image = [UIImage imageNamed:@"dot-green.png"];
33 [self addSubview:self.statusDot];
36 self.nameLabel.backgroundColor = [UIColor clearColor];
37 self.nameLabel.font = [UIFont systemFontOfSize:24];
38 self.nameLabel.adjustsFontSizeToFitWidth = YES;
40 CGFloat third = self.frame.size.width / 3.0;
42 self.connectedLabel.frame = CGRectMake(0, 48, third, 20);
43 self.connectedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
44 self.connectedLabel.font = [UIFont systemFontOfSize:14];
45 self.connectedLabel.backgroundColor = [UIColor clearColor];
46 self.connectedLabel.textAlignment = UITextAlignmentCenter;
47 self.connectedLabel.text = @"";
48 self.connectedLabel.textColor = [UIColor darkGrayColor];
49 [self addSubview:self.connectedLabel];
51 self.bwInLabel.frame = CGRectMake(third, 48, third, 20);
52 self.bwInLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
53 self.bwInLabel.font = [UIFont systemFontOfSize:14];
54 self.bwInLabel.backgroundColor = [UIColor clearColor];
55 self.bwInLabel.textAlignment = UITextAlignmentCenter;
56 self.bwInLabel.text = @"";
57 self.bwInLabel.textColor = [UIColor darkGrayColor];
58 [self addSubview:self.bwInLabel];
60 self.bwOutLabel.frame = CGRectMake(third * 2, 48, third, 20);
61 self.bwOutLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
62 self.bwOutLabel.font = [UIFont systemFontOfSize:14];
63 self.bwOutLabel.backgroundColor = [UIColor clearColor];
64 self.bwOutLabel.textAlignment = UITextAlignmentCenter;
65 self.bwOutLabel.text = @"";
66 self.bwOutLabel.textColor = [UIColor darkGrayColor];
67 [self addSubview:self.bwOutLabel];
70 self.nameLabel.frame = CGRectMake(32, 9, 0, 0);
71 self.nameLabel.text = self.loadBalancer.name;
72 [self.nameLabel sizeToFit];
73 self.nameLabel.frame = CGRectMake(32, 9, MIN(self.frame.size.width - 40, self.nameLabel.frame.size.width), self.nameLabel.frame.size.height);
74 [self addSubview:self.nameLabel];
81 self.statusDot = [[[UIImageView alloc] init] autorelease];
82 self.nameLabel = [[[UILabel alloc] init] autorelease];
83 self.connectedLabel = [[[UILabel alloc] init] autorelease];
84 self.bwInLabel = [[[UILabel alloc] init] autorelease];
85 self.bwOutLabel = [[[UILabel alloc] init] autorelease];
90 - (id)initWithLoadBalancer:(LoadBalancer *)lb {
93 self.loadBalancer = lb;
99 - (void)drawRect:(CGRect)rect {
101 CGContextRef context = UIGraphicsGetCurrentContext();
103 // draw gradient background
104 CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
105 size_t num_locations = 2;
106 CGFloat locations[2] = { 1.0, 0.0 };
107 CGFloat components[8] = { 0.871, 0.871, 0.871, 1.0, 1.0, 1.0, 1.0, 1.0 };
108 CGGradientRef gradient = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations);
110 CGContextSaveGState(context);
111 CGContextAddRect(context, rect);
112 CGContextClip(context);
113 CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, 74), 0);
114 CGContextRestoreGState(context);
116 CGColorSpaceRelease(colorspace);
117 CGGradientRelease(gradient);
119 UIColor *lineColor = [UIColor colorWithWhite:0.784 alpha:1];
125 CGContextSetStrokeColorWithColor(context, lineColor.CGColor);
126 CGContextSetLineWidth(context, 1.0);
127 CGContextMoveToPoint(context, 0.0, 43.0);
128 CGContextAddLineToPoint(context, rect.size.width, 43.0);
129 CGContextStrokePath(context);
132 float third = rect.size.width / 3.0;
134 CGContextMoveToPoint(context, third, 43.0);
135 CGContextAddLineToPoint(context, third, rect.size.height);
136 CGContextStrokePath(context);
138 CGContextMoveToPoint(context, third * 2, 43.0);
139 CGContextAddLineToPoint(context, third * 2, rect.size.height);
140 CGContextStrokePath(context);
143 self.connectedLabel.frame = CGRectMake(0, 48, third, 20);
144 self.bwInLabel.frame = CGRectMake(third, 48, third, 20);
145 self.bwOutLabel.frame = CGRectMake(third * 2, 48, third, 20);
150 [loadBalancer release];
153 [connectedLabel release];
155 [bwOutLabel release];