diff --git a/AHAlertView.podspec b/AHAlertView.podspec new file mode 100644 index 0000000..8ea6156 --- /dev/null +++ b/AHAlertView.podspec @@ -0,0 +1,15 @@ +Pod::Spec.new do |s| + s.name = "AHAlertView" + s.version = "0.0.2" + s.summary = "`AHAlertView` is a powerful, block-based alternative to UIKit's `UIAlertView`. " + s.homepage = "https://github.com/warrenm/AHAlertView.git" + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { "Warren Moore" => "wm@warrenmoore.net" } + s.source = { :git => "https://github.com/zhigang1992/AHAlertView.git", :tag => "v0.0.2" } + s.platform = :ios, '5.0' + s.source_files = 'Class', 'AHAlertView/**/*.{h,m}' + s.public_header_files = 'AHAlertView/**/*.h' + s.resources = 'AHAlertView/**/*.png' + s.frameworks = 'QuartzCore' + s.requires_arc = true +end diff --git a/AHAlertView/AHAlertView+CustomAppearance.h b/AHAlertView/AHAlertView+CustomAppearance.h new file mode 100644 index 0000000..b956c03 --- /dev/null +++ b/AHAlertView/AHAlertView+CustomAppearance.h @@ -0,0 +1,13 @@ +// +// AHAlertView+CustomAppearance.h +// AHAlertViewSample +// +// Created by Kyle Fang on 2/25/13. +// Copyright (c) 2013 Auerhaus Development, LLC. All rights reserved. +// + +#import "AHAlertView.h" + +@interface AHAlertView (CustomAppearance) ++ (void)applyCustomAlertAppearance; +@end diff --git a/AHAlertView/AHAlertView+CustomAppearance.m b/AHAlertView/AHAlertView+CustomAppearance.m new file mode 100644 index 0000000..1923f09 --- /dev/null +++ b/AHAlertView/AHAlertView+CustomAppearance.m @@ -0,0 +1,51 @@ +// +// AHAlertView+CustomAppearance.m +// AHAlertViewSample +// +// Created by Kyle Fang on 2/25/13. +// Copyright (c) 2013 Auerhaus Development, LLC. All rights reserved. +// + +#import "AHAlertView+CustomAppearance.h" + +@implementation AHAlertView (CustomAppearance) ++ (void)applyCustomAlertAppearance +{ + [[AHAlertView appearance] setContentInsets:UIEdgeInsetsMake(12, 18, 12, 18)]; + + [[AHAlertView appearance] setBackgroundImage:[UIImage imageNamed:@"custom-dialog-background"]]; + + UIEdgeInsets buttonEdgeInsets = UIEdgeInsetsMake(20, 8, 20, 8); + + UIImage *cancelButtonImage = [[UIImage imageNamed:@"custom-cancel-normal"] + resizableImageWithCapInsets:buttonEdgeInsets]; + UIImage *normalButtonImage = [[UIImage imageNamed:@"custom-button-normal"] + resizableImageWithCapInsets:buttonEdgeInsets]; + + [[AHAlertView appearance] setCancelButtonBackgroundImage:cancelButtonImage + forState:UIControlStateNormal]; + [[AHAlertView appearance] setButtonBackgroundImage:normalButtonImage + forState:UIControlStateNormal]; + + [[AHAlertView appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + [UIFont boldSystemFontOfSize:18], UITextAttributeFont, + [UIColor whiteColor], UITextAttributeTextColor, + [UIColor blackColor], UITextAttributeTextShadowColor, + [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset, + nil]]; + + [[AHAlertView appearance] setMessageTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + [UIFont systemFontOfSize:14], UITextAttributeFont, + [UIColor colorWithWhite:0.8 alpha:1.0], UITextAttributeTextColor, + [UIColor blackColor], UITextAttributeTextShadowColor, + [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset, + nil]]; + + [[AHAlertView appearance] setButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + [UIFont boldSystemFontOfSize:14], UITextAttributeFont, + [UIColor whiteColor], UITextAttributeTextColor, + [UIColor blackColor], UITextAttributeTextShadowColor, + [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset, + nil]]; +} +@end diff --git a/AHAlertViewSample/Resources/custom-button-normal.png b/AHAlertView/custom-button-normal.png similarity index 100% rename from AHAlertViewSample/Resources/custom-button-normal.png rename to AHAlertView/custom-button-normal.png diff --git a/AHAlertViewSample/Resources/custom-button-normal@2x.png b/AHAlertView/custom-button-normal@2x.png similarity index 100% rename from AHAlertViewSample/Resources/custom-button-normal@2x.png rename to AHAlertView/custom-button-normal@2x.png diff --git a/AHAlertViewSample/Resources/custom-cancel-normal.png b/AHAlertView/custom-cancel-normal.png similarity index 100% rename from AHAlertViewSample/Resources/custom-cancel-normal.png rename to AHAlertView/custom-cancel-normal.png diff --git a/AHAlertViewSample/Resources/custom-cancel-normal@2x.png b/AHAlertView/custom-cancel-normal@2x.png similarity index 100% rename from AHAlertViewSample/Resources/custom-cancel-normal@2x.png rename to AHAlertView/custom-cancel-normal@2x.png diff --git a/AHAlertViewSample/Resources/custom-dialog-background.png b/AHAlertView/custom-dialog-background.png similarity index 100% rename from AHAlertViewSample/Resources/custom-dialog-background.png rename to AHAlertView/custom-dialog-background.png diff --git a/AHAlertViewSample/Resources/custom-dialog-background@2x.png b/AHAlertView/custom-dialog-background@2x.png similarity index 100% rename from AHAlertViewSample/Resources/custom-dialog-background@2x.png rename to AHAlertView/custom-dialog-background@2x.png diff --git a/AHAlertViewSample.xcodeproj/project.pbxproj b/AHAlertViewSample.xcodeproj/project.pbxproj index f416ffc..069b5de 100644 --- a/AHAlertViewSample.xcodeproj/project.pbxproj +++ b/AHAlertViewSample.xcodeproj/project.pbxproj @@ -7,13 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 04B58B1416DA994A00070EE1 /* AHAlertView+CustomAppearance.m in Sources */ = {isa = PBXBuildFile; fileRef = 04B58B1316DA994A00070EE1 /* AHAlertView+CustomAppearance.m */; }; + 04B58B1B16DA99CB00070EE1 /* custom-button-normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 04B58B1516DA99CB00070EE1 /* custom-button-normal.png */; }; + 04B58B1C16DA99CB00070EE1 /* custom-button-normal@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 04B58B1616DA99CB00070EE1 /* custom-button-normal@2x.png */; }; + 04B58B1D16DA99CB00070EE1 /* custom-cancel-normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 04B58B1716DA99CB00070EE1 /* custom-cancel-normal.png */; }; + 04B58B1E16DA99CB00070EE1 /* custom-cancel-normal@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 04B58B1816DA99CB00070EE1 /* custom-cancel-normal@2x.png */; }; + 04B58B1F16DA99CB00070EE1 /* custom-dialog-background.png in Resources */ = {isa = PBXBuildFile; fileRef = 04B58B1916DA99CB00070EE1 /* custom-dialog-background.png */; }; + 04B58B2016DA99CB00070EE1 /* custom-dialog-background@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 04B58B1A16DA99CB00070EE1 /* custom-dialog-background@2x.png */; }; 802BC624160CF38400C330C5 /* AHAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 802BC623160CF38400C330C5 /* AHAlertView.m */; }; - 802BC630160CF3B700C330C5 /* custom-button-normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC626160CF3B700C330C5 /* custom-button-normal.png */; }; - 802BC631160CF3B700C330C5 /* custom-button-normal@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC627160CF3B700C330C5 /* custom-button-normal@2x.png */; }; - 802BC632160CF3B700C330C5 /* custom-cancel-normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC628160CF3B700C330C5 /* custom-cancel-normal.png */; }; - 802BC633160CF3B700C330C5 /* custom-cancel-normal@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC629160CF3B700C330C5 /* custom-cancel-normal@2x.png */; }; - 802BC634160CF3B700C330C5 /* custom-dialog-background.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC62A160CF3B700C330C5 /* custom-dialog-background.png */; }; - 802BC635160CF3B700C330C5 /* custom-dialog-background@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC62B160CF3B700C330C5 /* custom-dialog-background@2x.png */; }; 802BC636160CF3B700C330C5 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC62C160CF3B700C330C5 /* Icon-72.png */; }; 802BC637160CF3B700C330C5 /* Icon-144.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC62D160CF3B700C330C5 /* Icon-144.png */; }; 802BC638160CF3B700C330C5 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 802BC62E160CF3B700C330C5 /* Icon.png */; }; @@ -30,14 +31,16 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 04B58B1216DA994A00070EE1 /* AHAlertView+CustomAppearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AHAlertView+CustomAppearance.h"; sourceTree = ""; }; + 04B58B1316DA994A00070EE1 /* AHAlertView+CustomAppearance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AHAlertView+CustomAppearance.m"; sourceTree = ""; }; + 04B58B1516DA99CB00070EE1 /* custom-button-normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "custom-button-normal.png"; sourceTree = ""; }; + 04B58B1616DA99CB00070EE1 /* custom-button-normal@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "custom-button-normal@2x.png"; sourceTree = ""; }; + 04B58B1716DA99CB00070EE1 /* custom-cancel-normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "custom-cancel-normal.png"; sourceTree = ""; }; + 04B58B1816DA99CB00070EE1 /* custom-cancel-normal@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "custom-cancel-normal@2x.png"; sourceTree = ""; }; + 04B58B1916DA99CB00070EE1 /* custom-dialog-background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "custom-dialog-background.png"; sourceTree = ""; }; + 04B58B1A16DA99CB00070EE1 /* custom-dialog-background@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "custom-dialog-background@2x.png"; sourceTree = ""; }; 802BC622160CF38400C330C5 /* AHAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AHAlertView.h; sourceTree = ""; }; 802BC623160CF38400C330C5 /* AHAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AHAlertView.m; sourceTree = ""; }; - 802BC626160CF3B700C330C5 /* custom-button-normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "custom-button-normal.png"; path = "Resources/custom-button-normal.png"; sourceTree = ""; }; - 802BC627160CF3B700C330C5 /* custom-button-normal@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "custom-button-normal@2x.png"; path = "Resources/custom-button-normal@2x.png"; sourceTree = ""; }; - 802BC628160CF3B700C330C5 /* custom-cancel-normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "custom-cancel-normal.png"; path = "Resources/custom-cancel-normal.png"; sourceTree = ""; }; - 802BC629160CF3B700C330C5 /* custom-cancel-normal@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "custom-cancel-normal@2x.png"; path = "Resources/custom-cancel-normal@2x.png"; sourceTree = ""; }; - 802BC62A160CF3B700C330C5 /* custom-dialog-background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "custom-dialog-background.png"; path = "Resources/custom-dialog-background.png"; sourceTree = ""; }; - 802BC62B160CF3B700C330C5 /* custom-dialog-background@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "custom-dialog-background@2x.png"; path = "Resources/custom-dialog-background@2x.png"; sourceTree = ""; }; 802BC62C160CF3B700C330C5 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "Resources/Icon-72.png"; sourceTree = ""; }; 802BC62D160CF3B700C330C5 /* Icon-144.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-144.png"; path = "Resources/Icon-144.png"; sourceTree = ""; }; 802BC62E160CF3B700C330C5 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = Resources/Icon.png; sourceTree = ""; }; @@ -76,6 +79,14 @@ 802BC621160CF38400C330C5 /* AHAlertView */ = { isa = PBXGroup; children = ( + 04B58B1516DA99CB00070EE1 /* custom-button-normal.png */, + 04B58B1616DA99CB00070EE1 /* custom-button-normal@2x.png */, + 04B58B1716DA99CB00070EE1 /* custom-cancel-normal.png */, + 04B58B1816DA99CB00070EE1 /* custom-cancel-normal@2x.png */, + 04B58B1916DA99CB00070EE1 /* custom-dialog-background.png */, + 04B58B1A16DA99CB00070EE1 /* custom-dialog-background@2x.png */, + 04B58B1216DA994A00070EE1 /* AHAlertView+CustomAppearance.h */, + 04B58B1316DA994A00070EE1 /* AHAlertView+CustomAppearance.m */, 802BC622160CF38400C330C5 /* AHAlertView.h */, 802BC623160CF38400C330C5 /* AHAlertView.m */, ); @@ -95,12 +106,6 @@ 802BC63A160CF3C000C330C5 /* Custom Appearance */ = { isa = PBXGroup; children = ( - 802BC626160CF3B700C330C5 /* custom-button-normal.png */, - 802BC627160CF3B700C330C5 /* custom-button-normal@2x.png */, - 802BC628160CF3B700C330C5 /* custom-cancel-normal.png */, - 802BC629160CF3B700C330C5 /* custom-cancel-normal@2x.png */, - 802BC62A160CF3B700C330C5 /* custom-dialog-background.png */, - 802BC62B160CF3B700C330C5 /* custom-dialog-background@2x.png */, ); name = "Custom Appearance"; sourceTree = ""; @@ -230,17 +235,17 @@ buildActionMask = 2147483647; files = ( 80C6F10E15FE54A900ABF313 /* InfoPlist.strings in Resources */, - 802BC630160CF3B700C330C5 /* custom-button-normal.png in Resources */, - 802BC631160CF3B700C330C5 /* custom-button-normal@2x.png in Resources */, - 802BC632160CF3B700C330C5 /* custom-cancel-normal.png in Resources */, - 802BC633160CF3B700C330C5 /* custom-cancel-normal@2x.png in Resources */, - 802BC634160CF3B700C330C5 /* custom-dialog-background.png in Resources */, - 802BC635160CF3B700C330C5 /* custom-dialog-background@2x.png in Resources */, 802BC636160CF3B700C330C5 /* Icon-72.png in Resources */, 802BC637160CF3B700C330C5 /* Icon-144.png in Resources */, 802BC638160CF3B700C330C5 /* Icon.png in Resources */, 802BC639160CF3B700C330C5 /* Icon@2x.png in Resources */, 802BC63D160CF65800C330C5 /* Default-568h@2x.png in Resources */, + 04B58B1B16DA99CB00070EE1 /* custom-button-normal.png in Resources */, + 04B58B1C16DA99CB00070EE1 /* custom-button-normal@2x.png in Resources */, + 04B58B1D16DA99CB00070EE1 /* custom-cancel-normal.png in Resources */, + 04B58B1E16DA99CB00070EE1 /* custom-cancel-normal@2x.png in Resources */, + 04B58B1F16DA99CB00070EE1 /* custom-dialog-background.png in Resources */, + 04B58B2016DA99CB00070EE1 /* custom-dialog-background@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -255,6 +260,7 @@ 80C6F11415FE54A900ABF313 /* AHAppDelegate.m in Sources */, 80C6F11C15FE54E900ABF313 /* AHAlertSampleViewController.m in Sources */, 802BC624160CF38400C330C5 /* AHAlertView.m in Sources */, + 04B58B1416DA994A00070EE1 /* AHAlertView+CustomAppearance.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AHAlertViewSample/AHAlertSampleViewController.m b/AHAlertViewSample/AHAlertSampleViewController.m index d5be763..7c74440 100644 --- a/AHAlertViewSample/AHAlertSampleViewController.m +++ b/AHAlertViewSample/AHAlertSampleViewController.m @@ -23,7 +23,7 @@ // #import "AHAlertSampleViewController.h" -#import "AHAlertView.h" +#import "AHAlertView+CustomAppearance.h" static const NSInteger kAHViewAutoresizingFlexibleMargins = UIViewAutoresizingFlexibleLeftMargin | @@ -112,49 +112,9 @@ static const NSInteger kAHViewAutoresizingFlexibleMargins = - (void)switchValueChanged:(UISwitch *)sender { if(sender.isOn) - [self applyCustomAlertAppearance]; + [AHAlertView applyCustomAlertAppearance]; else [AHAlertView applySystemAlertAppearance]; } -- (void)applyCustomAlertAppearance -{ - [[AHAlertView appearance] setContentInsets:UIEdgeInsetsMake(12, 18, 12, 18)]; - - [[AHAlertView appearance] setBackgroundImage:[UIImage imageNamed:@"custom-dialog-background"]]; - - UIEdgeInsets buttonEdgeInsets = UIEdgeInsetsMake(20, 8, 20, 8); - - UIImage *cancelButtonImage = [[UIImage imageNamed:@"custom-cancel-normal"] - resizableImageWithCapInsets:buttonEdgeInsets]; - UIImage *normalButtonImage = [[UIImage imageNamed:@"custom-button-normal"] - resizableImageWithCapInsets:buttonEdgeInsets]; - - [[AHAlertView appearance] setCancelButtonBackgroundImage:cancelButtonImage - forState:UIControlStateNormal]; - [[AHAlertView appearance] setButtonBackgroundImage:normalButtonImage - forState:UIControlStateNormal]; - - [[AHAlertView appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: - [UIFont boldSystemFontOfSize:18], UITextAttributeFont, - [UIColor whiteColor], UITextAttributeTextColor, - [UIColor blackColor], UITextAttributeTextShadowColor, - [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset, - nil]]; - - [[AHAlertView appearance] setMessageTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: - [UIFont systemFontOfSize:14], UITextAttributeFont, - [UIColor colorWithWhite:0.8 alpha:1.0], UITextAttributeTextColor, - [UIColor blackColor], UITextAttributeTextShadowColor, - [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset, - nil]]; - - [[AHAlertView appearance] setButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: - [UIFont boldSystemFontOfSize:14], UITextAttributeFont, - [UIColor whiteColor], UITextAttributeTextColor, - [UIColor blackColor], UITextAttributeTextShadowColor, - [NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset, - nil]]; -} - @end