Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

ARC/MRC compatible #12

Open
wants to merge 4 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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
project.xcworkspace
xcuserdata
Binary file added [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions MKAdditions/MKBlockAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions MKAdditions/NSObject+MKBlockAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ @implementation NSObject (MKBlockAdditions)

- (void) performBlock:(VoidBlock) aBlock
{
[_block release];
#if !__has_feature(objc_arc)
[_block release];
#endif
_block = [aBlock copy];

[self performSelector:@selector(callBlock)];
}

- (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];
Expand All @@ -31,7 +35,9 @@ - (void) performBlock:(VoidBlock) aBlock afterDelay:(NSTimeInterval) delay
-(void) callBlock
{
_block();
#if !__has_feature(objc_arc)
[_block release];
#endif
_block = nil;
}

Expand Down
21 changes: 21 additions & 0 deletions MKAdditions/UIActionSheet+MKBlockAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
#import "MKBlockAdditions.h"

@interface UIActionSheet (MKBlockAdditions) <UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
+(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
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
Expand Down
142 changes: 129 additions & 13 deletions MKAdditions/UIActionSheet+MKBlockAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,77 @@

@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
{
[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];
[_dismissBlock release];
#endif
_cancelBlock = [cancelled copy];
_dismissBlock = [dismissed copy];

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title
delegate:(id<UIActionSheetDelegate>)[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 ++;

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
}

+(void) actionSheetWithTitle:(NSString*) title
message:(NSString*) message
buttons:(NSArray*) buttonTitles
Expand All @@ -39,14 +110,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<UIActionSheetDelegate>)[self class]
cancelButtonTitle:nil
destructiveButtonTitle:destructiveButtonTitle
otherButtonTitles:nil];
Expand All @@ -69,8 +141,9 @@ + (void) actionSheetWithTitle:(NSString*) title
if([view isKindOfClass:[UIBarButtonItem class]])
[actionSheet showFromBarButtonItem:(UIBarButtonItem*) view animated:YES];

#if !__has_feature(objc_arc)
[actionSheet release];
#endif
}

+ (void) photoPickerWithTitle:(NSString*) title
Expand All @@ -79,19 +152,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<UIActionSheetDelegate>)[self class]
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
Expand Down Expand Up @@ -121,8 +199,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
}


Expand All @@ -134,16 +213,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();
}

Expand All @@ -168,7 +251,7 @@ +(void)actionSheet:(UIActionSheet*) actionSheet didDismissWithButtonIndex:(NSInt


UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = [self class];
picker.delegate = (id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>)[self class];
picker.allowsEditing = YES;

if(buttonIndex == 1)
Expand All @@ -188,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
8 changes: 8 additions & 0 deletions MKAdditions/UIAlertView+MKBlockAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading