Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing UIColor-Expanded dependency #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Mac OS X
*.DS_Store
*._*
*.psd

# Xcode
Expand All @@ -17,4 +18,4 @@ build/
*.pyc

# Backup files
*~.nib
*~.nib
6 changes: 3 additions & 3 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

A different license may apply to other software included in this package,
including Erica Sadun's UIColor-Extended category. Please consult their
respective headers for the terms of their individual licenses.
A different license may apply to other software included in this
package. Please consult their respective headers for the terms of
their individual licenses.
4 changes: 4 additions & 0 deletions MAConfirmButton/MAConfirmButton.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ typedef enum {
CALayer *colorLayer;
CALayer *darkenLayer;
UIButton *cancelOverlay;
BOOL ensureAccessibleTouch;
CGRect touchBounds;
}

@property (nonatomic, assign) MAConfirmButtonToggleAnimation toggleAnimation;
Expand All @@ -36,5 +38,7 @@ typedef enum {
- (void)disableWithTitle:(NSString *)disabledString;
- (void)setAnchor:(CGPoint)anchor;
- (void)setTintColor:(UIColor *)color;
- (void)setEnsureAccessibleTouch:(BOOL)flag;
- (void)reset;

@end
57 changes: 55 additions & 2 deletions MAConfirmButton/MAConfirmButton.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

#import "MAConfirmButton.h"
#import "UIColor-Expanded.h"

#define kHeight 26.0
#define kPadding 20.0
Expand Down Expand Up @@ -272,7 +271,23 @@ - (void)setAnchor:(CGPoint)anchor{
}

- (void)setTintColor:(UIColor *)color{
self.tint = [UIColor colorWithHue:color.hue saturation:color.saturation+0.15 brightness:color.brightness alpha:1];
// Slightly raise the saturation. However, this requires an iOS 5 method, so check if it exists:
if ([color respondsToSelector:@selector(getHue:saturation:brightness:alpha:)]) {
CGFloat hue = 0.0f, saturation = 0.0f, brightness = 0.0f;
CGFloat alpha = 1.0f;
BOOL success = [color getHue:&hue saturation:&saturation brightness:&brightness alpha:nil];
if (success) {
self.tint = [UIColor colorWithHue:hue saturation:saturation+0.15 brightness:brightness alpha:alpha];
} else {
// Fallback in case getHue:saturation:brightness:alpha: failed
self.tint = color;
}
} else {
// Can't get HSB components (iOS <= 4.x). So just use the original color
// passed without raising saturation. No big visual difference anyhow.
self.tint = color;
}

colorLayer.backgroundColor = tint.CGColor;
[self setNeedsDisplay];
}
Expand Down Expand Up @@ -336,5 +351,43 @@ - (void)cancel{
self.selected = NO;
}

- (void)reset {
confirmed = NO;
[self cancel];
}

#pragma mark - Accessible touch

- (void)updateTouchBounds {
CGRect bounds = self.frame;
bounds.origin.x = bounds.origin.y = 0;
if (ensureAccessibleTouch) {
if (bounds.size.width < 44) {
CGFloat delta = 44 - bounds.size.width;
bounds.origin.x -= delta / 2;
bounds.size.width += delta;
}
if (bounds.size.height < 44) {
CGFloat delta = 44 - bounds.size.height;
bounds.origin.y -= delta / 2;
bounds.size.height += delta;
}
}
touchBounds = bounds;
}

- (void)setEnsureAccessibleTouch:(BOOL)flag {
ensureAccessibleTouch = flag;
[self updateTouchBounds];
}

- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
[self updateTouchBounds];
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return CGRectContainsPoint(touchBounds, point) ? self : nil;
}

@end
96 changes: 0 additions & 96 deletions MAConfirmButton/UIColor-Expanded.h

This file was deleted.

Loading