iOS学习资料四

每天学习一点点,进步一点点

1、自定义NSLog

#ifdef DEBUG

#define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

#else

#define NSLog(...)

#endif

2、Font

#define FontL(s)            [UIFont systemFontOfSize:s weight:UIFontWeightLight]

#define FontR(s)            [UIFont systemFontOfSize:s weight:UIFontWeightRegular]

#define FontB(s)            [UIFont systemFontOfSize:s weight:UIFontWeightBold]

#define FontT(s)            [UIFont systemFontOfSize:s weight:UIFontWeightThin]

#define Font(s)              FontL(s)

3、FORMAT

#define FORMAT(f, ...)      [NSString stringWithFormat:f, ## __VA_ARGS__]

4、在主线程上运行

#define kDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);

5、开启异步线程

#define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);

6、通知

#define NOTIF_ADD(n, f)    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(f) name:n object:nil]#define NOTIF_POST(n, o)    [[NSNotificationCenter defaultCenter] postNotificationName:n object:o]#define NOTIF_REMV()        [[NSNotificationCenter defaultCenter] removeObserver:self]

7、随机颜色

+ (UIColor *)RandomColor {  

  NSInteger aRedValue = arc4random() % 255;   

 NSInteger aGreenValue = arc4random() % 255;   

 NSInteger aBlueValue = arc4random() % 255;   

 UIColor *randColor = [UIColor colorWithRed:aRedValue / 255.0f green:aGreenValue / 255.0f blue:aBlueValue / 255.0f alpha:1.0f]; 

   return randColor;

}

8、获取window

+(UIWindow*)getWindow {UIWindow* win =nil;

//[UIApplication sharedApplication].keyWindow;

for(iditemin[UIApplicationsharedApplication].windows) {if([itemclass] == [UIWindowclass]) 

{

If 

 (!((UIWindow*)item).hidden) 

{      

          win = item;

break;     

       }      

  }

    }

return   win;

}

9、修改textField的placeholder的字体颜色、大小

[textField setValue:[UIColor redColor]forKeyPath:@"_placeholderLabel.textColor"];

[textField setValue:[UIFont boldSystemFontOfSize:16]forKeyPath:@"_placeholderLabel.font"];

10、统一收起键盘

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

你可能感兴趣的:(iOS学习资料四)