Skip to content

Commit

Permalink
Big ol 2.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkimmett committed Jan 28, 2014
1 parent 474beee commit 1d86594
Show file tree
Hide file tree
Showing 22 changed files with 890 additions and 264 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
Pods/*
*.app.dSYM.zip
*.ipa
build
*.xccheckout
14 changes: 14 additions & 0 deletions NKToggleOverlayButton.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Pod::Spec.new do |s|
s.name = "NKToggleOverlayButton"
s.version = "2.0.0"
s.license = 'MIT'
s.summary = "NKToggleOverlayButton is a two state button that displays a translucent overlay when it's state is changed."
s.homepage = "https://github.com/neilkimmett/NKToggleOverlayButton"
s.screenshots = "https://raw.github.com/neilkimmett/NKToggleOverlayButton/master/animation.gif"
s.author = { "Neil Kimmett" => "neilkimmett@gmail.com" }
s.source = { :git => "https://github.com/neilkimmett/NKToggleOverlayButton.git", :tag => 'v2.0.0' }
s.platform = :ios, '5.0'
s.source_files = 'NKToggleOverlayButton/NKToggleOverlayButton'
s.public_header_files = 'NKToggleOverlayButton/NKToggleOverlayButton'
s.requires_arc = true
end
36 changes: 36 additions & 0 deletions NKToggleOverlayButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
2871583815C4378000A1477D /* on-press@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2871583015C4378000A1477D /* on-press@2x.png */; };
2871583915C4378000A1477D /* on.png in Resources */ = {isa = PBXBuildFile; fileRef = 2871583115C4378000A1477D /* on.png */; };
2871583A15C4378000A1477D /* on@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2871583215C4378000A1477D /* on@2x.png */; };
28D4D189189811AD008B0621 /* UIImage+ImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D4D188189811AD008B0621 /* UIImage+ImageEffects.m */; };
28D4D18A189811E4008B0621 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2871583B15C43FD700A1477D /* QuartzCore.framework */; };
28D4D18C189811FF008B0621 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28D4D18B189811FF008B0621 /* Accelerate.framework */; };
28D4D18F189812AD008B0621 /* NKArchIndependentRounding.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D4D18E189812AD008B0621 /* NKArchIndependentRounding.m */; };
28D4D19418981561008B0621 /* thin-cross.png in Resources */ = {isa = PBXBuildFile; fileRef = 28D4D19018981561008B0621 /* thin-cross.png */; };
28D4D19518981561008B0621 /* thin-cross@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 28D4D19118981561008B0621 /* thin-cross@2x.png */; };
28D4D19618981561008B0621 /* thin-tick.png in Resources */ = {isa = PBXBuildFile; fileRef = 28D4D19218981561008B0621 /* thin-tick.png */; };
28D4D19718981561008B0621 /* thin-tick@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 28D4D19318981561008B0621 /* thin-tick@2x.png */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -59,13 +67,24 @@
2871583115C4378000A1477D /* on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = on.png; path = Images/on.png; sourceTree = "<group>"; };
2871583215C4378000A1477D /* on@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "on@2x.png"; path = "Images/on@2x.png"; sourceTree = "<group>"; };
2871583B15C43FD700A1477D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
28D4D187189811AD008B0621 /* UIImage+ImageEffects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ImageEffects.h"; sourceTree = "<group>"; };
28D4D188189811AD008B0621 /* UIImage+ImageEffects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ImageEffects.m"; sourceTree = "<group>"; };
28D4D18B189811FF008B0621 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
28D4D18D189812AD008B0621 /* NKArchIndependentRounding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NKArchIndependentRounding.h; sourceTree = "<group>"; };
28D4D18E189812AD008B0621 /* NKArchIndependentRounding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NKArchIndependentRounding.m; sourceTree = "<group>"; };
28D4D19018981561008B0621 /* thin-cross.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "thin-cross.png"; path = "Images/thin-cross.png"; sourceTree = "<group>"; };
28D4D19118981561008B0621 /* thin-cross@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "thin-cross@2x.png"; path = "Images/thin-cross@2x.png"; sourceTree = "<group>"; };
28D4D19218981561008B0621 /* thin-tick.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "thin-tick.png"; path = "Images/thin-tick.png"; sourceTree = "<group>"; };
28D4D19318981561008B0621 /* thin-tick@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "thin-tick@2x.png"; path = "Images/thin-tick@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
283659AF15B17D1900ECD392 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
28D4D18C189811FF008B0621 /* Accelerate.framework in Frameworks */,
28D4D18A189811E4008B0621 /* QuartzCore.framework in Frameworks */,
283659B715B17D1900ECD392 /* UIKit.framework in Frameworks */,
283659B915B17D1900ECD392 /* Foundation.framework in Frameworks */,
283659BB15B17D1900ECD392 /* CoreGraphics.framework in Frameworks */,
Expand Down Expand Up @@ -96,6 +115,7 @@
283659B515B17D1900ECD392 /* Frameworks */ = {
isa = PBXGroup;
children = (
28D4D18B189811FF008B0621 /* Accelerate.framework */,
283659B615B17D1900ECD392 /* UIKit.framework */,
283659B815B17D1900ECD392 /* Foundation.framework */,
283659BA15B17D1900ECD392 /* CoreGraphics.framework */,
Expand Down Expand Up @@ -134,6 +154,10 @@
2871581415C3147900A1477D /* Images */,
283659D715B17D5700ECD392 /* NKToggleOverlayButton.h */,
283659D815B17D5700ECD392 /* NKToggleOverlayButton.m */,
28D4D18D189812AD008B0621 /* NKArchIndependentRounding.h */,
28D4D18E189812AD008B0621 /* NKArchIndependentRounding.m */,
28D4D187189811AD008B0621 /* UIImage+ImageEffects.h */,
28D4D188189811AD008B0621 /* UIImage+ImageEffects.m */,
);
path = NKToggleOverlayButton;
sourceTree = "<group>";
Expand All @@ -145,6 +169,10 @@
2871582315C4376B00A1477D /* cross@2x.png */,
2871582415C4376B00A1477D /* tick.png */,
2871582515C4376B00A1477D /* tick@2x.png */,
28D4D19018981561008B0621 /* thin-cross.png */,
28D4D19118981561008B0621 /* thin-cross@2x.png */,
28D4D19218981561008B0621 /* thin-tick.png */,
28D4D19318981561008B0621 /* thin-tick@2x.png */,
);
name = Images;
sourceTree = "<group>";
Expand Down Expand Up @@ -218,12 +246,16 @@
buildActionMask = 2147483647;
files = (
283659C115B17D1900ECD392 /* InfoPlist.strings in Resources */,
28D4D19418981561008B0621 /* thin-cross.png in Resources */,
2871582615C4376B00A1477D /* cross.png in Resources */,
2871582715C4376B00A1477D /* cross@2x.png in Resources */,
28D4D19718981561008B0621 /* thin-tick@2x.png in Resources */,
2871582815C4376B00A1477D /* tick.png in Resources */,
2871582915C4376B00A1477D /* tick@2x.png in Resources */,
28D4D19618981561008B0621 /* thin-tick.png in Resources */,
2871583315C4378000A1477D /* off-press.png in Resources */,
2871583415C4378000A1477D /* off-press@2x.png in Resources */,
28D4D19518981561008B0621 /* thin-cross@2x.png in Resources */,
2871583515C4378000A1477D /* off.png in Resources */,
2871583615C4378000A1477D /* off@2x.png in Resources */,
2871583715C4378000A1477D /* on-press.png in Resources */,
Expand All @@ -242,6 +274,8 @@
buildActionMask = 2147483647;
files = (
283659C315B17D1900ECD392 /* main.m in Sources */,
28D4D18F189812AD008B0621 /* NKArchIndependentRounding.m in Sources */,
28D4D189189811AD008B0621 /* UIImage+ImageEffects.m in Sources */,
283659C715B17D1900ECD392 /* NKAppDelegate.m in Sources */,
283659CA15B17D1900ECD392 /* NKViewController.m in Sources */,
283659D915B17D5700ECD392 /* NKToggleOverlayButton.m in Sources */,
Expand Down Expand Up @@ -316,6 +350,7 @@
283659D415B17D1900ECD392 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NKToggleOverlayButton/NKToggleOverlayButton-Prefix.pch";
INFOPLIST_FILE = "NKToggleOverlayButton/NKToggleOverlayButton-Info.plist";
Expand All @@ -327,6 +362,7 @@
283659D515B17D1900ECD392 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NKToggleOverlayButton/NKToggleOverlayButton-Prefix.pch";
INFOPLIST_FILE = "NKToggleOverlayButton/NKToggleOverlayButton-Info.plist";
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion NKToggleOverlayButton/NKAppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of NKToggleOverlayButton.
Copyright (c) 2012, Neil Kimmett
Copyright (c) 2014, Neil Kimmett
All rights reserved.
Permission is hereby granted, free of charge, to any person
Expand Down
12 changes: 3 additions & 9 deletions NKToggleOverlayButton/NKAppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of NKToggleOverlayButton.
Copyright (c) 2012, Neil Kimmett
Copyright (c) 2014, Neil Kimmett
All rights reserved.
Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -39,18 +39,12 @@ @implementation NKAppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;

- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[[NKViewController alloc] init] autorelease];
self.viewController = [[NKViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// NKArchIndependentRounding.h
//

/*
* CREDIT TO SIMON WHITAKER: https://gist.github.com/simonwhitaker/8213159
*
* Calling math.h functions like `floor` and `floorf` on CGFloat variables
* becomes problematic when compiling the same code for both 32-bit and
* 64-bit platforms, since CGFloat is double on 64-bit, float on 32-bit.
* Hence, if you compile with -Wconversion set, `floorf` will give a warning
* on 64-bit, while `floor` gives a warning on 32-bit.
*
* Here's a suggested implementation of an architecture-independent `floor`
* function, written using plain old function overloading which is enabled
* using the `__attribute__((overloadable))` Clang language extension.
*
* See http://clang.llvm.org/docs/LanguageExtensions.html#function-overloading-in-c
*/

float __attribute__((overloadable)) nk_floor(float f);
double __attribute__((overloadable)) nk_floor(double d);

float __attribute__((overloadable)) nk_ceil(float f);
double __attribute__((overloadable)) nk_ceil(double d);

float __attribute__((overloadable)) nk_round(float f);
double __attribute__((overloadable)) nk_round(double d);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NKArchIndependentRounding.m
//


#import "NKArchIndependentRounding.h"

float __attribute__((overloadable)) nk_floor(float f) { return floorf(f); }
double __attribute__((overloadable)) nk_floor(double d) { return floor(d); }

float __attribute__((overloadable)) nk_ceil(float f) { return ceilf(f); }
double __attribute__((overloadable)) nk_ceil(double d) { return ceil(d); }

float __attribute__((overloadable)) nk_round(float f) { return roundf(f); }
double __attribute__((overloadable)) nk_round(double d) { return round(d); }
76 changes: 45 additions & 31 deletions NKToggleOverlayButton/NKToggleOverlayButton/NKToggleOverlayButton.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of NKToggleOverlayButton.
Copyright (c) 2012, Neil Kimmett
Copyright (c) 2014, Neil Kimmett
All rights reserved.
Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -30,59 +30,73 @@
*
*/

#if NS_BLOCKS_AVAILABLE

@protocol NKToggleOverlayButtonDelegate;
#if NS_BLOCKS_AVAILABLE

@class NKToggleOverlayButton;

typedef void (^NKToggleActionBlock)(NKToggleOverlayButton *button);

#import <UIKit/UIKit.h>

#define kNotifyInterestUpdated @"ListingInterestDidUpdate"
/**
NKToggleOverlayButton is a two state button that displays a translucent overlay when it's state is changed.
@interface NKToggleOverlayButton : UIView
Behaviour can be attached to the button by assigning action blocks to the toggleOnBlock and toggleOffBlock properties. Alternatively you can use addTarget:action:forControlEvents to add a target/action pair for the control event UIControlEventValueChanged (for when the button state is toggled) or UIControlEventTouchUpInside (for when the button is tapped)
*/
@interface NKToggleOverlayButton : UIControl

/**
Programmatically toggles the button's on/off state
@param animated Toggles whether to show the animated overlay
*/
- (void)toggleSelectedAnimated:(BOOL)animated;

// Images used to set the on/off images for different control states,
// analogous to the setImage:forState: method of UIButton
/**
Sets the the button's on/off state. Use -isSelected (declared in superclass UIControl) to query button's current state. Use -setSelected: (declared in superclass UIControl) to set the button's on/off state without triggering toggle[On|Off]Block to be executed.
@param selected If true toggles the button on, if false toggles the button off
@param animated Toggles whether to show the animated overlay
*/
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;

/**
Assign an image to be used for the given state when the button is on
@param image The image to be used
@param state The control state to assign the given image for
*/
- (void)setOnImage:(UIImage *)image forState:(UIControlState)state;

/**
Assign an image to be used for the given state when the button is off
@param image The image to be used
@param state The control state to assign the given image for
*/
- (void)setOffImage:(UIImage *)image forState:(UIControlState)state;

// Title label
@property (nonatomic, retain) UILabel *titleLabel;
/// A label that occupies the whole bounds of the button
@property (nonatomic, strong, readonly) UILabel *titleLabel;

// Used to turn the overlay animation on or off (default on)
/// Whether to display the animated overlay or not
@property (nonatomic, assign) BOOL showOverlay;

// Used to determine the on/off state of the button (default off)
@property (nonatomic, assign) BOOL isOn;

// Text that is displayed in the overlay when button is toggled on/off
/// Text that is displayed in the animated overlay when the button is toggled on
@property (nonatomic, copy) NSString *overlayOnText;

/// Text that is displayed in the animated overlay when the button is toggled off
@property (nonatomic, copy) NSString *overlayOffText;

// Image displayed in the overlay when button is toggled on/off
@property (nonatomic, retain) UIImage *overlayOnImage;
@property (nonatomic, retain) UIImage *overlayOffImage;
/// Image that is displayed in the animated overlay when the button is toggled on
@property (nonatomic, strong) UIImage *overlayOnImage;

// Blocks that are executed when the button is toggled on/off
//
// Remember to be careful not to create a retain cycle by capturing
// self strongly in these blocks; instead use a weak __block reference
// to self
@property (nonatomic, copy) NKToggleActionBlock toggleOnBlock;
@property (nonatomic, copy) NKToggleActionBlock toggleOffBlock;
/// Image that is displayed in the animated overlay when the button is toggled off
@property (nonatomic, strong) UIImage *overlayOffImage;

// Delegate for if you want to kick it old school
@property (nonatomic, assign) id<NKToggleOverlayButtonDelegate> delegate;

@end
/// Block that is executed when the button is toggled on
@property (nonatomic, copy) NKToggleActionBlock toggleOnBlock;

/// Block that is executed when the button is toggled off
@property (nonatomic, copy) NKToggleActionBlock toggleOffBlock;

@protocol NKToggleOverlayButtonDelegate <NSObject>
@optional
- (void)toggleButtonDidToggle:(NKToggleOverlayButton *)button;
@end

#endif
Loading

0 comments on commit 1d86594

Please sign in to comment.