From e5896718687c34664ebdd2541a04a207492f1151 Mon Sep 17 00:00:00 2001 From: Bryan Tung Date: Wed, 1 May 2013 13:57:45 +0800 Subject: [PATCH 1/4] ARC/MRC compatible --- .gitignore | 3 + Default-568h@2x.png | Bin 0 -> 18594 bytes MKAdditions/NSObject+MKBlockAdditions.m | 10 +- MKAdditions/UIActionSheet+MKBlockAdditions.m | 37 ++++-- MKAdditions/UIAlertView+MKBlockAdditions.m | 10 +- .../project.pbxproj | 13 ++- .../UIKitCategoryAdditionsAppDelegate.m | 2 + .../UIKitCategoryAdditionsViewController.m | 2 + .../en.lproj/UIKitCategoryViewController.xib | 109 ++++++++---------- UIKitCategoryAdditions/main.m | 8 ++ 10 files changed, 113 insertions(+), 81 deletions(-) create mode 100644 .gitignore create mode 100644 Default-568h@2x.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c1d909 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +project.xcworkspace +xcuserdata \ No newline at end of file diff --git a/Default-568h@2x.png b/Default-568h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0891b7aabfcf3422423b109c8beed2bab838c607 GIT binary patch literal 18594 zcmeI4X;f257Jx&9fS`ixvS;&$x8J@slQFSel)6zJN=?13FB7H(lQjRkSy8x_-S~tvu2gzn1oS+dLcF#eqtq$ z%tf9TTvX?`)R@}3uBI;jzS-=ZR-Td&MHaS&;!0?Ni*#$#`n*~CcQK)Q9vAQ~TUpnI!j)a2biYK^R)M~A5wUDZhx?ULMX z3x1P&qt=trOY6P2U67L=m=U?F|5#Uj(eCueNTZaHs_ceWiHeET+j+tp3Jt9g(ekqP z2WOvfR{qV+9r+o4J5?qK>7;;^+I7tGv-i)es$X_D=EoKF+S?zsyj^oRFElP}c}JT< zd8SUs-?O?}2YD#ngKbnHgzHBcboxK_2r9l(?eNCl-pEzkJm}fY?WC*jnS?VBE4EpY zO$fEejz6fU;W2Kl>JeQBZBl-%Irg`obSlg*@4QB;Dd1H7^Oi5wvt4d{RZ!8Og?^aE z)k0$1g+V3fd(gdQ3d&q2q-FL*uy#}|bc^=VhFsl0jBgUGJ+-s3U8MK9A!YJJMxpci z5hJ%|{DwV48fZn0{n5l$N_KcSb#NKE4plB`9I6Zt=Z!~-zw0{9tg$L&Ju1F0X)Cy8 zKF;(&lJ>x)Jw(=;p~sF(Sd9VWGwFE2rnyS9!f^DZ8+aCLq zQ};>lcJ1GDLqjm6Hd>|Eabno@P`~Bn(~6^aD_#yoEH(a?Nm1S<;S+hSxI5d16^<1lEM3NPFi zkqPrpL)+ zgnseFikg`gJVBha1&7C4;O6>h=dt~`ND+;Zd?W(4v2JIb7Pt>Td42%M-Ju-XAH#Pns762L}K3 zDhvsRqN0Ni(1UrishD2YvV?4*h2iFj$+&N||Fn$4n|^NSU+o?~jq`0jVQt8T9l{7b zXiwwODFh2V!Q6sqP9S>WH$oOf$N~=d0-bqTlD61!=`&0eAP-F>XN?*|gtOXX{ zQVTWyYo4ZK0GAw!GHf|pz9`D;-bbb*5LBX*{bnz|+)$@&P9|ORM2o?95{;ejvo&r- zq8cBhTN6nn)7~W>54U)%-F_-b?YKdfk5I8MHcuzBD5)!;yv#Z&R&^y=@=>VTIMy#r zX&U<=BsPkdqcMe<_}2+>H%XKyrr5ZR8_KVe>ZqYN z^=^~TFD};;rHJ$U;{~w^hYojl4hRI@SH$^K{YEo=sg)WY87r!*7blQK&qnpDo0`Vn zkl)9u9g=mCh&ZCJS(L4yN3k0kQ zuvg$h2KEEk51T+O0JQ+r0`R>g{jvqM0Mr6d3qUOZwE!?PI7HY@CE|dr sfw?Q;rAv?G4&^^8-z_>&sWXMxvD*gPOU4CBe-*@OtE+wfmVJNyHv)PfH~;_u literal 0 HcmV?d00001 diff --git a/MKAdditions/NSObject+MKBlockAdditions.m b/MKAdditions/NSObject+MKBlockAdditions.m index fa2c8bd..84a26df 100644 --- a/MKAdditions/NSObject+MKBlockAdditions.m +++ b/MKAdditions/NSObject+MKBlockAdditions.m @@ -14,7 +14,9 @@ @implementation NSObject (MKBlockAdditions) - (void) performBlock:(VoidBlock) aBlock { - [_block release]; +#if !__has_feature(objc_arc) + [_block release]; +#endif _block = [aBlock copy]; [self performSelector:@selector(callBlock)]; @@ -22,7 +24,9 @@ - (void) performBlock:(VoidBlock) aBlock - (void) performBlock:(VoidBlock) aBlock afterDelay:(NSTimeInterval) delay { - [_block release]; +#if !__has_feature(objc_arc) + [_block release]; +#endif _block = [aBlock copy]; [self performSelector:@selector(callBlock) withObject:nil afterDelay:delay]; @@ -31,7 +35,9 @@ - (void) performBlock:(VoidBlock) aBlock afterDelay:(NSTimeInterval) delay -(void) callBlock { _block(); +#if !__has_feature(objc_arc) [_block release]; +#endif _block = nil; } diff --git a/MKAdditions/UIActionSheet+MKBlockAdditions.m b/MKAdditions/UIActionSheet+MKBlockAdditions.m index 3ed5d0c..43ce35a 100644 --- a/MKAdditions/UIActionSheet+MKBlockAdditions.m +++ b/MKAdditions/UIActionSheet+MKBlockAdditions.m @@ -39,14 +39,15 @@ + (void) actionSheetWithTitle:(NSString*) title onDismiss:(DismissBlock) dismissed onCancel:(CancelBlock) cancelled { +#if !__has_feature(objc_arc) [_cancelBlock release]; - _cancelBlock = [cancelled copy]; - [_dismissBlock release]; +#endif + _cancelBlock = [cancelled copy]; _dismissBlock = [dismissed copy]; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title - delegate:[self class] + delegate:(id)[self class] cancelButtonTitle:nil destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:nil]; @@ -69,7 +70,9 @@ + (void) actionSheetWithTitle:(NSString*) title if([view isKindOfClass:[UIBarButtonItem class]]) [actionSheet showFromBarButtonItem:(UIBarButtonItem*) view animated:YES]; +#if !__has_feature(objc_arc) [actionSheet release]; +#endif } @@ -79,19 +82,24 @@ + (void) photoPickerWithTitle:(NSString*) title onPhotoPicked:(PhotoPickedBlock) photoPicked onCancel:(CancelBlock) cancelled { +#if !__has_feature(objc_arc) [_cancelBlock release]; - _cancelBlock = [cancelled copy]; - [_photoPickedBlock release]; + [_presentVC release]; +#endif + _cancelBlock = [cancelled copy]; _photoPickedBlock = [photoPicked copy]; - [_presentVC release]; +#if !__has_feature(objc_arc) _presentVC = [presentVC retain]; +#else + _presentVC = presentVC; +#endif int cancelButtonIndex = -1; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title - delegate:[self class] + delegate:(id)[self class] cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; @@ -121,8 +129,9 @@ + (void) photoPickerWithTitle:(NSString*) title if([view isKindOfClass:[UIBarButtonItem class]]) [actionSheet showFromBarButtonItem:(UIBarButtonItem*) view animated:YES]; - - [actionSheet release]; +#if !__has_feature(objc_arc) + [actionSheet release]; +#endif } @@ -134,16 +143,20 @@ + (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking _photoPickedBlock(editedImage); [picker dismissModalViewControllerAnimated:YES]; - [picker autorelease]; +#if !__has_feature(objc_arc) + [picker autorelease]; +#endif } + (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { // Dismiss the image selection and close the program - [_presentVC dismissModalViewControllerAnimated:YES]; + [_presentVC dismissModalViewControllerAnimated:YES]; +#if !__has_feature(objc_arc) [picker autorelease]; [_presentVC release]; +#endif _cancelBlock(); } @@ -168,7 +181,7 @@ +(void)actionSheet:(UIActionSheet*) actionSheet didDismissWithButtonIndex:(NSInt UIImagePickerController *picker = [[UIImagePickerController alloc] init]; - picker.delegate = [self class]; + picker.delegate = (id)[self class]; picker.allowsEditing = YES; if(buttonIndex == 1) diff --git a/MKAdditions/UIAlertView+MKBlockAdditions.m b/MKAdditions/UIAlertView+MKBlockAdditions.m index 8a9f32b..f29d9ae 100644 --- a/MKAdditions/UIAlertView+MKBlockAdditions.m +++ b/MKAdditions/UIAlertView+MKBlockAdditions.m @@ -58,10 +58,14 @@ + (UIAlertView*) alertViewWithTitle:(NSString*) title [alert addButtonWithTitle:buttonTitle]; [alert show]; +#if !__has_feature(objc_arc) return [alert autorelease]; +#else + return alert; +#endif } -+ (UIAlertView*) alertViewWithTitle:(NSString*) title ++ (UIAlertView*) alertViewWithTitle:(NSString*) title message:(NSString*) message { return [UIAlertView alertViewWithTitle:title @@ -78,7 +82,11 @@ + (UIAlertView*) alertViewWithTitle:(NSString*) title cancelButtonTitle:cancelButtonTitle otherButtonTitles: nil]; [alert show]; +#if !__has_feature(objc_arc) return [alert autorelease]; +#else + return alert; +#endif } diff --git a/UIKitCategoryAdditions.xcodeproj/project.pbxproj b/UIKitCategoryAdditions.xcodeproj/project.pbxproj index 67d8cce..03ff196 100644 --- a/UIKitCategoryAdditions.xcodeproj/project.pbxproj +++ b/UIKitCategoryAdditions.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ ABD7412213388C9E00899EE2 /* UIKitCategoryAdditionsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABD7411A13388C9E00899EE2 /* UIKitCategoryAdditionsViewController.m */; }; ABD7413913388D3400899EE2 /* UIActionSheet+MKBlockAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = ABD7413613388D3400899EE2 /* UIActionSheet+MKBlockAdditions.m */; }; ABD7413A13388D3400899EE2 /* UIAlertView+MKBlockAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = ABD7413813388D3400899EE2 /* UIAlertView+MKBlockAdditions.m */; }; + DEB1F5C41730E29300F54C7E /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DEB1F5C31730E29300F54C7E /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -43,6 +44,7 @@ ABD7413613388D3400899EE2 /* UIActionSheet+MKBlockAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIActionSheet+MKBlockAdditions.m"; sourceTree = ""; }; ABD7413713388D3400899EE2 /* UIAlertView+MKBlockAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+MKBlockAdditions.h"; sourceTree = ""; }; ABD7413813388D3400899EE2 /* UIAlertView+MKBlockAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+MKBlockAdditions.m"; sourceTree = ""; }; + DEB1F5C31730E29300F54C7E /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -62,6 +64,7 @@ AB5E753F1336DD790016813D = { isa = PBXGroup; children = ( + DEB1F5C31730E29300F54C7E /* Default-568h@2x.png */, ABD7413313388D3400899EE2 /* MKAdditions */, ABD7410B13388C9E00899EE2 /* UIKitCategoryAdditions */, AB5E754D1336DD790016813D /* Frameworks */, @@ -143,6 +146,9 @@ /* Begin PBXProject section */ AB5E75411336DD790016813D /* Project object */ = { isa = PBXProject; + attributes = { + LastUpgradeCheck = 0460; + }; buildConfigurationList = AB5E75441336DD790016813D /* Build configuration list for PBXProject "UIKitCategoryAdditions" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; @@ -168,6 +174,7 @@ ABD7411B13388C9E00899EE2 /* InfoPlist.strings in Resources */, ABD7411C13388C9E00899EE2 /* MainWindow.xib in Resources */, ABD7411D13388C9E00899EE2 /* UIKitCategoryViewController.xib in Resources */, + DEB1F5C41730E29300F54C7E /* Default-568h@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -221,6 +228,7 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; @@ -238,6 +246,7 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvmgcc42; @@ -257,7 +266,7 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UIKitCategoryAdditions/UIKitCategoryAdditions-Prefix.pch"; - GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = "UIKitCategoryAdditions/UIKitCategoryAdditions-Info.plist"; PRODUCT_NAME = UIKitCategoryAdditions; WRAPPER_EXTENSION = app; @@ -271,7 +280,7 @@ COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "UIKitCategoryAdditions/UIKitCategoryAdditions-Prefix.pch"; - GCC_VERSION = com.apple.compilers.llvmgcc42; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = "UIKitCategoryAdditions/UIKitCategoryAdditions-Info.plist"; PRODUCT_NAME = UIKitCategoryAdditions; VALIDATE_PRODUCT = YES; diff --git a/UIKitCategoryAdditions/UIKitCategoryAdditionsAppDelegate.m b/UIKitCategoryAdditions/UIKitCategoryAdditionsAppDelegate.m index 5081843..2df6b0d 100644 --- a/UIKitCategoryAdditions/UIKitCategoryAdditionsAppDelegate.m +++ b/UIKitCategoryAdditions/UIKitCategoryAdditionsAppDelegate.m @@ -65,11 +65,13 @@ - (void)applicationWillTerminate:(UIApplication *)application */ } +#if !__has_feature(objc_arc) - (void)dealloc { [_window release]; [_viewController release]; [super dealloc]; } +#endif @end diff --git a/UIKitCategoryAdditions/UIKitCategoryAdditionsViewController.m b/UIKitCategoryAdditions/UIKitCategoryAdditionsViewController.m index 70ac7cc..7264de9 100644 --- a/UIKitCategoryAdditions/UIKitCategoryAdditionsViewController.m +++ b/UIKitCategoryAdditions/UIKitCategoryAdditionsViewController.m @@ -13,10 +13,12 @@ @implementation UIKitCategoryAdditionsViewController +#if !__has_feature(objc_arc) - (void)dealloc { [super dealloc]; } +#endif - (void)didReceiveMemoryWarning { diff --git a/UIKitCategoryAdditions/en.lproj/UIKitCategoryViewController.xib b/UIKitCategoryAdditions/en.lproj/UIKitCategoryViewController.xib index 6385c47..cfff75d 100644 --- a/UIKitCategoryAdditions/en.lproj/UIKitCategoryViewController.xib +++ b/UIKitCategoryAdditions/en.lproj/UIKitCategoryViewController.xib @@ -1,31 +1,28 @@ - 1056 - 10J869 - 1305 - 1038.35 - 461.00 + 1552 + 12D78 + 3084 + 1187.37 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 300 + 2083 YES IBProxyObject - IBUIView IBUIButton + IBUIView YES com.apple.InterfaceBuilder.IBCocoaTouchPlugin - YES - - YES - - + PluginDependencyRecalculationVersion + YES @@ -53,11 +50,6 @@ IBCocoaTouchFramework 0 0 - - Helvetica-Bold - 15 - 16 - 1 Alert @@ -72,6 +64,17 @@ 3 MC41AA + + Helvetica-Bold + Helvetica + 2 + 15 + + + Helvetica-Bold + 15 + 16 + @@ -79,12 +82,10 @@ {{47, 250}, {219, 37}} - NO IBCocoaTouchFramework 0 0 - 1 Alert @@ -93,6 +94,8 @@ MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + @@ -105,7 +108,6 @@ IBCocoaTouchFramework 0 0 - 1 Action @@ -114,6 +116,8 @@ MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + @@ -126,7 +130,6 @@ IBCocoaTouchFramework 0 0 - 1 Photo @@ -135,6 +138,8 @@ MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + {{0, 20}, {320, 460}} @@ -142,36 +147,8 @@ - 10 - - 549453824 - {84, 1} - - YES - - YES - - - - TU0AKgAAAVjFzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/ -y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/ -xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/ -xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/ -xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/ -xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P8ADQEAAAMAAAABAFQAAAEB -AAMAAAABAAEAAAECAAMAAAAEAAAB+gEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAAACAES -AAMAAAABAAEAAAEVAAMAAAABAAQAAAEWAAMAAAABAAEAAAEXAAQAAAABAAABUAEcAAMAAAABAAEAAAFS -AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA - - - - - - 3 - MCAwAA - - - groupTableViewBackgroundColor + 3 + MCAwAA NO @@ -191,21 +168,21 @@ AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA - actionTapped: - + alertTapped: + 7 - 11 + 12 - alertTapped: - + actionTapped: + 7 - 12 + 11 @@ -231,7 +208,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA YES 0 - + + YES + @@ -285,21 +264,23 @@ AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA YES -1.CustomClassName + -1.IBPluginDependency -2.CustomClassName + -2.IBPluginDependency 10.IBPluginDependency 14.IBPluginDependency - 6.IBEditorWindowLastContentRect 6.IBPluginDependency 8.IBPluginDependency 9.IBPluginDependency - + YES UIKitCategoryAdditionsViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - {{239, 654}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -334,7 +315,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA blockCallTapped: photoTapped: - + YES id id @@ -351,7 +332,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA blockCallTapped: photoTapped: - + YES actionTapped: @@ -386,6 +367,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA YES 3 - 300 + 2083 diff --git a/UIKitCategoryAdditions/main.m b/UIKitCategoryAdditions/main.m index 078ed84..ddd041a 100644 --- a/UIKitCategoryAdditions/main.m +++ b/UIKitCategoryAdditions/main.m @@ -8,10 +8,18 @@ #import +#import "UIKitCategoryAdditionsAppDelegate.h" + int main(int argc, char *argv[]) { +#if !__has_feature(objc_arc) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; +#else + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([UIKitCategoryAdditionsAppDelegate class])); + } +#endif } From eb4e1b048fdfad3639eae1343f1ba02d822d013f Mon Sep 17 00:00:00 2001 From: Bryan Tung Date: Wed, 1 May 2013 14:08:10 +0800 Subject: [PATCH 2/4] New UIActionSheet class method with specific show area and animated param --- MKAdditions/UIActionSheet+MKBlockAdditions.h | 9 +++++ MKAdditions/UIActionSheet+MKBlockAdditions.m | 38 +++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/MKAdditions/UIActionSheet+MKBlockAdditions.h b/MKAdditions/UIActionSheet+MKBlockAdditions.h index 40db10b..978fb3c 100644 --- a/MKAdditions/UIActionSheet+MKBlockAdditions.h +++ b/MKAdditions/UIActionSheet+MKBlockAdditions.h @@ -10,6 +10,15 @@ #import "MKBlockAdditions.h" @interface UIActionSheet (MKBlockAdditions) ++(void) actionSheetWithTitle:(NSString*) title + destructiveButtonTitle:(NSString*) destructiveButtonTitle + buttons:(NSArray *) buttonTitles + fromRect:(CGRect) rect + showInView:(UIView*) view + onDismiss:(DismissBlock) dismissed + onCancel:(CancelBlock) cancelled + animated:(BOOL) animated; + +(void) actionSheetWithTitle:(NSString*) title message:(NSString*) message buttons:(NSArray*) buttonTitles diff --git a/MKAdditions/UIActionSheet+MKBlockAdditions.m b/MKAdditions/UIActionSheet+MKBlockAdditions.m index 43ce35a..4e12c9c 100644 --- a/MKAdditions/UIActionSheet+MKBlockAdditions.m +++ b/MKAdditions/UIActionSheet+MKBlockAdditions.m @@ -15,6 +15,43 @@ @implementation UIActionSheet (MKBlockAdditions) ++(void) actionSheetWithTitle:(NSString *)title + destructiveButtonTitle:(NSString *)destructiveButtonTitle + buttons:(NSArray *)buttonTitles + fromRect:(CGRect)rect + showInView:(UIView *)view + onDismiss:(DismissBlock)dismissed + onCancel:(CancelBlock)cancelled + animated:(BOOL)animated +{ +#if !__has_feature(objc_arc) + [_cancelBlock release]; + [_dismissBlock release]; +#endif + _cancelBlock = [cancelled copy]; + _dismissBlock = [dismissed copy]; + + UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title + delegate:(id)[self class] + cancelButtonTitle:nil + destructiveButtonTitle:destructiveButtonTitle + otherButtonTitles:nil]; + + for(NSString* thisButtonTitle in buttonTitles) + [actionSheet addButtonWithTitle:thisButtonTitle]; + + [actionSheet addButtonWithTitle:NSLocalizedString(@"Cancel", @"")]; + actionSheet.cancelButtonIndex = [buttonTitles count]; + + if(destructiveButtonTitle) + actionSheet.cancelButtonIndex ++; + + [actionSheet showFromRect:rect inView:view animated:animated]; +#if !__has_feature(objc_arc) + [actionSheet release]; +#endif +} + +(void) actionSheetWithTitle:(NSString*) title message:(NSString*) message buttons:(NSArray*) buttonTitles @@ -73,7 +110,6 @@ + (void) actionSheetWithTitle:(NSString*) title #if !__has_feature(objc_arc) [actionSheet release]; #endif - } + (void) photoPickerWithTitle:(NSString*) title From ca4db17172174ac5df5847ac0739d61ddf95acf8 Mon Sep 17 00:00:00 2001 From: Bryan Tung Date: Fri, 7 Mar 2014 14:12:29 +0800 Subject: [PATCH 3/4] added functions: 1. change buttons title color 2. change title color and use large font size --- MKAdditions/UIActionSheet+MKBlockAdditions.h | 12 ++++ MKAdditions/UIActionSheet+MKBlockAdditions.m | 67 ++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/MKAdditions/UIActionSheet+MKBlockAdditions.h b/MKAdditions/UIActionSheet+MKBlockAdditions.h index 978fb3c..e29ab5f 100644 --- a/MKAdditions/UIActionSheet+MKBlockAdditions.h +++ b/MKAdditions/UIActionSheet+MKBlockAdditions.h @@ -19,6 +19,18 @@ onCancel:(CancelBlock) cancelled animated:(BOOL) animated; ++(void) actionSheetWithTitle:(NSString*) title + titleColor:(UIColor*) titleColor + titleUseLargeFont:(BOOL) largeTitle + destructiveButtonTitle:(NSString*) destructiveButtonTitle + buttons:(NSArray *) buttonTitles + buttonsColor:(UIColor*) buttonColor + fromRect:(CGRect) rect + showInView:(UIView*) view + onDismiss:(DismissBlock) dismissed + onCancel:(CancelBlock) cancelled + animated:(BOOL) animated; + +(void) actionSheetWithTitle:(NSString*) title message:(NSString*) message buttons:(NSArray*) buttonTitles diff --git a/MKAdditions/UIActionSheet+MKBlockAdditions.m b/MKAdditions/UIActionSheet+MKBlockAdditions.m index 4e12c9c..4da8c10 100644 --- a/MKAdditions/UIActionSheet+MKBlockAdditions.m +++ b/MKAdditions/UIActionSheet+MKBlockAdditions.m @@ -23,6 +23,31 @@ +(void) actionSheetWithTitle:(NSString *)title onDismiss:(DismissBlock)dismissed onCancel:(CancelBlock)cancelled animated:(BOOL)animated +{ + [UIActionSheet actionSheetWithTitle:title + titleColor:nil + titleUseLargeFont:NO + destructiveButtonTitle:destructiveButtonTitle + buttons:buttonTitles + buttonsColor:nil + fromRect:rect + showInView:view + onDismiss:dismissed + onCancel:cancelled + animated:animated]; +} + ++(void) actionSheetWithTitle:(NSString*) title + titleColor:(UIColor *)titleColor + titleUseLargeFont:(BOOL)largeTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + buttons:(NSArray *)buttonTitles + buttonsColor:(UIColor *)buttonColor + fromRect:(CGRect)rect + showInView:(UIView *)view + onDismiss:(DismissBlock)dismissed + onCancel:(CancelBlock)cancelled + animated:(BOOL)animated { #if !__has_feature(objc_arc) [_cancelBlock release]; @@ -46,7 +71,16 @@ +(void) actionSheetWithTitle:(NSString *)title if(destructiveButtonTitle) actionSheet.cancelButtonIndex ++; + if (buttonColor) { + [actionSheet setButtonTitleColor:buttonColor]; + } + [actionSheet showFromRect:rect inView:view animated:animated]; + + if (titleColor) { + [actionSheet setTitleColor:titleColor]; + } + [actionSheet setLargeTitle:largeTitle]; #if !__has_feature(objc_arc) [actionSheet release]; #endif @@ -237,4 +271,37 @@ +(void)actionSheet:(UIActionSheet*) actionSheet didDismissWithButtonIndex:(NSInt } } } + +- (void)setButtonTitleColor:(UIColor *)color +{ + for (id view in self.subviews) { + if ([view isKindOfClass:[UIButton class]]) { + [view setTitleColor:color forState:UIControlStateNormal]; + [view setTitleColor:color forState:UIControlStateHighlighted]; + [view setTitleColor:color forState:UIControlStateSelected]; + } + } +} + +- (void)setTitleColor:(UIColor *)color +{ + UILabel *label = [self valueForKey:@"_titleLabel"]; + if (label) { + if (color) + [label setTextColor:color]; + } +} + +- (void)setLargeTitle:(BOOL)largeTitle +{ + if (largeTitle) { + UILabel *label = [self valueForKey:@"_titleLabel"]; + if (label) { + UIFont *font = [UIFont boldSystemFontOfSize:17]; + [label setFont:font]; + [label setFrame:CGRectMake(0, label.frame.origin.y, self.frame.size.width, 34)]; + } + } +} + @end From b4036b7e8fc9513de965907f8ddcdd631533cae6 Mon Sep 17 00:00:00 2001 From: bryan Date: Tue, 22 Apr 2014 21:10:43 +0800 Subject: [PATCH 4/4] add alert view with text input --- MKAdditions/MKBlockAdditions.h | 1 + MKAdditions/UIAlertView+MKBlockAdditions.h | 8 +++ MKAdditions/UIAlertView+MKBlockAdditions.m | 71 +++++++++++++++++++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/MKAdditions/MKBlockAdditions.h b/MKAdditions/MKBlockAdditions.h index 1e2606e..b12a7b3 100644 --- a/MKAdditions/MKBlockAdditions.h +++ b/MKAdditions/MKBlockAdditions.h @@ -11,5 +11,6 @@ typedef void (^VoidBlock)(); typedef void (^DismissBlock)(int buttonIndex); typedef void (^CancelBlock)(); typedef void (^PhotoPickedBlock)(UIImage *chosenImage); +typedef void (^TextFieldDismissBlock)(int buttonIndex, UITextField *textField); #define kPhotoActionSheetTag 10000 \ No newline at end of file diff --git a/MKAdditions/UIAlertView+MKBlockAdditions.h b/MKAdditions/UIAlertView+MKBlockAdditions.h index 8412529..f17962c 100644 --- a/MKAdditions/UIAlertView+MKBlockAdditions.h +++ b/MKAdditions/UIAlertView+MKBlockAdditions.h @@ -24,7 +24,15 @@ onDismiss:(DismissBlock) dismissed onCancel:(CancelBlock) cancelled; ++ (UIAlertView*) alertViewWithTitle:(NSString*) title + message:(NSString*) message + cancelButtonTitle:(NSString*) cancelButtonTitle + otherButtonTitles:(NSArray*) otherButtons + onTextFieldDismiss:(TextFieldDismissBlock) dismissed + onCancel:(CancelBlock) cancelled; + @property (nonatomic, copy) DismissBlock dismissBlock; @property (nonatomic, copy) CancelBlock cancelBlock; +@property (nonatomic, copy) TextFieldDismissBlock textFieldDismissBlock; @end diff --git a/MKAdditions/UIAlertView+MKBlockAdditions.m b/MKAdditions/UIAlertView+MKBlockAdditions.m index f29d9ae..85a2e92 100644 --- a/MKAdditions/UIAlertView+MKBlockAdditions.m +++ b/MKAdditions/UIAlertView+MKBlockAdditions.m @@ -11,17 +11,20 @@ static char DISMISS_IDENTIFER; static char CANCEL_IDENTIFER; +static char TEXTFIELD_IDENTIFIER; @implementation UIAlertView (Block) @dynamic cancelBlock; @dynamic dismissBlock; +@dynamic textFieldDismissBlock; - (void)setDismissBlock:(DismissBlock)dismissBlock { objc_setAssociatedObject(self, &DISMISS_IDENTIFER, dismissBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); } + - (DismissBlock)dismissBlock { return objc_getAssociatedObject(self, &DISMISS_IDENTIFER); @@ -37,22 +40,79 @@ - (CancelBlock)cancelBlock return objc_getAssociatedObject(self, &CANCEL_IDENTIFER); } +- (void)setTextFieldDismissBlock:(TextFieldDismissBlock)textFieldDismissBlock +{ + objc_setAssociatedObject(self, &TEXTFIELD_IDENTIFIER, textFieldDismissBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); +} -+ (UIAlertView*) alertViewWithTitle:(NSString*) title +- (TextFieldDismissBlock)textFieldDismissBlock +{ + return objc_getAssociatedObject(self, &TEXTFIELD_IDENTIFIER); +} + ++ (UIAlertView*) alertViewWithTitle:(NSString*) title message:(NSString*) message cancelButtonTitle:(NSString*) cancelButtonTitle otherButtonTitles:(NSArray*) otherButtons onDismiss:(DismissBlock) dismissed onCancel:(CancelBlock) cancelled { + UIAlertView *alert = [[UIAlertView alloc] showAlertViewWithTitle:title + message:message + cancelButtonTitle:cancelButtonTitle + otherButtonTitles:otherButtons + dismissBlock:dismissed + textFieldDismissBlock:nil + cancelBlock:cancelled]; +#if !__has_feature(objc_arc) + return [alert autorelease]; +#else + return alert; +#endif +} + ++ (UIAlertView*) alertViewWithTitle:(NSString *)title + message:(NSString *)message + cancelButtonTitle:(NSString *)cancelButtonTitle + otherButtonTitles:(NSArray *)otherButtons + onTextFieldDismiss:(TextFieldDismissBlock)dismissed + onCancel:(CancelBlock)cancelled +{ + UIAlertView *alert = [[UIAlertView alloc] showAlertViewWithTitle:title + message:message + cancelButtonTitle:cancelButtonTitle + otherButtonTitles:otherButtons + dismissBlock:nil + textFieldDismissBlock:dismissed + cancelBlock:cancelled]; +#if !__has_feature(objc_arc) + return [alert autorelease]; +#else + return alert; +#endif +} + +- (UIAlertView*)showAlertViewWithTitle:(NSString*)title + message:(NSString*)message + cancelButtonTitle:(NSString*)cancelButtonTitle + otherButtonTitles:(NSArray*)otherButtons + dismissBlock:(DismissBlock)dismiss + textFieldDismissBlock:(TextFieldDismissBlock)textFieldDismiss + cancelBlock:(CancelBlock)cancel +{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:[self class] cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil]; - [alert setDismissBlock:dismissed]; - [alert setCancelBlock:cancelled]; + [alert setCancelBlock:cancel]; + if (dismiss) + [alert setDismissBlock:dismiss]; + if (textFieldDismiss) { + [alert setAlertViewStyle:UIAlertViewStylePlainTextInput]; + [alert setTextFieldDismissBlock:textFieldDismiss]; + } for(NSString *buttonTitle in otherButtons) [alert addButtonWithTitle:buttonTitle]; @@ -98,6 +158,11 @@ + (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger) alertView.cancelBlock(); } } + else if (alertView.alertViewStyle==UIAlertViewStylePlainTextInput) { + if (alertView.textFieldDismissBlock) { + alertView.textFieldDismissBlock(buttonIndex - 1, [alertView textFieldAtIndex:0]); + } + } else { if (alertView.dismissBlock) {