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

Collection of PR's. #113

Open
wants to merge 11 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@

## Notice

Since it dosen't seem like the original repo is actively maintained, I will from now on maintain this fork. Many of the PRs from the original repo has been merged and implemented in this branch.

SIAlertView
=============

An UIAlertView replacement with block syntax and fancy transition styles. As seen in [Grid Diary](http://griddiaryapp.com/).

[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=Sumi-Interactive&url=https://github.com/Sumi-Interactive/SIAlertView&title=SIAlertView&tags=github&category=software)


## Preview

![SIAlertView Screenshot](https://github.com/Sumi-Interactive/SIAlertView/raw/master/screenshot.png)
Expand Down Expand Up @@ -42,7 +48,7 @@ An UIAlertView replacement with block syntax and fancy transition styles. As see
**Code:**

```objc
SIAlertView *alertView = [[SIAlertView alloc] initWithTitle:@"SIAlertView" andMessage:@"Sumi Interactive"];
SIAlertView *alertView = [[SIAlertView alloc] initWithTitle:@"SIAlertView" message:@"Sumi Interactive"];

[alertView addButtonWithTitle:@"Button1"
type:SIAlertViewButtonTypeDefault
Expand Down
24 changes: 24 additions & 0 deletions SIAlertView/SIAlertBackgroundWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// SIAlertBackgroundWindow.h
// SIAlertView
//


#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, SIAlertViewBackgroundStyle) {
SIAlertViewBackgroundStyleGradient,
SIAlertViewBackgroundStyleSolid,
SIAlertViewBackgroundStyleClear
};

const UIWindowLevel UIWindowLevelSIAlert;
const UIWindowLevel UIWindowLevelSIAlertBackground;

@interface SIAlertBackgroundWindow : UIWindow

#pragma mark - Initialization

- (id)initWithFrame:(CGRect)frame andStyle:(SIAlertViewBackgroundStyle)style;

@end
76 changes: 76 additions & 0 deletions SIAlertView/SIAlertBackgroundWindow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// SIAlertBackgroundWindow.m
// SIAlertView
//


#import "SIAlertBackgroundWindow.h"

const UIWindowLevel UIWindowLevelSIAlert = 1996.0; // don't overlap system's alert
const UIWindowLevel UIWindowLevelSIAlertBackground = 1985.0; // below the alert window

@interface SIAlertBackgroundWindow ()

@property (nonatomic, assign) SIAlertViewBackgroundStyle style;

@end



@implementation SIAlertBackgroundWindow

#pragma mark - Initialization

- (id)initWithFrame:(CGRect)frame andStyle:(SIAlertViewBackgroundStyle)style
{
self = [super initWithFrame:frame];
if(self) {
_style = style;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.opaque = NO;
self.windowLevel = UIWindowLevelSIAlertBackground;
}
return self;
}

#pragma mark - Drawing

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();

switch (self.style) {
case SIAlertViewBackgroundStyleGradient:
{
size_t locationsCount = 2;
CGFloat locations[2] = {0.0f, 1.0f};
CGFloat colors[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
CGColorSpaceRelease(colorSpace);

CGPoint center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
CGFloat radius = MIN(self.bounds.size.width, self.bounds.size.height) ;
CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
}
break;
case SIAlertViewBackgroundStyleSolid:
{

[[UIColor colorWithWhite:0 alpha:0.5] set];
CGContextFillRect(context, self.bounds);

}
break;
case SIAlertViewBackgroundStyleClear:
{
[[UIColor clearColor] set];
CGContextFillRect(context, self.bounds);
}
}

[super drawRect:rect];
}

@end
49 changes: 49 additions & 0 deletions SIAlertView/SIAlertButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SIAlertButton.h
// SIAlertView
//


#import <Foundation/Foundation.h>

@class SIAlertView;

typedef NS_ENUM(NSInteger, SIAlertViewButtonType) {
SIAlertViewButtonTypeOK,
SIAlertViewButtonTypeCancel,
SIAlertViewButtonTypePrimary,
SIAlertViewButtonTypeInfo,
SIAlertViewButtonTypeSuccess,
SIAlertViewButtonTypeWarning,
SIAlertViewButtonTypeDanger,
SIAlertViewButtonTypeInverse,
SIAlertViewButtonTypeTwitter,
SIAlertViewButtonTypeFacebook,
SIAlertViewButtonTypePurple
};

typedef void(^SIAlertViewHandler)(SIAlertView *alertView);

@interface SIAlertButton : UIButton

@property (nonatomic, copy) NSString *title;
@property (nonatomic, assign) SIAlertViewButtonType type;
@property (nonatomic, copy) SIAlertViewHandler action;

#pragma mark - Initialization

+ (SIAlertButton *)alertButtonWithTitle:(NSString *)aTitle
type:(SIAlertViewButtonType)aType
action:(SIAlertViewHandler)anAction
font:(UIFont *)aFont
tag:(NSInteger)aTag
enabled:(BOOL)enabled;

+ (SIAlertButton *)alertButtonWithTitle:(NSString *)aTitle
color:(UIColor *)aColor
action:(SIAlertViewHandler)anAction
font:(UIFont *)aFont
tag:(NSInteger)aTag
enabled:(BOOL)enabled;

@end
167 changes: 167 additions & 0 deletions SIAlertView/SIAlertButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
//
// SIAlertButton.m
// SIAlertView
//


#import "SIAlertButton.h"
#import "UIColor+SIAlertView.h"

@interface SIAlertButton ()

@property (strong, nonatomic) UIColor *color;

+ (UIColor *)colorForButtonType:(SIAlertViewButtonType)aType;

@end



@implementation SIAlertButton

@synthesize color;

#pragma mark - Initialization

+ (SIAlertButton *)alertButtonWithTitle:(NSString *)aTitle
type:(SIAlertViewButtonType)aType
action:(SIAlertViewHandler)anAction
font:(UIFont *)aFont
tag:(NSInteger)aTag
enabled:(BOOL)enabled
{
SIAlertButton *button = [SIAlertButton buttonWithType:UIButtonTypeCustom];
button.action = anAction;
button.tag = aTag;
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
button.titleLabel.font = aFont;
button.enabled = enabled;
[button setTitle:aTitle forState:UIControlStateNormal];
button.color = [SIAlertButton colorForButtonType:aType];
return button;
}

+ (SIAlertButton *)alertButtonWithTitle:(NSString *)aTitle
color:(UIColor *)aColor
action:(SIAlertViewHandler)anAction
font:(UIFont *)aFont
tag:(NSInteger)aTag
enabled:(BOOL)enabled
{
SIAlertButton *button = [SIAlertButton buttonWithType:UIButtonTypeCustom];
button.action = anAction;
button.tag = aTag;
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
button.titleLabel.font = aFont;
button.enabled = enabled;
[button setTitle:aTitle forState:UIControlStateNormal];
button.color = aColor;
return button;
}

#pragma mark - Setters

- (void)setColor:(UIColor *)newColor
{
color = newColor;

if([newColor SIIsLightColor]) {
[self setTitleColor:[UIColor colorWithWhite:0.35f alpha:1.0f] forState:UIControlStateNormal];
[self setTitleColor:[UIColor colorWithWhite:0.35f alpha:0.8f] forState:UIControlStateHighlighted];
}
else {
[self setTitleColor:[UIColor colorWithWhite:1.0f alpha:1.0f] forState:UIControlStateNormal];
[self setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.8f] forState:UIControlStateHighlighted];
}

[self setNeedsDisplay];
}

#pragma mark - Utilities
+ (UIColor *)colorForButtonType:(SIAlertViewButtonType)aType
{
switch (aType) {
case SIAlertViewButtonTypePrimary:
return [UIColor colorWithHue:215.0f/360.0f saturation:0.82f brightness:0.84f alpha:1.0f];

case SIAlertViewButtonTypeInfo:
return [UIColor colorWithHue:194.0f/360.0f saturation:0.75f brightness:0.74f alpha:1.0f];

case SIAlertViewButtonTypeSuccess:
return [UIColor colorWithHue:116.0f/360.0f saturation:0.5f brightness:0.74f alpha:1.0f];

case SIAlertViewButtonTypeWarning:
return [UIColor colorWithHue:35.0f/360.0f saturation:0.90f brightness:0.96f alpha:1.0f];

case SIAlertViewButtonTypeDanger:
return [UIColor colorWithHue:3.0f/360.0f saturation:0.76f brightness:0.88f alpha:1.0f];

case SIAlertViewButtonTypeInverse:
return [UIColor colorWithHue:0.0f saturation:0.0f brightness:0.2f alpha:1.0f];

case SIAlertViewButtonTypeTwitter:
return [UIColor colorWithHue:212.0f/360.0f saturation:0.75f brightness:1.0f alpha:1.0f];

case SIAlertViewButtonTypeFacebook:
return [UIColor colorWithHue:220.0f/360.0f saturation:0.62f brightness:0.6f alpha:1.0f];

case SIAlertViewButtonTypePurple:
return [UIColor colorWithHue:260.0f/360.0f saturation:0.45f brightness:0.75f alpha:1.0f];

case SIAlertViewButtonTypeCancel:
return [UIColor colorWithHue:0.0f saturation:0.0f brightness:0.7f alpha:1.0f];

case SIAlertViewButtonTypeOK:
default:
return [UIColor colorWithHue:0.0f saturation:0.0f brightness:0.94f alpha:1.0f];
}
}

#pragma mark - UIButton

- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self setNeedsDisplay];
}

- (void)setTitle:(NSString *)title {

_title = title;
[self setNeedsDisplay];
}

- (void)setEnabled:(BOOL)enabled {

self.alpha = enabled ? 1 : 0.5;
self.userInteractionEnabled = enabled ? YES : NO;
[self setNeedsDisplay];
}

#pragma mark - Drawing

- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);

UIColor *fill = (!self.highlighted) ? self.color : [self.color SIDarkenColorWithValue:0.06f];
CGContextSetFillColorWithColor(context, fill.CGColor);

UIColor *border = (!self.highlighted) ? [self.color SIDarkenColorWithValue:0.06f] : [self.color SIDarkenColorWithValue:0.12f];
CGContextSetStrokeColorWithColor(context, border.CGColor);

CGContextSetLineWidth(context, 1.0f);

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0.5f, 0.5f, rect.size.width-1.0f, rect.size.height-1.0f)
cornerRadius:3.5f];

CGContextAddPath(context, path.CGPath);
CGContextDrawPath(context, kCGPathFillStroke);

CGContextRestoreGState(context);
}

@end
Binary file removed SIAlertView/SIAlertView.bundle/button-cancel-d.png
Binary file not shown.
Binary file not shown.
Binary file removed SIAlertView/SIAlertView.bundle/button-cancel.png
Binary file not shown.
Binary file removed SIAlertView/SIAlertView.bundle/button-cancel@2x.png
Binary file not shown.
Binary file removed SIAlertView/SIAlertView.bundle/button-default-d.png
Binary file not shown.
Binary file not shown.
Binary file removed SIAlertView/SIAlertView.bundle/button-default.png
Binary file not shown.
Binary file removed SIAlertView/SIAlertView.bundle/button-default@2x.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.