每天學習一點點,進步一點點
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];