author | Drew Gottlieb |
Sun, 02 Dec 2012 17:23:13 +0100 | |
changeset 8187 | fa725fe25708 |
parent 6908 | 896ed2afcfb8 |
child 11549 | 893722a2a1f9 |
permissions | -rwxr-xr-x |
6679
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
1 |
// |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
2 |
// MNEValueTrackingSlider |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
3 |
// |
6700 | 4 |
// Copyright 2012 Michael Neuwert |
6679
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
5 |
// "You can use the code in your own project and modify it as you like." |
6700 | 6 |
// http://blog.neuwert-media.com/2012/04/customized-uislider-with-visual-value-tracking/ |
6679
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
7 |
// |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
8 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
9 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
10 |
#import "MNEValueTrackingSlider.h" |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
11 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
12 |
#pragma mark - |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
13 |
#pragma mark Private UIView subclass rendering the popup showing slider value |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
14 |
@interface SliderValuePopupView : UIView |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
15 |
@property (nonatomic, retain) UIFont *font; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
16 |
@property (nonatomic, copy) NSString *text; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
17 |
@property (nonatomic) float arrowOffset; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
18 |
@end |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
19 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
20 |
@implementation SliderValuePopupView |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
21 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
22 |
@synthesize font = _font; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
23 |
@synthesize text = _text; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
24 |
@synthesize arrowOffset = _arrowOffset; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
25 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
26 |
-(id) initWithFrame:(CGRect) frame { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
27 |
self = [super initWithFrame:frame]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
28 |
if (self) { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
29 |
self.font = [UIFont boldSystemFontOfSize:18]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
30 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
31 |
return self; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
32 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
33 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
34 |
-(void) dealloc { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
35 |
self.text = nil; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
36 |
self.font = nil; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
37 |
[super dealloc]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
38 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
39 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
40 |
-(void) drawRect:(CGRect) rect { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
41 |
// Create the path for the rounded rectangle |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
42 |
CGRect roundedRect = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, floorf(self.bounds.size.height * 0.8)); |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
43 |
UIBezierPath *roundedRectPath = [UIBezierPath bezierPathWithRoundedRect:roundedRect cornerRadius:6.0]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
44 |
roundedRectPath.lineWidth = 2.0f; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
45 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
46 |
// Create the arrow path |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
47 |
UIBezierPath *arrowPath = [UIBezierPath bezierPath]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
48 |
/* |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
49 |
// Make sure the arrow offset is nice |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
50 |
if (-self.arrowOffset + 1 > CGRectGetMidX(self.bounds) / 2) |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
51 |
self.arrowOffset = -CGRectGetMidX(self.bounds) / 2 + 1; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
52 |
if (self.arrowOffset > CGRectGetMidX(self.bounds) / 2) |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
53 |
self.arrowOffset = CGRectGetMidX(self.bounds) / 2 -1; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
54 |
*/ |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
55 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
56 |
CGFloat midX = CGRectGetMidX(self.bounds) + self.arrowOffset; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
57 |
CGPoint p0 = CGPointMake(midX, CGRectGetMaxY(self.bounds)); |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
58 |
[arrowPath moveToPoint:p0]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
59 |
[arrowPath addLineToPoint:CGPointMake((midX - 10.0), CGRectGetMaxY(roundedRect))]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
60 |
[arrowPath addLineToPoint:CGPointMake((midX + 10.0), CGRectGetMaxY(roundedRect))]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
61 |
[arrowPath closePath]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
62 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
63 |
// Attach the arrow path to the rounded rect |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
64 |
[roundedRectPath appendPath:arrowPath]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
65 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
66 |
// Color various sections |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
67 |
[[UIColor blackColor] setFill]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
68 |
[roundedRectPath fill]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
69 |
[[UIColor whiteColor] setStroke]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
70 |
[roundedRectPath stroke]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
71 |
[[UIColor whiteColor] setFill]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
72 |
[arrowPath fill]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
73 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
74 |
// Draw the text |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
75 |
if (self.text) { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
76 |
[[UIColor lightYellowColor] set]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
77 |
CGSize s = [_text sizeWithFont:self.font]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
78 |
CGFloat yOffset = (roundedRect.size.height - s.height) / 2; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
79 |
CGRect textRect = CGRectMake(roundedRect.origin.x, yOffset, roundedRect.size.width, s.height); |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
80 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
81 |
[_text drawInRect:textRect |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
82 |
withFont:self.font |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
83 |
lineBreakMode:UILineBreakModeWordWrap |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
84 |
alignment:UITextAlignmentCenter]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
85 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
86 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
87 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
88 |
@end |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
89 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
90 |
#pragma mark - |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
91 |
#pragma mark MNEValueTrackingSlider implementations |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
92 |
@implementation MNEValueTrackingSlider |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
93 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
94 |
@synthesize thumbRect, textValue; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
95 |
|
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6700
diff
changeset
|
96 |
#pragma mark Private methods |
6679
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
97 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
98 |
-(void) _constructSlider { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
99 |
valuePopupView = [[SliderValuePopupView alloc] initWithFrame:CGRectZero]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
100 |
valuePopupView.backgroundColor = [UIColor clearColor]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
101 |
valuePopupView.alpha = 0.0; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
102 |
[self addSubview:valuePopupView]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
103 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
104 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
105 |
-(void) _fadePopupViewInAndOut:(BOOL)aFadeIn { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
106 |
[UIView beginAnimations:nil context:NULL]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
107 |
[UIView setAnimationDuration:0.25]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
108 |
if (aFadeIn) { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
109 |
valuePopupView.alpha = 1.0; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
110 |
} else { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
111 |
valuePopupView.alpha = 0.0; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
112 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
113 |
[UIView commitAnimations]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
114 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
115 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
116 |
-(void) _positionAndUpdatePopupView { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
117 |
CGRect _thumbRect = self.thumbRect; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
118 |
CGRect popupRect = CGRectOffset(_thumbRect, 0, -floorf(_thumbRect.size.height * 1.5)); |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
119 |
// (-100, -15) determines the size of the the rect |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
120 |
popupRect = CGRectInset(popupRect, -100, -15); |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
121 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
122 |
// this prevents drawing the popup outside the slider view |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
123 |
if (popupRect.origin.x < -self.frame.origin.x+5) |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
124 |
popupRect.origin.x = -self.frame.origin.x+5; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
125 |
else if (popupRect.origin.x > self.superview.frame.size.width - popupRect.size.width - self.frame.origin.x - 5) |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
126 |
popupRect.origin.x = self.superview.frame.size.width - popupRect.size.width - self.frame.origin.x - 5; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
127 |
//else if (CGRectGetMaxX(popupRect) > CGRectGetMaxX(self.superview.bounds)) |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
128 |
// popupRect.origin.x = CGRectGetMaxX(self.superview.bounds) - CGRectGetWidth(popupRect) - 1.0; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
129 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
130 |
valuePopupView.arrowOffset = CGRectGetMidX(_thumbRect) - CGRectGetMidX(popupRect); |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
131 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
132 |
valuePopupView.frame = popupRect; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
133 |
valuePopupView.text = self.textValue; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
134 |
[valuePopupView setNeedsDisplay]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
135 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
136 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
137 |
#pragma mark Memory management |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
138 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
139 |
-(id) initWithFrame:(CGRect) frame { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
140 |
self = [super initWithFrame:frame]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
141 |
if (self) { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
142 |
[self _constructSlider]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
143 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
144 |
return self; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
145 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
146 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
147 |
-(id) initWithCoder:(NSCoder *)aDecoder { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
148 |
self = [super initWithCoder:aDecoder]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
149 |
if (self) { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
150 |
[self _constructSlider]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
151 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
152 |
return self; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
153 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
154 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
155 |
-(void) dealloc { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
156 |
[valuePopupView release]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
157 |
[textValue release]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
158 |
[super dealloc]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
159 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
160 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
161 |
#pragma mark - |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
162 |
#pragma mark UIControl touch event tracking |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
163 |
-(BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
164 |
// Fade in and update the popup view |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
165 |
CGPoint touchPoint = [touch locationInView:self]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
166 |
// Check if the knob is touched. Only in this case show the popup-view |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
167 |
if(CGRectContainsPoint(CGRectInset(self.thumbRect, -14.0, -12.0), touchPoint)) { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
168 |
[self _positionAndUpdatePopupView]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
169 |
[self _fadePopupViewInAndOut:YES]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
170 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
171 |
return [super beginTrackingWithTouch:touch withEvent:event]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
172 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
173 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
174 |
-(BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
175 |
// Update the popup view as slider knob is being moved |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
176 |
[self _positionAndUpdatePopupView]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
177 |
return [super continueTrackingWithTouch:touch withEvent:event]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
178 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
179 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
180 |
-(void) cancelTrackingWithEvent:(UIEvent *)event { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
181 |
[super cancelTrackingWithEvent:event]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
182 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
183 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
184 |
-(void) endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
185 |
// Fade out the popoup view |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
186 |
[self _fadePopupViewInAndOut:NO]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
187 |
[super endTrackingWithTouch:touch withEvent:event]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
188 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
189 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
190 |
#pragma mark - |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
191 |
#pragma mark Custom property accessors |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
192 |
-(CGRect) thumbRect { |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
193 |
CGRect trackRect = [self trackRectForBounds:self.bounds]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
194 |
CGRect thumbR = [self thumbRectForBounds:self.bounds |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
195 |
trackRect:trackRect |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
196 |
value:self.value]; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
197 |
return thumbR; |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
198 |
} |
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
199 |
|
d8b98aa486a6
tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff
changeset
|
200 |
@end |