Created
July 25, 2015 14:24
-
-
Save TheFinestArtist/15056d2e7e82e69af0e7 to your computer and use it in GitHub Desktop.
SDCAlertView+Custom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SDCAlertView+Custom.h | |
// Custom | |
// | |
// Created by The Finest Artist | |
// | |
// | |
#import <SDCAlertView/SDCAlertController.h> | |
@interface SDCAlertController (Custom) | |
+ (void)okWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(SDCAlertAction *))handler; | |
+ (void)alertWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(SDCAlertAction *))handler; | |
+ (void)deleteAlertWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(SDCAlertAction *))handler; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SDCAlertView+Custom.m | |
// Custom | |
// | |
// Created by The Finest Artist | |
// | |
// | |
#import "SDCAlertController+Custom.h" | |
#import <SDCAlertView/SDCAlertControllerVisualStyle.h> | |
@interface CustomAlertControllerVisualStyle : NSObject <SDCAlertControllerVisualStyle> | |
@end | |
@implementation CustomAlertControllerVisualStyle | |
#pragma mark - Alert | |
- (CGFloat)width { | |
return 270; | |
} | |
- (UIEdgeInsets)contentPadding { | |
return UIEdgeInsetsMake(36, 16, 12, 16); | |
} | |
- (CGFloat)cornerRadius { | |
return 7; | |
} | |
- (UIEdgeInsets)margins { | |
return UIEdgeInsetsMake(3, 0, 3, 0); | |
} | |
- (UIOffset)parallax { | |
return UIOffsetMake(15.75, 15.75); | |
} | |
#pragma mark - Title & Message Labels | |
- (UIFont *)titleLabelFont { | |
return [UIFont boldSystemFontOfSize:17]; | |
} | |
- (UIFont *)messageLabelFont { | |
return [UIFont systemFontOfSize:13]; | |
} | |
- (UIColor *)titleLabelColor { | |
return UIColorFromRGB(kColorGray4); | |
} | |
- (UIColor *)messageLabelColor { | |
return UIColorFromRGB(kColorGray4); | |
} | |
- (CGFloat)labelSpacing { | |
return 22; | |
} | |
- (CGFloat)messageLabelBottomSpacing { | |
return 22; | |
} | |
- (NSTextAlignment)messageTextAlignment { | |
return NSTextAlignmentCenter; | |
} | |
#pragma mark - Actions | |
- (CGFloat)actionViewHeight { | |
return 44; | |
} | |
- (CGFloat)minimumActionViewWidth { | |
return 90; // Fits exactly three actions without scrolling | |
} | |
- (UIView *)actionViewHighlightBackgroundView { | |
UIView *view = [[UIView alloc] init]; | |
view.backgroundColor = UIColorFromRGBA(kColorGray3, 0.1f); | |
return view; | |
} | |
- (UIColor *)actionViewSeparatorColor { | |
return UIColorFromRGB(kColorGray3); | |
} | |
- (CGFloat)actionViewSeparatorThickness { | |
return 1 / [UIScreen mainScreen].scale; | |
} | |
- (UIColor *)textColorForAction:(SDCAlertAction *)action { | |
if (action.style & SDCAlertActionStyleDestructive) { | |
return UIColorFromRGB(kColorRed); | |
} else { | |
return UIColorFromRGB(kColorDarkOrange); | |
} | |
} | |
- (UIFont *)fontForAction:(SDCAlertAction *)action { | |
if (action.style & SDCAlertActionStyleRecommended) { | |
return [UIFont boldSystemFontOfSize:17]; | |
} else { | |
return [UIFont systemFontOfSize:17]; | |
} | |
} | |
#pragma mark - Text Fields | |
- (UIFont *)textFieldFont { | |
return [UIFont systemFontOfSize:13]; | |
} | |
- (CGFloat)estimatedTextFieldHeight { | |
return 25; | |
} | |
- (CGFloat)textFieldBorderWidth { | |
return 1 / [UIScreen mainScreen].scale; | |
} | |
- (UIColor *)textFieldBorderColor { | |
return UIColorFromRGB(kColorGray3); | |
} | |
- (UIEdgeInsets)textFieldMargins { | |
return UIEdgeInsetsMake(4, 4, 4, 4); | |
} | |
@end | |
@implementation SDCAlertController (Custom) | |
+ (void)okWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(SDCAlertAction *))handler { | |
SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:title | |
message:message | |
preferredStyle:SDCAlertControllerStyleAlert]; | |
alert.visualStyle = [[CustomAlertControllerVisualStyle alloc] init]; | |
[alert addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:handler]]; | |
[alert presentWithCompletion:nil]; | |
} | |
+ (void)alertWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(SDCAlertAction *))handler { | |
SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:title | |
message:message | |
preferredStyle:SDCAlertControllerStyleAlert]; | |
alert.visualStyle = [[CustomAlertControllerVisualStyle alloc] init]; | |
[alert addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:handler]]; | |
[alert addAction:[SDCAlertAction actionWithTitle:@"Confirm" style:SDCAlertActionStyleDefault handler:handler]]; | |
[alert presentWithCompletion:nil]; | |
} | |
+ (void)deleteAlertWithTitle:(NSString *)title message:(NSString *)message handler:(void (^)(SDCAlertAction *))handler { | |
SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:title | |
message:message | |
preferredStyle:SDCAlertControllerStyleAlert]; | |
alert.visualStyle = [[CustomAlertControllerVisualStyle alloc] init]; | |
[alert addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDefault handler:handler]]; | |
[alert addAction:[SDCAlertAction actionWithTitle:@"Delete" style:SDCAlertActionStyleDestructive handler:handler]]; | |
[alert presentWithCompletion:nil]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment