diff --git a/MBProgressHUD.h b/MBProgressHUD.h old mode 100644 new mode 100755 index 834954a49..01af308e0 --- a/MBProgressHUD.h +++ b/MBProgressHUD.h @@ -104,8 +104,12 @@ typedef enum { float progress; +#if __has_feature(objc_arc) + id __weak delegate; +#else id delegate; - NSString *labelText; +#endif + NSString *labelText; NSString *detailsLabelText; float opacity; UIFont *labelFont; @@ -165,8 +169,11 @@ typedef enum { * The UIView (i.g., a UIIMageView) to be shown when the HUD is in MBProgressHUDModeCustomView. * For best results use a 37 by 37 pixel view (so the bounds match the build in indicator bounds). */ +#if __has_feature(objc_arc) +@property (strong) UIView *customView; +#else @property (retain) UIView *customView; - +#endif /** * MBProgressHUD operation mode. Switches between indeterminate (MBProgressHUDModeIndeterminate) and determinate * progress (MBProgressHUDModeDeterminate). The default is MBProgressHUDModeIndeterminate. @@ -187,8 +194,11 @@ typedef enum { * delegate should conform to the MBProgressHUDDelegate protocol and implement the hudWasHidden method. The delegate * object will not be retained. */ +#if __has_feature(objc_arc) +@property (weak) id delegate; +#else @property (assign) id delegate; - +#endif /** * An optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit * the entire text. If the text is too long it will get clipped by displaying "..." at the end. If left unchanged or @@ -267,13 +277,19 @@ typedef enum { /** * Font to be used for the main label. Set this property if the default is not adequate. */ +#if __has_feature(objc_arc) +@property (strong) UIFont* labelFont; +#else @property (retain) UIFont* labelFont; - +#endif /** * Font to be used for the details label. Set this property if the default is not adequate. */ +#if __has_feature(objc_arc) +@property (strong) UIFont* detailsLabelFont; +#else @property (retain) UIFont* detailsLabelFont; - +#endif /** * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0. */ diff --git a/MBProgressHUD.m b/MBProgressHUD.m old mode 100644 new mode 100755 index fb623f901..33379aa8a --- a/MBProgressHUD.m +++ b/MBProgressHUD.m @@ -19,19 +19,26 @@ - (void)handleGraceTimer:(NSTimer *)theTimer; - (void)handleMinShowTimer:(NSTimer *)theTimer; - (void)setTransformForCurrentOrientation:(BOOL)animated; - (void)cleanUp; -- (void)deviceOrientationDidChange:(NSNotification*)notification; - (void)launchExecution; - (void)deviceOrientationDidChange:(NSNotification *)notification; - (void)hideDelayed:(NSNumber *)animated; - (void)launchExecution; - (void)cleanUp; +#if __has_feature(objc_arc) +@property (strong) UIView *indicator; +@property (strong) NSTimer *graceTimer; +@property (strong) NSTimer *minShowTimer; +@property (strong) NSDate *showStarted; +#else @property (retain) UIView *indicator; -@property (assign) float width; -@property (assign) float height; @property (retain) NSTimer *graceTimer; @property (retain) NSTimer *minShowTimer; @property (retain) NSDate *showStarted; +#endif + +@property (assign) float width; +@property (assign) float height; @end @@ -149,14 +156,18 @@ - (float)progress { - (void)updateLabelText:(NSString *)newText { if (labelText != newText) { +#if !__has_feature(objc_arc) [labelText release]; +#endif labelText = [newText copy]; } } - (void)updateDetailsLabelText:(NSString *)newText { if (detailsLabelText != newText) { +#if !__has_feature(objc_arc) [detailsLabelText release]; +#endif detailsLabelText = [newText copy]; } } @@ -171,13 +182,22 @@ - (void)updateIndicators { } if (mode == MBProgressHUDModeDeterminate) { +#if __has_feature(objc_arc) + self.indicator = [[MBRoundProgressView alloc] init]; +#else self.indicator = [[[MBRoundProgressView alloc] init] autorelease]; - } +#endif +} else if (mode == MBProgressHUDModeCustomView && self.customView != nil){ self.indicator = self.customView; } else { +#if __has_feature(objc_arc) + self.indicator = [[UIActivityIndicatorView alloc] + initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; +#else self.indicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease]; +#endif [(UIActivityIndicatorView *)indicator startAnimating]; } @@ -200,7 +220,11 @@ + (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated { MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view]; [view addSubview:hud]; [hud show:animated]; +#if __has_feature(objc_arc) + return hud; +#else return [hud autorelease]; +#endif } + (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated { @@ -245,6 +269,15 @@ - (id)initWithView:(UIView *)view { return me; } +- (void)removeFromSuperview { + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UIDeviceOrientationDidChangeNotification + object:nil]; + + [super removeFromSuperview]; +} + + - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { @@ -287,9 +320,8 @@ - (id)initWithFrame:(CGRect)frame { return self; } +#if !__has_feature(objc_arc) - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [indicator release]; [label release]; [detailsLabel release]; @@ -301,6 +333,7 @@ - (void)dealloc { [customView release]; [super dealloc]; } +#endif #pragma mark - #pragma mark Layout @@ -484,9 +517,14 @@ - (void)handleMinShowTimer:(NSTimer *)theTimer { - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated { methodForExecution = method; +#if __has_feature(objc_arc) + targetForExecution = target; + objectForExecution = object; +#else targetForExecution = [target retain]; objectForExecution = [object retain]; - +#endif + // Launch execution in new thread taskInProgress = YES; [NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil]; @@ -496,8 +534,9 @@ - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object } - (void)launchExecution { +#if !__has_feature(objc_arc) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - +#endif // Start executing the requested task [targetForExecution performSelector:methodForExecution withObject:objectForExecution]; @@ -505,7 +544,9 @@ - (void)launchExecution { // be done only in the main thread) [self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO]; +#if !__has_feature(objc_arc) [pool release]; +#endif } - (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context { @@ -536,8 +577,10 @@ - (void)cleanUp { self.indicator = nil; +#if !__has_feature(objc_arc) [targetForExecution release]; [objectForExecution release]; +#endif [self hide:useAnimation]; }