Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned project structure for Demo.

  • Loading branch information...
commit e135e3627d4a3073db4055dce3d8e2f5edc2f1f5 1 parent 7c72b44
@jasonmorrissey authored
View
6 Demo/Classes/DemoTableViewController.h
@@ -1,6 +0,0 @@
-#import <UIKit/UIKit.h>
-#import "JMSlider.h"
-
-@interface DemoTableViewController : UITableViewController <JMSliderDelegate>
-
-@end
View
93 Demo/Classes/DemoTableViewController.m
@@ -1,93 +0,0 @@
-#import "DemoTableViewController.h"
-
-@interface DemoTableViewController()
-@property (nonatomic,retain) JMSlider * slider;
-@end
-
-@implementation DemoTableViewController
-
-@synthesize slider = slider_;
-
-- (void)dealloc
-{
- self.slider = nil;
- [super dealloc];
-}
-
-- (void)loadView;
-{
- [super loadView];
- [self.tableView setCanCancelContentTouches:NO];
-}
-
-- (UITableViewCell *)sliderCell;
-{
- UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SliderCell"] autorelease];
-
- [cell setSelectionStyle:UITableViewCellEditingStyleNone];
-
- CGRect sliderFrame = CGRectMake(0., 0., 320., 90.);
-
- self.slider = [JMSlider sliderWithFrame:sliderFrame centerTitle:@"more" leftTitle:@"hide read" rightTitle:@"hide all" delegate:self];
-
- [cell addSubview:self.slider];
- return cell;
-}
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-{
- return 1;
-}
-
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-{
- return 1;
-}
-
-- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
-{
- return 90.;
-}
-
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-{
-// static NSString *CellIdentifier = @"Cell";
-//
-// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-// if (cell == nil)
-// {
-// cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
-// }
-//
- return [self sliderCell];
-}
-
-#pragma mark - Table view delegate
-
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
-{
-}
-
--(void)slider:(JMSlider *)slider didSelect:(JMSliderSelection)selection;
-{
- switch (selection)
- {
- case JMSliderSelectionLeft:
- NSLog(@"invoked: left");
- break;
-
- case JMSliderSelectionCenter:
- NSLog(@"invoked: center");
- break;
-
- case JMSliderSelectionRight:
- NSLog(@"invoked: right");
- break;
-
- default:
- break;
- }
-}
-
-
-@end
View
48 Demo/Classes/DemoViewController.m
@@ -1,50 +1,54 @@
// Created by Jason Morrissey - jasonmorrissey.org
#import "DemoViewController.h"
-#import "UIView+JMNoise.h"
-#import "UIView+Positioning.h"
+#import "CenteredTableViewController.h"
@interface DemoViewController()
+@property (nonatomic,retain) JMSlider * slider;
@end
@implementation DemoViewController
--(void)loadView;
+@synthesize slider = slider_;
+
+- (void)dealloc;
+{
+ self.slider = nil;
+ [super dealloc];
+}
+
+- (void)loadView;
{
- [super loadView];
- self.view.backgroundColor = [UIColor whiteColor];
-
- [self.view applyNoise];
-
CGRect sliderFrame = CGRectMake(0., 0., 320., 90.);
+ self.slider = [JMSlider sliderWithFrame:sliderFrame centerTitle:@"more" leftTitle:@"hide read" rightTitle:@"hide all" delegate:self];
- JMSlider * slider = [JMSlider sliderWithFrame:sliderFrame centerTitle:@"more" leftTitle:@"hide read" rightTitle:@"hide all" delegate:self];
+ UITableView * tableView = [CenteredTableViewController tableViewWithCenteredView:self.slider];
- slider.centerExecuteBlock = ^{ NSLog(@"executing block: center"); };
- slider.leftExecuteBlock = ^{ NSLog(@"executing block: left"); };
- slider.rightExecuteBlock = ^{ NSLog(@"executing block: right"); };
+ // Important: When including the slider in tableViews or scrollViews, I highly recommend
+ // that you set canCancelContentTouches to NO so that the table/scrollView doesn't scroll
+ // while the user is toggling the slider.
+ [tableView setCanCancelContentTouches:NO];
- [self.view addSubview:slider];
-
- [slider centerInSuperView];
+ self.view = tableView;
}
-
#pragma Mark -
#pragma Mark - JMSliderDelegate Methods
-(void)slider:(JMSlider *)slider didSelect:(JMSliderSelection)selection;
{
+ [slider setLoading:YES];
+
switch (selection)
{
case JMSliderSelectionLeft:
NSLog(@"invoked: left");
break;
-
+
case JMSliderSelectionCenter:
NSLog(@"invoked: center");
break;
-
+
case JMSliderSelectionRight:
NSLog(@"invoked: right");
break;
@@ -52,6 +56,14 @@ -(void)slider:(JMSlider *)slider didSelect:(JMSliderSelection)selection;
default:
break;
}
+
+ [self performSelector:@selector(stopSimulatedLoading) withObject:nil afterDelay:2.];
}
+- (void) stopSimulatedLoading;
+{
+ [self.slider setLoading:NO];
+}
+
+
@end
View
10 Demo/Classes/Helpers/CenteredTableViewController.h
@@ -0,0 +1,10 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import <UIKit/UIKit.h>
+
+@interface CenteredTableViewController : UITableViewController
+
+- (id)initWithCenteredView:(UIView *)centeredView;
++ (UITableView *) tableViewWithCenteredView:(UIView *)centeredView;
+
+@end
View
84 Demo/Classes/Helpers/CenteredTableViewController.m
@@ -0,0 +1,84 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import "CenteredTableViewController.h"
+#import "UIView+Positioning.h"
+#import "UIView+JMNoise.h"
+
+@interface CenteredTableViewController()
+@property (nonatomic,retain) UIView * viewForDemo;
+@end
+
+@implementation CenteredTableViewController
+
+@synthesize viewForDemo = viewForDemo_;
+
+- (void)dealloc;
+{
+ self.viewForDemo = nil;
+ [super dealloc];
+}
+
+- (void)loadView;
+{
+ [super loadView];
+
+ UIView * tableBackgroundView = [[[UIView alloc] initWithFrame:self.tableView.bounds] autorelease];
+ [tableBackgroundView applyNoiseWithOpacity:0.2];
+ self.tableView.backgroundView = tableBackgroundView;
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+
+ UIView * tableHeader = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, self.tableView.bounds.size.height / 2 - (self.viewForDemo.frame.size.height / 2))] autorelease];
+ tableHeader.backgroundColor = [UIColor clearColor];
+ [self.tableView setTableHeaderView:tableHeader];
+}
+
+- (UITableViewCell *)demoCell;
+{
+ UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DemoCell"] autorelease];
+ [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
+
+ UIView * viewForDemo = [self viewForDemo];
+ viewForDemo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
+ [cell addSubview:viewForDemo];
+ [viewForDemo centerInSuperView];
+
+ return cell;
+}
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return 1;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
+{
+ return self.viewForDemo.frame.size.height;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ return [self demoCell];
+}
+
+- (id)initWithCenteredView:(UIView *)centeredView;
+{
+ self = [super initWithStyle:UITableViewStylePlain];
+ if (self)
+ {
+ self.viewForDemo = centeredView;
+ }
+ return self;
+}
+
++ (UITableView *) tableViewWithCenteredView:(UIView *)centeredView;
+{
+ CenteredTableViewController * viewController = [[[CenteredTableViewController alloc] initWithCenteredView:centeredView] autorelease];
+ return viewController.tableView;
+}
+
+@end
View
0  Demo/Classes/DemoAppDelegate.h → Demo/Classes/Helpers/DemoAppDelegate.h
File renamed without changes
View
6 Demo/Classes/DemoAppDelegate.m → Demo/Classes/Helpers/DemoAppDelegate.m
@@ -1,7 +1,7 @@
// Created by Jason Morrissey - jasonmorrissey.org
#import "DemoAppDelegate.h"
-#import "DemoTableViewController.h"
+#import "DemoViewController.h"
@implementation DemoAppDelegate
@@ -13,11 +13,11 @@ @implementation DemoAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- DemoTableViewController * demoViewController = [[[DemoTableViewController alloc] initWithNibName:nil bundle:nil] autorelease];
+ DemoViewController * demoViewController = [[[DemoViewController alloc] initWithNibName:nil bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:demoViewController] autorelease];
[self.navigationController setNavigationBarHidden:YES];
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
View
2  Demo/Classes/UIView+JMNoise.h → Demo/Classes/Helpers/UIView+JMNoise.h
@@ -1,4 +1,4 @@
-// Created by Jason Morrissey - jasonmorrissey.org
+// Created by Jason Morrissey
#import <UIKit/UIKit.h>
View
18 Demo/Classes/UIView+JMNoise.m → Demo/Classes/Helpers/UIView+JMNoise.m
@@ -1,15 +1,15 @@
-// Created by Jason Morrissey - jasonmorrissey.org
+// Created by Jason Morrissey
#import <QuartzCore/QuartzCore.h>
#import "UIView+JMNoise.h"
#include <stdlib.h>
-#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
+#define kNoiseTileDimension 50
+#define kNoiseIntensity 250
+#define kNoiseDefaultOpacity 0.4
+#define kNoisePixelWidth 0.3
-#define kNoiseTileDimension 100
-#define kNoiseIntensity 100
-#define kNoiseDefaultOpacity 0.3
-#define kNoisePixelWidth 0.25
+#define JM_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#pragma Mark -
#pragma Mark - Noise Layer
@@ -41,6 +41,7 @@ + (UIImage *)noiseTileImage;
{
if (!JMNoiseImage)
{
+ #ifndef __clang_analyzer__
CGFloat imageScale;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
@@ -59,7 +60,7 @@ + (UIImage *)noiseTileImage;
colorSpace,kCGImageAlphaPremultipliedLast);
CFRelease(colorSpace);
- for (int i=0; i<(imageDimension * kNoiseIntensity); i++)
+ for (int i=0; i<(kNoiseTileDimension * kNoiseIntensity); i++)
{
int x = arc4random() % (imageDimension + 1);
int y = arc4random() % (imageDimension + 1);
@@ -70,7 +71,7 @@ + (UIImage *)noiseTileImage;
CGImageRef imageRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);
- if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"4.0"))
+ if (JM_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"4.0"))
{
JMNoiseImage = [[UIImage alloc] initWithCGImage:imageRef scale:imageScale orientation:UIImageOrientationUp];
}
@@ -78,6 +79,7 @@ + (UIImage *)noiseTileImage;
{
JMNoiseImage = [[UIImage alloc] initWithCGImage:imageRef];
}
+ #endif
}
return JMNoiseImage;
}
View
44 JMSlider.xcodeproj/project.pbxproj
@@ -13,17 +13,17 @@
4719176D13A490FB00567E9E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4719176C13A490FB00567E9E /* Foundation.framework */; };
4719176F13A4910000567E9E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4719176E13A4910000567E9E /* QuartzCore.framework */; };
4719177113A4910600567E9E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4719177013A4910600567E9E /* CoreGraphics.framework */; };
- 475467A113C31F0800904174 /* UIView+JMNoise.m in Sources */ = {isa = PBXBuildFile; fileRef = 475467A013C31F0800904174 /* UIView+JMNoise.m */; };
4788298413C1CE5A007E0509 /* UIView+Positioning.m in Sources */ = {isa = PBXBuildFile; fileRef = 4788297D13C1CE5A007E0509 /* UIView+Positioning.m */; };
4788298513C1CE5A007E0509 /* UIView+Size.m in Sources */ = {isa = PBXBuildFile; fileRef = 4788297F13C1CE5A007E0509 /* UIView+Size.m */; };
4788298713C1CE5A007E0509 /* JMCenterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4788298313C1CE5A007E0509 /* JMCenterView.m */; };
4788298913C1CE83007E0509 /* JMSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4788298813C1CE83007E0509 /* JMSlider.m */; };
47B98CF013C1E2FF0042592E /* JMSideView.m in Sources */ = {isa = PBXBuildFile; fileRef = 47B98CEF13C1E2FF0042592E /* JMSideView.m */; };
- 47F343E013A4AF6F00EC49ED /* DemoAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 47F343DC13A4AF6F00EC49ED /* DemoAppDelegate.m */; };
+ 47EB6BE113C821E7004D0308 /* CenteredTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 47EB6BDC13C821E7004D0308 /* CenteredTableViewController.m */; };
+ 47EB6BE213C821E7004D0308 /* DemoAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 47EB6BDE13C821E7004D0308 /* DemoAppDelegate.m */; };
+ 47EB6BE313C821E7004D0308 /* UIView+JMNoise.m in Sources */ = {isa = PBXBuildFile; fileRef = 47EB6BE013C821E7004D0308 /* UIView+JMNoise.m */; };
47F343E113A4AF6F00EC49ED /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 47F343DE13A4AF6F00EC49ED /* DemoViewController.m */; };
886B464D13C2945500191AD9 /* JMSliderTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 886B464C13C2945500191AD9 /* JMSliderTrack.m */; };
886B465413C29D0100191AD9 /* JMSliderComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 886B465313C29D0100191AD9 /* JMSliderComponent.m */; };
- 88ADC72413C40BD800C8263E /* DemoTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 88ADC72313C40BD800C8263E /* DemoTableViewController.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -36,8 +36,6 @@
4719176C13A490FB00567E9E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
4719176E13A4910000567E9E /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
4719177013A4910600567E9E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
- 4754679F13C31F0800904174 /* UIView+JMNoise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+JMNoise.h"; sourceTree = "<group>"; };
- 475467A013C31F0800904174 /* UIView+JMNoise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+JMNoise.m"; sourceTree = "<group>"; };
4788297C13C1CE5A007E0509 /* UIView+Positioning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Positioning.h"; sourceTree = "<group>"; };
4788297D13C1CE5A007E0509 /* UIView+Positioning.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Positioning.m"; sourceTree = "<group>"; };
4788297E13C1CE5A007E0509 /* UIView+Size.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Size.h"; sourceTree = "<group>"; };
@@ -48,8 +46,12 @@
47B98CEE13C1E2FF0042592E /* JMSideView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMSideView.h; sourceTree = "<group>"; };
47B98CEF13C1E2FF0042592E /* JMSideView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMSideView.m; sourceTree = "<group>"; };
47E1AEEF13C1C7B200269D16 /* JMSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMSlider.h; sourceTree = "<group>"; };
- 47F343DB13A4AF6F00EC49ED /* DemoAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoAppDelegate.h; sourceTree = "<group>"; };
- 47F343DC13A4AF6F00EC49ED /* DemoAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoAppDelegate.m; sourceTree = "<group>"; };
+ 47EB6BDB13C821E7004D0308 /* CenteredTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CenteredTableViewController.h; sourceTree = "<group>"; };
+ 47EB6BDC13C821E7004D0308 /* CenteredTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CenteredTableViewController.m; sourceTree = "<group>"; };
+ 47EB6BDD13C821E7004D0308 /* DemoAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoAppDelegate.h; sourceTree = "<group>"; };
+ 47EB6BDE13C821E7004D0308 /* DemoAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoAppDelegate.m; sourceTree = "<group>"; };
+ 47EB6BDF13C821E7004D0308 /* UIView+JMNoise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+JMNoise.h"; sourceTree = "<group>"; };
+ 47EB6BE013C821E7004D0308 /* UIView+JMNoise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+JMNoise.m"; sourceTree = "<group>"; };
47F343DD13A4AF6F00EC49ED /* DemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoViewController.h; sourceTree = "<group>"; };
47F343DE13A4AF6F00EC49ED /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = "<group>"; };
886B464B13C2945500191AD9 /* JMSliderTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMSliderTrack.h; sourceTree = "<group>"; };
@@ -57,8 +59,6 @@
886B464F13C2956F00191AD9 /* JMSliderConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMSliderConstants.h; sourceTree = "<group>"; };
886B465213C29D0000191AD9 /* JMSliderComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JMSliderComponent.h; sourceTree = "<group>"; };
886B465313C29D0100191AD9 /* JMSliderComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JMSliderComponent.m; sourceTree = "<group>"; };
- 88ADC72213C40BD800C8263E /* DemoTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoTableViewController.h; sourceTree = "<group>"; };
- 88ADC72313C40BD800C8263E /* DemoTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoTableViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -164,17 +164,25 @@
path = Internal;
sourceTree = "<group>";
};
+ 47EB6BDA13C821E7004D0308 /* Helpers */ = {
+ isa = PBXGroup;
+ children = (
+ 47EB6BDB13C821E7004D0308 /* CenteredTableViewController.h */,
+ 47EB6BDC13C821E7004D0308 /* CenteredTableViewController.m */,
+ 47EB6BDD13C821E7004D0308 /* DemoAppDelegate.h */,
+ 47EB6BDE13C821E7004D0308 /* DemoAppDelegate.m */,
+ 47EB6BDF13C821E7004D0308 /* UIView+JMNoise.h */,
+ 47EB6BE013C821E7004D0308 /* UIView+JMNoise.m */,
+ );
+ path = Helpers;
+ sourceTree = "<group>";
+ };
47F343DA13A4AF6F00EC49ED /* Classes */ = {
isa = PBXGroup;
children = (
- 4754679F13C31F0800904174 /* UIView+JMNoise.h */,
- 475467A013C31F0800904174 /* UIView+JMNoise.m */,
- 47F343DB13A4AF6F00EC49ED /* DemoAppDelegate.h */,
- 47F343DC13A4AF6F00EC49ED /* DemoAppDelegate.m */,
+ 47EB6BDA13C821E7004D0308 /* Helpers */,
47F343DD13A4AF6F00EC49ED /* DemoViewController.h */,
47F343DE13A4AF6F00EC49ED /* DemoViewController.m */,
- 88ADC72213C40BD800C8263E /* DemoTableViewController.h */,
- 88ADC72313C40BD800C8263E /* DemoTableViewController.m */,
);
path = Classes;
sourceTree = "<group>";
@@ -248,7 +256,6 @@
buildActionMask = 2147483647;
files = (
4719172A13A4875400567E9E /* main.m in Sources */,
- 47F343E013A4AF6F00EC49ED /* DemoAppDelegate.m in Sources */,
47F343E113A4AF6F00EC49ED /* DemoViewController.m in Sources */,
4788298413C1CE5A007E0509 /* UIView+Positioning.m in Sources */,
4788298513C1CE5A007E0509 /* UIView+Size.m in Sources */,
@@ -257,8 +264,9 @@
47B98CF013C1E2FF0042592E /* JMSideView.m in Sources */,
886B464D13C2945500191AD9 /* JMSliderTrack.m in Sources */,
886B465413C29D0100191AD9 /* JMSliderComponent.m in Sources */,
- 475467A113C31F0800904174 /* UIView+JMNoise.m in Sources */,
- 88ADC72413C40BD800C8263E /* DemoTableViewController.m in Sources */,
+ 47EB6BE113C821E7004D0308 /* CenteredTableViewController.m in Sources */,
+ 47EB6BE213C821E7004D0308 /* DemoAppDelegate.m in Sources */,
+ 47EB6BE313C821E7004D0308 /* UIView+JMNoise.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
4 JMSlider/Internal/JMCenterView.h
@@ -8,12 +8,12 @@
@interface JMCenterView : JMSliderComponent
- (id)initForSlider:(JMSlider *)slider withTitle:(NSString *)title;
-
+ (JMCenterView *)sliderButtonForSlider:(JMSlider *)slider withTitle:(NSString *)title;
+- (void)setLoading:(BOOL)loading;
+
// Custom drawing
- (void)drawButtonInRect:(CGRect)rect;
- (CGSize)sizeOfButton;
-
@end
View
33 JMSlider/Internal/JMCenterView.m
@@ -2,9 +2,11 @@
#import "JMCenterView.h"
#import "JMSlider.h"
+#import "UIView+Positioning.h"
@interface JMCenterView()
@property (assign) CGPoint touchStartPoint;
+@property (nonatomic,retain) UIActivityIndicatorView * activityView;
- (CGPoint)touchPoint:(NSSet *)touches;
- (void)drawButtonInRect:(CGRect)rect;
- (CGSize)sizeOfButton;
@@ -13,9 +15,11 @@ - (CGSize)sizeOfButton;
@implementation JMCenterView
@synthesize touchStartPoint = touchStartPoint_;
+@synthesize activityView = activityView_;
- (void)dealloc;
{
+ self.activityView = nil;
[super dealloc];
}
@@ -50,9 +54,12 @@ - (void)drawButtonInRect:(CGRect)rect;
[outline stroke];
}
- CGFloat textOpacity = 1. - fabs([self.slider slideRatio]);
- [[UIColor colorWithWhite:1. alpha:textOpacity] set];
- [self.title drawInRect:CGRectOffset(rect, 0, kJMButtonPadding.height -1.) withFont:kJMButtonFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentCenter];
+ if (!activityView_)
+ {
+ CGFloat textOpacity = 1. - fabs([self.slider slideRatio]);
+ [[UIColor colorWithWhite:1. alpha:textOpacity] set];
+ [self.title drawInRect:CGRectOffset(rect, 0, kJMButtonPadding.height -1.) withFont:kJMButtonFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentCenter];
+ }
}
- (CGSize)sizeOfButton;
@@ -101,6 +108,26 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
[super touchesEnded:touches withEvent:event];
[self.slider releaseDragShouldCancel:NO];
}
+
+#pragma Mark -
+#pragma Mark - Loading State
+
+- (void)setLoading:(BOOL)loading;
+{
+ [self.activityView removeFromSuperview];
+ self.activityView = nil;
+
+ if (loading)
+ {
+ self.activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
+ self.activityView.autoresizesSubviews = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
+ [self.activityView startAnimating];
+ [self addSubview:self.activityView];
+ [self.activityView centerInSuperView];
+ }
+ [self setNeedsDisplay];
+}
+
#pragma Mark -
#pragma Mark - Factories
View
2  JMSlider/Internal/JMSliderConstants.h
@@ -5,7 +5,7 @@
#define kJMButtonPadding CGSizeMake(34., 8.)
#define kJMButtonFont [UIFont fontWithName:@"HelveticaNeue" size:14.]
-#define kJMSliderButtonInvisiblePadding CGSizeMake(30., 20.)
+#define kJMSliderButtonInvisiblePadding CGSizeMake(40., 30.)
#define kJMButtonColor [UIColor colorWithWhite:0.7 alpha:1.]
#define kJMButtonOutlineColor [UIColor colorWithWhite:0. alpha:0.1]
View
2  JMSlider/Internal/JMSliderTrack.m
@@ -31,7 +31,7 @@ - (void)drawRect:(CGRect)rect;
CGRect rightEdgeRect = CGRectMake(CGRectGetMaxX(trackRect) + kJMSliderTrackEdgeRadius, CGRectGetMidY(trackRect) - 0.5, 1., 1.);
UIBezierPath * rightEdgePath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(rightEdgeRect, -1. * kJMSliderTrackEdgeRadius, -1. * kJMSliderTrackEdgeRadius)];
[rightEdgePath fill];
- }
+ }
}
+ (JMSliderTrack *)sliderTrackForSlider:(JMSlider *)slider;
View
2  JMSlider/JMSlider.h
@@ -62,5 +62,7 @@ typedef void(^JMSliderExecutionBlock)(void);
+ (JMSlider *) sliderWithFrame:(CGRect)frame centerTitle:(NSString *)centerTitle leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle delegate:(id<JMSliderDelegate>)delegate;
+ (JMSlider *) sliderWithFrame:(CGRect)frame delegate:(id<JMSliderDelegate>)delegate;
+- (void)setLoading:(BOOL)loading;
+
@end
View
6 JMSlider/JMSlider.m
@@ -178,7 +178,6 @@ - (void)releaseDragShouldCancel:(BOOL)cancelled;
{
self.suppressCallbacks = YES;
[self.delegate slider:self didSelect:JMSliderSelectionLeft];
-// [self.delegate performSelector:@selector(slider:didSelect:) withObject:self withObject:JMSliderSelectionLeft];
#if NS_BLOCKS_AVAILABLE
if (leftExecuteBlock_) leftExecuteBlock_();
#endif
@@ -211,6 +210,11 @@ - (void)tappedCenterView;
}
}
+- (void)setLoading:(BOOL)loading;
+{
+ [self.centerView setLoading:loading];
+}
+
#pragma Mark -
#pragma Mark - Subview Generation
View
59 readme.md
@@ -0,0 +1,59 @@
+## JMSlider
+
+JMSlider is a sliding component that can be used to toggle three actions. It's main purpose is to allow for multiple actions at the end of lists/tables while keeping visual clutter to a minimum. The component is rendered entirely using **Core Graphics** so it does not require any additional images to be used in your projects.
+
+## How it looks
+
+Here's a video that demonstrates how JMSlider behaves out of the box:
+
+<iframe width="560" height="349" src="http://www.youtube.com/embed/GV40mAwcCrI?hd=1" frameborder="0" allowfullscreen></iframe>
+
+Or an image for convenience:
+
+<img src="http://alienblue.org/github/JMSlider-sequence.png" width=349 height=900 />
+
+## Usage
+
+A demo project is included in the repository so that you can give it a test drive.
+
+`JMSlider *slider = [JMSlider sliderWithFrame:sliderFrame centerTitle:@"more" leftTitle:@"hide read" rightTitle:@"hide all" delegate:self];`
+
+By implementing the `slider:didSelect:` method, you will receive a callback when the tab selection changes.
+
+## Flexibility
+
+JMSlider also supports the execution of blocks so that you can embed your logic inline, like this:
+
+`[slider setLeftExecuteBlock:^{
+ // do stuff after left option has been selected
+}];`
+
+## Loading Indicator
+
+The slider has a built-in activity indicator for convenience. To turn the activity indicator on:
+
+`[slider setLoading:YES];`
+
+The Demo project included also demonstrates how this can be used in your code.
+
+## Customisation
+
+You can subclass any of the slider's internal components, and then implement any/all of the following methods in your delegate:
+
+`-(JMCenterView *)sliderCenterViewForSlider:(JMSlider *)slider`
+
+`-(JMSideView *)sliderLeftViewForSlider:(JMSlider *)slider`
+
+`-(JMSideView *)sliderRightViewForSlider:(JMSlider *)slider`
+
+`-(JMSliderTrack *)sliderTrackViewForSlider:(JMSlider *)slider`
+
+For example, Alien Blue subclasses JMCenterView to draw a dark version of the toggle in Night Mode.
+
+## Acknowledgements
+
+This project uses the UIView+Positioning and UIView+Size categories developed by the very talented [Kevin O'Neill](https://github.com/kevinoneill/Useful-Bits).
+
+## License
+
+JMSlider is BSD licensed, so you can freely use it in commercial applications.

0 comments on commit e135e36

Please sign in to comment.
Something went wrong with that request. Please try again.