極力推薦:技術(shù)分享和Demo應(yīng)用
如果大家有其他的常用的宏定義瘫镇,歡迎添加,東西如果不全面,請(qǐng)批評(píng)和指正! (1. 判斷機(jī)型
, 2.適配iPhone Xs MAX TabBar和導(dǎo)航,適配6s為基準(zhǔn),ipd,iPhone自適應(yīng)大小, 3.獲取系統(tǒng)版本 iOS 13 , 4.GRB 顏色設(shè)置, 5.用于正則式,并非正則式, 6.常用提示框, 7.是否為空或是[NSNull null], 8.字符串是否為空, 9.數(shù)組是否為空, 10.便捷方式創(chuàng)建NSNumber類型, 11.便捷創(chuàng)建NSString, 12.線程執(zhí)行方法, 13.單例創(chuàng)建, 14.通過字典的key 獲取NSString,NSNumber,NSDictionary, 15.block 聲明 16.NSString轉(zhuǎn)UTF8 17.去空格,首尾空格和換行符,去掉所有的空格),18. 字體設(shè)置, 19.獲取相關(guān)權(quán)限,20.弱引用和強(qiáng)引用, 21.獲取圖片資源, 22.arc 和mrc 會(huì)陸續(xù)更新最新使用的方法... , 23.字體設(shè)置 , 24. 存取值 , 25.獲取圖片和獲取版本號(hào)
14:通過字典的key 獲取 NSString,NSNumber,NSDictionary ,NSArray (推薦使用)
常用方法: 1.計(jì)算Label多行的高度, 2.登錄密碼正則表達(dá)式(大字母或者小寫字母,數(shù)字,特殊符號(hào),必須有都含有,8-16位) ,3.返回指定的界面 4.獲取網(wǎng)絡(luò)運(yùn)行商 ,5.自我封裝NSdate 常用方法(不完善持續(xù)更新...)
附加:Xcode注釋和推薦使用
// FIXME: (標(biāo)示處代碼需要修正窜司,使用方法) // FIXME: ??
// TODO: (標(biāo)示處有功能代碼待編寫筒繁,使用方法) // TODO:??
// !!!: (標(biāo)示處代碼需要注意熟呛,使用方法) // !!!:??
// MARK: (標(biāo)記广辰,和#pragma mark效果相同) // MARK:??
局部常量:static const NSString *NAME = @“fansion”;//用static修飾后外部不能訪問
全局常量:不管在哪個(gè)文件夾讲岁,外部都能訪問;
const NSString *NAME = @“fansion”;//*NAME不能被修改酵幕,NAME可以
NSString const *NAME = @“fansion”;//*NAME不能被修改扰藕,NAME可以
NSString *const NAME = @“fansion”;//*NAME能被修改,NAME不可以
1.適配 iPhone 14
#define kScreenWidth ([[UIScreen mainScreen] bounds].size.width)
#define kScreenHeight ([[UIScreen mainScreen] bounds].size.height)
/**適配 iPhone X TabBar和導(dǎo)航區(qū)別
* Top區(qū)別:iPhone 14 為例:導(dǎo)航(44 points)+狀態(tài)欄(47 points)= 91 points
* Top區(qū)別:iPhone 14 pro 為例:導(dǎo)航(44 points)+狀態(tài)欄(54 points)= 99 points
* Iphone 6s為例:導(dǎo)航(44 points)+狀態(tài)欄(20 points)= 64 points
* Bottom區(qū)別:iPhone X 為例: 83 points高度(TabBar) = Danger Area(34 points) + 原來的49 points
* Iphone 6s為例:49 points高度(TabBar) = 49 points
*/
//iPhone14 (47) / iPhone14 Pro Max (54)
/**狀態(tài)欄的高度**/
let kStatusBarHeight: CGFloat = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
/**底部安全區(qū)域高度**/
let kSafeAreaBottom: CGFloat = window?.safeAreaInsets.bottom ?? 0
/**狀態(tài)欄+navi高度**/
let kNavAndStatusBarHeight: CGFloat = kStatusBarHeight + 44
#define TabbarHeight (isFullScreen ? (49.f+34.f) :49.f)
#define TabbarSafeBottomHeight (isFullScreen ?34.f:0.f)
#define StatusBarAndNavigationBarHeight (isFullScreen ?88.f:64.f)
/* iOS設(shè)備 */
#define kDevice_Is_iPhone4s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDevice_Is_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDevice_Is_iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDevice_Is_iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6PlusBigMode ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen]currentMode].size) : NO)
#define iphoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen]currentMode].size) : NO)
#define PW ([UIScreen mainScreen].bounds.size.width/375)
#define PH ([UIScreen mainScreen].bounds.size.height/667)
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
//6s適配參數(shù)
#define KsuitParam (kDevice_Is_iPhone6Plus ?1.12:(kDevice_Is_iPhone6?1.0:(iPhone6PlusBigMode ?1.01:(iphoneX ? 1.0 : 0.85)))) //以6s為基準(zhǔn)圖
2.判斷機(jī)型
//判斷是否為iPhone
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
//判斷是否為iPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//判斷是否為ipod
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
// 判斷 iPad
#define DX_UI_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// 判斷iPhone X
#define DX_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
//判斷iPHoneXr | 11
#define DX_Is_iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !DX_UI_IS_IPAD : NO)
//判斷iPHoneXs | 11Pro
#define DX_Is_iPhoneXS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !DX_UI_IS_IPAD : NO)
//判斷iPhoneXs Max | 11ProMax
#define DX_Is_iPhoneXS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !DX_UI_IS_IPAD : NO)
//判斷iPhone12_Mini
#define DX_Is_iPhone12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !DX_UI_IS_IPAD : NO)
//判斷iPhone12 | 12Pro
#define DX_Is_iPhone12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !DX_UI_IS_IPAD : NO)
//判斷iPhone12 Pro Max
#define DX_Is_iPhone12_ProMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !DX_UI_IS_IPAD : NO)
//x系列
#define DX_IS_IPhoneX_All (DX_Is_iPhoneX || DX_Is_iPhoneXR || DX_Is_iPhoneXS || DX_Is_iPhoneXS_MAX || DX_Is_iPhone12_Mini || DX_Is_iPhone12 || DX_Is_iPhone12_ProMax)
- 獲取系統(tǒng)版本
#ifndef __IPHONE_13_0
#define __IPHONE_13_0 130000
#endif
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
...
#endif
#define IOS_SYSTEM_STRING [[UIDevice currentDevice] systemVersion]
#define IOS11_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0)
#define IOS10_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0)
#define IOS9_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
#define IOS8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IOS7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
4.GRB 顏色設(shè)置
/** 顏色RGB */
#define HSVCOLOR(h,s,v) [UIColor colorWithHue:h saturation:s value:v alpha:1]
#define HSVACOLOR(h,s,v,a) [UIColor colorWithHue:h saturation:s value:v alpha:a]
/** 16進(jìn)制色值參數(shù)轉(zhuǎn)換 */
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
4.ImageNamed 設(shè)置
#define ImageNamed(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
5.用于正則式
/** 用于正則式 */
/** 用于正則式 */
#define NUM @"0123456789"
#define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
/** 驗(yàn)證手機(jī)號(hào)及固話方法 */
#define TelephoneNUM @"^(0[0-9]{2,3})?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\\d{8}$)"
/** 判斷社會(huì)信用代碼證 */
#define SocialCreditNUM @"^([0-9ABCDEFGHJKLMNPQRTUWXY]{2})([0-9]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{9})([0-9Y])$"
/** 工商稅號(hào) */
#define BusinessCirclesNUM @"[0-9]\\\\d{13}([0-9]|X)$"
/** 郵政編碼 */
#define CodeNUM @"^[0-8]\\\\d{5}(?!\\\\d)$"
/** 驗(yàn)證身份證號(hào)(15位或18位數(shù)字) */
#define IDCardNUM @"\\d{14}[[0-9],0-9xX]"
/** 驗(yàn)證Email地址 */
#define EmailNUM @"^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\.\\w+([-.]\\w+)*$"
/** 整數(shù)或者小數(shù) */
#define IntAndDecimalNUM @"^[0-9]+([.]{0,1}[0-9]+){0,1}$"
/** 驗(yàn)證URL */
#define URLNUM @"^http://([\\w-]+\.)+[\\w-]+(/[\\w-./?%&=]*)?$"
/** 驗(yàn)證QQ */
#define QQNUM @"[1-9][0-9]\{4,\}"
/** 匹配帳號(hào)是否合法 */
#define AccountLegalityNUM @"^[a-zA-Z][a-zA-Z0-9_]{4,15}$"
/** 只能輸入漢字 */
#define ChineseCharactersNUM @"^[\u4e00-\u9fa5]{0,}$"
/** 匹配空白行的正則表達(dá)式 */
#define SpaceNUM @"^\n\s*\r"
6.常用NSlog打印
/** 打印 NSlog */
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
/**打印信息*/
#define NSLogI(fmt, ...) NSLog((@"%s ??INFO [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
/**調(diào)試信息*/
#define NSLogD(fmt, ...) NSLog((@"%s ??DEBUG [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
/**錯(cuò)誤信息*/
#define NSLogE(fmt, ...) NSLog((@"%s ??ERROR [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
/**未知信息*/
#define NSLogU(fmt, ...) NSLog((@"%s ??UNKNOW [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
6.常用提示框
/** 彈出提示框 UIAlertView */
#define showMessageView(__MESSAGE__) \
UIAlertView *alertView_ = [[UIAlertView alloc] initWithTitle:@"提示" \
message:__MESSAGE__ \
delegate:nil \
cancelButtonTitle:@"確定" \
otherButtonTitles:nil]; \
[alertView_ show];
/** 彈出提示框 UIAlertController */
#define showMessageController(MESSAGE,VC) \
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:MESSAGE preferredStyle:UIAlertControllerStyleAlert]; \
UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil]; \
[alertController addAction:action]; \
[VC presentViewController:alertController animated:YES completion:nil]
7.是否為空或是[NSNull null]
/**是否為空或是[NSNull null] */
#define NotNilAndNull(_ref) (((_ref) != nil) && (![(_ref) isEqual:[NSNull null]]))
#define IsNilOrNull(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]])
- 字符串是否為空
/**是否為空或是[NSNull null] */
#define IsStrEmpty(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref)isEqualToString:@""]))
- 數(shù)組是否為空
#define IsArrEmpty(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref) count] == 0))
10.便捷方式創(chuàng)建NSNumber類型
/** 便捷方式創(chuàng)建NSNumber類型 */
#undef __INT
#define __INT( __x ) [NSNumber numberWithInt:(NSInteger)__x]
#undef __UINT
#define __UINT( __x ) [NSNumber numberWithUnsignedInt:(NSUInteger)__x]
#undef __FLOAT
#define __FLOAT( __x ) [NSNumber numberWithFloat:(float)__x]
#undef __DOUBLE
#define __DOUBLE( __x ) [NSNumber numberWithDouble:(double)__x]
11.便捷創(chuàng)建NSString
/** 便捷創(chuàng)建NSString */
#undef STR_FROM_INT
#define STR_FROM_INT( __x ) [NSString stringWithFormat:@"%d", (__x)]
12.線程執(zhí)行方法
/** 線程執(zhí)行方法 */
#define Foreground_Begin dispatch_async(dispatch_get_main_queue(), ^{
#define Foreground_End });
#define Background_Begin dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\
@autoreleasepool {
#define Background_End }\
});
13.單例創(chuàng)建
/** 線程執(zhí)行方法 */
#undef AS_SINGLETON
#define AS_SINGLETON( __class ) \
+ (__class *)sharedInstance;
#undef DEF_SINGLETON
#define DEF_SINGLETON( __class ) \
+ (__class *)sharedInstance \
{ \
static dispatch_once_t once; \
static __class * __singleton__; \
dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \
return __singleton__; \
}
- 通過字典的key 獲取NSString,NSNumber,NSDictionary ,NSArray
.h創(chuàng)建
/** 通過字典的key 獲取value (判斷轉(zhuǎn)換為)NSString */
extern NSString* EncodeStringFromDic(NSDictionary *dic, NSString *key);
/** 通過字典的key 獲取value (判斷轉(zhuǎn)換為)NSNumber */
extern NSNumber* EncodeNumberFromDic(NSDictionary *dic, NSString *key);
extern NSDictionary *EncodeDicFromDic(NSDictionary *dic, NSString *key);
extern NSArray *EncodeArrayFromDic(NSDictionary *dic, NSString *key);
extern NSArray *EncodeArrayFromDicUsingParseBlock(NSDictionary *dic, NSString *key, id(^parseBlock)(NSDictionary *innerDic));
.m創(chuàng)建
NSString* EncodeStringFromDic(NSDictionary *dic, NSString *key)
{
id temp = [dic objectForKey:key];
if ([temp isKindOfClass:[NSString class]])
{
return temp;
}
else if ([temp isKindOfClass:[NSNumber class]])
{
return [temp stringValue];
}
return nil;
}
NSNumber* EncodeNumberFromDic(NSDictionary *dic, NSString *key)
{
id temp = [dic objectForKey:key];
if ([temp isKindOfClass:[NSString class]])
{
return [NSNumber numberWithDouble:[temp doubleValue]];
}
else if ([temp isKindOfClass:[NSNumber class]])
{
return temp;
}
return nil;
}
NSDictionary *EncodeDicFromDic(NSDictionary *dic, NSString *key)
{
id temp = [dic objectForKey:key];
if ([temp isKindOfClass:[NSDictionary class]])
{
return temp;
}
return nil;
}
NSArray *EncodeArrayFromDic(NSDictionary *dic, NSString *key)
{
id temp = [dic objectForKey:key];
if ([temp isKindOfClass:[NSArray class]])
{
return temp;
}
return nil;
}
NSArray *EncodeArrayFromDicUsingParseBlock(NSDictionary *dic, NSString *key, id(^parseBlock)(NSDictionary *innerDic))
{
NSArray *tempList = EncodeArrayFromDic(dic, key);
if ([tempList count])
{
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[tempList count]];
for (NSDictionary *item in tempList)
{
id dto = parseBlock(item);
if (dto) {
[array addObject:dto];
}
}
return array;
}
return nil;
}
15.block 聲明
#ifdef NS_BLOCKS_AVAILABLE
typedef void (^ZLyBasicBlock)(void);
typedef void (^ZLyOperationCallBackBlock)(BOOL isSuccess, NSString *errorMsg);
typedef void (^ZLyArrayBlock)(NSArray *list);
#endif
16.NSString轉(zhuǎn)UTF8
#define OC(str) [NSString stringWithCString:(str) encoding:NSUTF8StringEncoding]
17.去空格,首尾空格和換行符,去掉所有的空格
/** 去掉首尾空格和換行符 */
#define FirstAndLastSpace(str) [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]
/**去掉所有空格*/
#define RemoveAllSpaces(str) [str stringByReplacingOccurrencesOfString:@" " withString:@""]
18.字體設(shè)置
#define Font_Size(f) [UIFont systemFontOfSize:(f)]
#define Font_Bold_Size(f) [UIFont boldSystemFontOfSize:(f)]
#define Font_Italic_Size(f) [UIFont italicSystemFontOfSize:(f)]
#define FontMediumSize(s) [UIFont fontWithName:@"xxx" size:s]
#define FontRegularSize(s) [UIFont fontWithName:@"xxx" size:s]
19.獲取相關(guān)權(quán)限. 相加,地位等
//獲取相機(jī)權(quán)限狀態(tài)
#define CameraStatus [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]
#define CameraDenied ((CameraStatus == AVAuthorizationStatusRestricted)||(CameraStatus == AVAuthorizationStatusDenied))
#define CameraAllowed (!CameraDenyed)
/** 定位權(quán)限*/
#define LocationStatus [CLLocationManager authorizationStatus];
#define LocationAllowed ([CLLocationManager locationServicesEnabled] && !((status == kCLAuthorizationStatusDenied) || (status == kCLAuthorizationStatusRestricted)))
#define LocationDenied (!LocationAllowed)
/** 消息推送權(quán)限*/
#define PushClose (([[UIDevice currentDevice].systemVersion floatValue]>=8.0f)?(UIUserNotificationTypeNone == [[UIApplication sharedApplication] currentUserNotificationSettings].types):(UIRemoteNotificationTypeNone == [[UIApplication sharedApplication] enabledRemoteNotificationTypes]))
#define PushOpen (!PushClose)
20.弱引用,強(qiáng)引用
#define WeakSelf(type) __weak typeof(type) weak##type = type;
#define StrongSelf(type) __strong typeof(type) type = weak##type;
21.獲取圖片資源
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
22.arc OR mrc
#if __has_feature(objc_arc)
// ARC
#else
// MRC
#endif
23.字體設(shè)置
#define IsIphone6P SCREEN_WIDTH==414
#define SizeScale (IsIphone6P ? 1.5 : 1)
#define kFontSize(value) value*SizeScale
#define kFont(value) [UIFont systemFontOfSize:value*SizeScale]
/**36px 導(dǎo)航欄文字**/
#define ZLyFont_36 [UIFont systemFontOfSize:36 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**32px 按鈕文字,標(biāo)題文字**/
#define ZLyFont_32 [UIFont systemFontOfSize:32 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**30px 正文內(nèi)容**/
#define ZLyFont_30 [UIFont systemFontOfSize:30 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**28px 填寫描述**/
#define ZLyFont_28 [UIFont systemFontOfSize:28 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**26px 輔助文字**/
#define ZLyFont_26 [UIFont systemFontOfSize:26 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**24px 輔助文字**/
#define ZLyFont_24 [UIFont systemFontOfSize:24 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**22px 說明性文字**/
#define ZLyFont_22 [UIFont systemFontOfSize:22 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**20px 輔助說明性文字**/
#define ZLyFont_20 [UIFont systemFontOfSize:20 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
/**100px **/
#define ZLyFont_100 [UIFont systemFontOfSize:100 / (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)?750.0:1536.0) * [UIScreen mainScreen].bounds.size.width]
24 存取數(shù)據(jù)
//存值
#define kSaveMyDefault(A,B) [[NSUserDefaults standardUserDefaults] setObject:B forKey:A]
//取值
#define kFetchMyDefault(A) [[NSUserDefaults standardUserDefaults] objectForKey:A]
#define kSaveZLyDefault(A,B) [[NSUserDefaults standardUserDefaults] setInteger:B forKey:A]
#define kFetchZLyDefault(A) [[NSUserDefaults standardUserDefaults] integerForKey:A]
25.獲取圖片和版本號(hào)
#define ImageName(name) [UIImage imageNamed:name]
#define FontSize(size) [UIFont systemFontOfSize:size]
#define VERSION (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
1.計(jì)算Label多行的高度
/**
1.根據(jù)text的font和字符串自動(dòng)算出size(重點(diǎn))
2.本身最大寬度
MAXFLOAT:最大高度為最大浮點(diǎn)數(shù)
**/
-(CGFloat)calculateString:(NSString *)str Width:(NSInteger)width Font:(NSInteger)font {
CGSize size = [str boundingRectWithSize:CGSizeMake(width, 100000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:font]} context:nil].size;
return size.height;
}
2.登錄密碼正則表達(dá)式
NSString *regex =@"(?=.*?[a-zA-Z])(?=.*?[0-9])(?=.*?[^\\w\\s]).{8,16}";
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
// 字符串判斷芳撒,然后BOOL值
BOOL result1 = [predicate1 evaluateWithObject:newpasswd];
3.返回指定的界面
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[要返回的類名 class]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
或者dissVC
[self.presentingViewController.presentingvc dismissViewControllerAnimated:NO completion:nil];
4.獲取網(wǎng)絡(luò)運(yùn)營(yíng)商
//獲取網(wǎng)絡(luò)運(yùn)營(yíng)商
+(NSString *)CTTelephonyNetworkProviders
{
//獲取本機(jī)運(yùn)營(yíng)商名稱
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [info subscriberCellularProvider];
//當(dāng)前手機(jī)所屬運(yùn)營(yíng)商名稱
NSString *mobile;
//先判斷有沒有SIM卡邓深,如果沒有則不獲取本機(jī)運(yùn)營(yíng)商
if (!carrier.isoCountryCode) {
// NSLog(@"沒有SIM卡");
mobile = @"無運(yùn)營(yíng)商";
}else{
mobile = [carrier carrierName];
}
return mobile;
}
5.NSdate 轉(zhuǎn)換(nsstring 格式)
+ (NSInteger)compareDate:(NSString*)startDate withDate:(NSString*)endDate;
/**只算小時(shí)和分鐘 HH:mm **/
+ (NSString *)dateStringWithHouseAndSecond:(NSString *)dateStr;
/* YYYY-MM-dd EEE HH:mm */
+(NSString *)dateString:(NSString *)dateStr;
/**EEE**/
+(NSString *)dateWeekString:(NSString *)dateStr;
/**MM-dd**/
+(NSString *)dateMonthAndDayString:(NSString *)dateStr;
/** yyyy-MM-dd HH:mm ----- MM-dd **/
+(NSString *)dateNewMonthAndDayString:(NSString *)dateStr;
/** yyyy-MM-dd HH:mm ----- yyyy **/
+(NSString *)dateAndYearString:(NSString *)dateStr;
/** yyyy-MM-dd HH:mm ----- yyyy-MM-dd 新增**/
+(NSString *)dateAndYearAndMonthAndDayString:(NSString *)dateStr;
/**獲取當(dāng)前時(shí)間**/
+(NSString*)getCurrentTimes;
/**獲取周數(shù) 周日-周六 (國(guó)外日歷)**/
+(NSString *)obtainCurrentDateAndUpdateInterface:(NSString *)datestring;
/****獲取當(dāng)前的時(shí)間 YYYY-MM-dd HH:mm****/
+(NSString*)getCurrentTimesYearAndMonthAndDayAndHoursAndSecond;
//獲取當(dāng)前的時(shí)間 只展示時(shí)間HH
+(NSString*)getCurrentTimesHH;
//獲取當(dāng)前的時(shí)間 YYYY-MM-dd HH:mm:ss
+(NSString*)getCurrentTimesYYYYMMddHHmmss ;
//獲取當(dāng)前的時(shí)間 YYYY-MM-dd HH:mm --- HH:mm
+(NSString *)dateHoursAndMinuesString:(NSString *)dateStr;
+ (NSString *)getCurrentWeek;
#pragma mark 獲取當(dāng)前第一天日期(周日)
+ (NSString *)obtainCurrentDateSunday:(NSString *)sundayString;
/**獲取周數(shù) 周日-周六 (國(guó)外日歷)**/
#pragma mark 獲取當(dāng)前第一天日期(周一)
+ (NSString *)obtainCurrentDateMonday:(NSString *)mondayString ;
/**獲取周數(shù) 周日-周六 (國(guó)外日歷)**/
#pragma mark 獲取當(dāng)前第一天日期(周二)
+ (NSString *)obtainCurrentDateTuesday:(NSString *)TuesdayString;
/**獲取周數(shù) 周日-周六 (國(guó)外日歷)**/
#pragma mark 獲取當(dāng)前第一天日期(周三)
+ (NSString *)obtainCurrentDateWenday:(NSString *)WendayString;
/**獲取周數(shù) 周日-周六 (國(guó)外日歷)**/
#pragma mark 獲取當(dāng)前第一天日期(周四)
+ (NSString *)obtainCurrentDateThursday:(NSString *)ThursdayString;
/**獲取周數(shù) 周日-周六 (國(guó)外日歷)**/
#pragma mark 獲取當(dāng)前第一天日期(周五)
+ (NSString *)obtainCurrentDateFriday:(NSString *)FridayString;
#pragma mark 獲取當(dāng)前第后天日期(周六)
+ (NSString *)obtainCurrentDateSaturday:(NSString *)SaturdayString;