Advertisement
priore

More useful macros

Sep 6th, 2012
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Devices
  2. #define ISPAD() ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  3. #define ISPHONE() ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
  4. #define ISPHONE5() (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
  5. #define ISRETINA() (BOOL isRetina = NO; if ([UIScreen instancesRespondToSelector:@selector(scale)])) { isRetina = ([[UIScreen mainScreen] scale] == 1.0 ? NO : YES) } return isRetina)
  6. // #define DEVICE_ID [[UIDevice currentDevice] uniqueIdentifier] deprecated!!
  7.  
  8. // Path
  9. #define DOC_PATH(path)[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:path]
  10.  
  11. // iOS Versions
  12. #define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
  13. #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
  14. #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  15. #define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
  16. #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
  17.  
  18. // WebView
  19. #define SCROLL_ENABLE(enable,webview) {for(id subview in webview.subviews){if ([[subview class] isSubclassOfClass:[UIScrollView class]]){((UIScrollView *)subview).scrollEnabled=enable;}}}
  20. #define BOUNCES_ENABLE(enable,webview)  {for(id subview in webview.subviews){if ([[subview class] isSubclassOfClass:[UIScrollView class]]){((UIScrollView *)subview).bounces=enable;}}}
  21.  
  22. // AlertView
  23. #define ALERT(title,msg) {UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil] autorelease];[alert show];}
  24.  
  25. // Frame Position
  26. #define CGPositionMake(r,x,y) CGRectMake(x,y,r.frame.size.width,r.frame.size.height)
  27.  
  28. // Localization
  29. #define LocalizedString(key) [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
  30.  
  31. // Block
  32. #ifdef __clang__
  33. /* clang doesn't support always_inline attribute on blocks,
  34.    use -O3 or other aggressive inlining optimization, say -finline-functions */
  35.     #define _ALWAYS_INLINE  
  36. #else
  37.     #define _ALWAYS_INLINE  __attribute__((always_inline))
  38. #endif
  39. #define __with_v(t) ^(t v) _ALWAYS_INLINE { #define __with_end(v) } (v);
  40. /* example (origin: http://pastebin.com/JpUHNgX4)
  41.     __with_v(UILabel*)
  42.         v.textColor = [UIColor darkGrayColor];
  43.         v.font = [UIFont systemFontOfSize:13.];
  44.      __with_end(v.textLabel);
  45. */
  46.  
  47. // ARC Trick
  48. #define ARC_RETAIN(obj) ((id(*)(id, SEL))objc_msgSend)(obj, NSSelectorFromString(@"retain"));
  49. #define ARC_RELEASE(obj) ((id(*)(id, SEL))objc_msgSend)(obj, NSSelectorFromString(@"release"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement