Permalink
Browse files

Adding default images to the TKPegSlider in the demo.

  • Loading branch information...
1 parent 40736b6 commit 44dc99a509a7be65786ed997523734f6f232e9dc @devinross committed Jun 30, 2014
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -51,7 +51,10 @@ - (void) loadView{
self.pegSlider = [[TKPegSlider alloc] initWithFrame:CGRectMake(10, 200, 40, 40)];
self.pegSlider.frame = CGRectMakeWithSize(10, 200, self.pegSlider.frame.size);
- self.pegSlider.numberOfPegs = 10;
+ self.pegSlider.numberOfPegs = 8;
+ self.pegSlider.leftEndImage = [UIImage imageNamed:@"sad"];
+ self.pegSlider.rightEndImage = [UIImage imageNamed:@"happy"];
+
[self.pegSlider addTarget:self action:@selector(changedPegValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.pegSlider];
@@ -62,6 +65,7 @@ - (void) changedPegValue:(TKPegSlider*)slider{
}
- (void) changedSwitchValue:(TKMultiSwitch*)switcher{
+ TKLog(@"%@",switcher);
}
@@ -53,6 +53,10 @@
2052AFCD168B840B00A49526 /* launch_iphone-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2052AFB2168B840B00A49526 /* launch_iphone-568h@2x.png */; };
2052AFCE168B840B00A49526 /* launch_iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = 2052AFB3168B840B00A49526 /* launch_iphone.png */; };
2053A4991961B5CC00A9E00D /* ControlsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2053A4981961B5CC00A9E00D /* ControlsViewController.m */; };
+ 2053A4BD1961F9B500A9E00D /* sad.png in Resources */ = {isa = PBXBuildFile; fileRef = 2053A4BB1961F9B500A9E00D /* sad.png */; };
+ 2053A4BE1961F9B500A9E00D /* sad@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2053A4BC1961F9B500A9E00D /* sad@2x.png */; };
+ 2053A4C21961F9C900A9E00D /* happy.png in Resources */ = {isa = PBXBuildFile; fileRef = 2053A4C01961F9C900A9E00D /* happy.png */; };
+ 2053A4C31961F9C900A9E00D /* happy@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2053A4C11961F9C900A9E00D /* happy@2x.png */; };
20A2A524174C37CF0058571F /* SlideToUnlockViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 20A2A523174C37CF0058571F /* SlideToUnlockViewController.m */; };
20CAEA9216F4EE6400D347E1 /* CalendarDayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 20CAEA9116F4EE6400D347E1 /* CalendarDayViewController.m */; };
20DAFB071814BB0D00EF525B /* ButtonViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 20DAFB061814BB0D00EF525B /* ButtonViewController.m */; };
@@ -149,6 +153,10 @@
2052AFB3168B840B00A49526 /* launch_iphone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = launch_iphone.png; sourceTree = "<group>"; };
2053A4971961B5CC00A9E00D /* ControlsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControlsViewController.h; sourceTree = "<group>"; };
2053A4981961B5CC00A9E00D /* ControlsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ControlsViewController.m; sourceTree = "<group>"; };
+ 2053A4BB1961F9B500A9E00D /* sad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = sad.png; sourceTree = "<group>"; };
+ 2053A4BC1961F9B500A9E00D /* sad@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sad@2x.png"; sourceTree = "<group>"; };
+ 2053A4C01961F9C900A9E00D /* happy.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = happy.png; sourceTree = "<group>"; };
+ 2053A4C11961F9C900A9E00D /* happy@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "happy@2x.png"; sourceTree = "<group>"; };
20A2A522174C37CF0058571F /* SlideToUnlockViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlideToUnlockViewController.h; sourceTree = "<group>"; };
20A2A523174C37CF0058571F /* SlideToUnlockViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SlideToUnlockViewController.m; sourceTree = "<group>"; };
20CAEA9016F4EE6400D347E1 /* CalendarDayViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalendarDayViewController.h; sourceTree = "<group>"; };
@@ -217,6 +225,10 @@
2052AF96168B840B00A49526 /* Images */ = {
isa = PBXGroup;
children = (
+ 2053A4C01961F9C900A9E00D /* happy.png */,
+ 2053A4C11961F9C900A9E00D /* happy@2x.png */,
+ 2053A4BB1961F9B500A9E00D /* sad.png */,
+ 2053A4BC1961F9B500A9E00D /* sad@2x.png */,
20F6154417E6A717007F443C /* wallpaper@2x.png */,
2052AF97168B840B00A49526 /* Back.png */,
2052AF98168B840B00A49526 /* Back@2x.png */,
@@ -448,12 +460,15 @@
2052AFB7168B840B00A49526 /* beer@2x.png in Resources */,
2052AFB8168B840B00A49526 /* ipadcover_1.jpg in Resources */,
2052AFB9168B840B00A49526 /* ipadcover_2.jpg in Resources */,
+ 2053A4C31961F9C900A9E00D /* happy@2x.png in Resources */,
2052AFBA168B840B00A49526 /* ipadcover_3.jpg in Resources */,
2052AFBB168B840B00A49526 /* ipadcover_4.jpg in Resources */,
2052AFBC168B840B00A49526 /* ipadcover_5.jpg in Resources */,
+ 2053A4BD1961F9B500A9E00D /* sad.png in Resources */,
2052AFBD168B840B00A49526 /* ipadcover_6.jpg in Resources */,
2052AFBE168B840B00A49526 /* ipadcover_7.jpg in Resources */,
2052AFBF168B840B00A49526 /* ipadcover_8.jpg in Resources */,
+ 2053A4C21961F9C900A9E00D /* happy.png in Resources */,
2052AFC0168B840B00A49526 /* ipadcover_9.jpg in Resources */,
2052AFC1168B840B00A49526 /* cover_1.jpg in Resources */,
2052AFC2168B840B00A49526 /* cover_2.jpg in Resources */,
@@ -466,6 +481,7 @@
2052AFC9168B840B00A49526 /* cover_9.jpeg in Resources */,
2052AFCA168B840B00A49526 /* icon_114.png in Resources */,
20F6154517E6A717007F443C /* wallpaper@2x.png in Resources */,
+ 2053A4BE1961F9B500A9E00D /* sad@2x.png in Resources */,
2052AFCB168B840B00A49526 /* icon_57.png in Resources */,
2052AFCC168B840B00A49526 /* icon_74.png in Resources */,
205164ED18DCBD6F0048E640 /* TapkuLibrary.bundle in Resources */,
@@ -211,8 +211,6 @@ - (void) pan:(UIPanGestureRecognizer*)pan{
if(pan.ended || pan.cancelled){
-
-
[UIView beginAnimations:nil context:nil];
self.selectionView.transform = CGAffineTransformIdentity;
self.selectionView.center = CGPointMake( INSET + per * index + CGRectGetWidth(self.selectionView.frame)/2, self.selectionView.center.y);
@@ -264,12 +262,8 @@ - (void) setIndexOfSelectedItem:(NSInteger)indexOfSelectedItem{
}
- (void) selectItemAtIndex:(NSInteger)index animated:(BOOL)animated{
-
CGFloat per = CGRectGetWidth(self.frame) / self.labels.count;
-
self.offsetFromCenter = -1;
-
-
if(index == _indexOfSelectedItem) return;
@@ -283,8 +277,6 @@ - (void) selectItemAtIndex:(NSInteger)index animated:(BOOL)animated{
i++;
}
if(animated) [UIView commitAnimations];
-
-
_indexOfSelectedItem = index;
}
@@ -57,10 +57,10 @@ - (id) initWithFrame:(CGRect)frame{
self.clipsToBounds = NO;
self.layer.cornerRadius = CGRectGetHeight(self.frame)/2;
- self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
+ self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectInset(CGRectMake(0, 0, 40, 40), 6, 6)];
[self addSubview:self.leftImageView];
- self.rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.frame)-40, 0, 40, 40)];
+ self.rightImageView = [[UIImageView alloc] initWithFrame:CGRectInset(CGRectMake(CGRectGetWidth(self.frame)-40, 0, 40, 40), 6, 6)];
[self addSubview:self.rightImageView];
_numberOfPegs = 3;
@@ -118,13 +118,16 @@ - (void) _setupPegs{
- (void) tintColorDidChange{
[super tintColorDidChange];
[self _setupPegs];
+ self.leftImageView.tintColor = self.rightImageView.tintColor = self.tintColor;
+
}
- (NSInteger) _indexOfSelectAtPoint:(CGFloat)point{
CGFloat leftPad = 16 + (self.leftImageView.image ? 40 : 3);
CGFloat rightPad = 16 + (self.rightImageView.image ? 40 : 3);
CGFloat per = (CGRectGetWidth(self.frame)-leftPad-rightPad) / (_numberOfPegs-1);
NSInteger index = (point+(per/2)-leftPad) / per;
+ index = MAX(0,index);
return MAX(0,MIN(_numberOfPegs-1,index));
}
- (void) pan:(UIPanGestureRecognizer*)gesture{
@@ -139,6 +142,11 @@ - (void) pan:(UIPanGestureRecognizer*)gesture{
i++;
}
[UIView commitAnimations];
+
+ if(index!= _selectedPegIndex){
+ _selectedPegIndex = index;
+ [self sendActionsForControlEvents:UIControlEventValueChanged];
+ }
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
@@ -157,6 +165,11 @@ - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
}
[UIView commitAnimations];
+ if(index!= _selectedPegIndex){
+ _selectedPegIndex = index;
+ [self sendActionsForControlEvents:UIControlEventValueChanged];
+ }
+
}
@@ -184,11 +197,11 @@ - (void) selectPegAtIndex:(NSInteger)index animated:(BOOL)animated{
}
- (void) setLeftEndImage:(UIImage *)leftEndImage{
- self.leftImageView.image = leftEndImage;
+ self.leftImageView.image = [leftEndImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self _setupPegs];
}
- (void) setRightEndImage:(UIImage *)rightEndImage{
- self.rightImageView.image = rightEndImage;
+ self.rightImageView.image = [rightEndImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self _setupPegs];
}
- (UIImage*) leftEndImage{

0 comments on commit 44dc99a

Please sign in to comment.