-
Notifications
You must be signed in to change notification settings - Fork 5
功能简介 Function summary
Damon edited this page Apr 10, 2018
·
1 revision
///弱引用 Weak reference
#define HDWEAKSELF __weak typeof(self) weakSelf = self
///强引用 Strong reference
#define HDSTRONGSELF __strong typeof(weakSelf) strongSelf = weakSelf
#pragma mark -
#pragma mark - log输出
//log输出,当为true时输出log,false不输出log
//Log output, when log is output for true, false does not output log
#define HDDEBUG_MODE true
#if HDDEBUG_MODE
#define HDDebugLog( s, ... ) NSLog( @"\n↓↓↓↓↓↓↓↓\n<%p %@:(%d)> \n%s\n%@\n↑↑↑↑↑↑↑↑", __FILE__, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __FUNCTION__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define HDDebugLog( s, ... )
#endif
#pragma mark -
#pragma mark - 界面 Interface
/*
* UIColor
*/
///16进制颜色转为UIColor
///16 Decimal color turn to UIColor
#define HDColorFromRGB(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]
///16进制颜色转为UIColor,设置透明度
///16 Decimal color turn to UIColor with alpha
#define HDColorFromRGBA(rgbValue, _A) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:_A]
///通过数值转为UIColor
///Turn to UIColor by numerical value
#define HDColorWithRGB(_R,_G,_B) ((UIColor *)[UIColor colorWithRed:_R/255.0 green:_G/255.0 blue:_B/255.0 alpha:1.0])
///通过数值转为UIColor,设置透明度
///Turn to UIColor by numerical value with alpha
#define HDColorWithRGBA(_R,_G,_B,_A) ((UIColor *)[UIColor colorWithRed:_R/255.0 green:_G/255.0 blue:_B/255.0 alpha:_A])
/*
* Screen size
*/
//屏幕宽度
//ScreenWidth
#define HDScreenWidth [UIScreen mainScreen].bounds.size.width
//屏幕高度
//ScreenHeight
#define HDScreenHeight [UIScreen mainScreen].bounds.size.height
//状态栏当前高度
//Status bar current height
#define HD_Portrait_Status_Height [UIApplication sharedApplication].statusBarFrame.size.height //状态栏高度
// 判断是否是iPhone X
//Judge whether it is iPhone X
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
// 状态栏默认高度
//Default height of State Bar
#define HD_Default_Portrait_Status_Height (iPhoneX ? 44.f : 20.f)
// 导航栏默认高度
//Default height of the navigation bar
#define HD_Default_Portrait_NAVIGATION_BAR_HEIGHT (iPhoneX ? 88.f : 64.f)
// tabBar默认高度
//Default height of the tabBar
#define HD_Default_Portrait_TAB_BAR_HEIGHT (iPhoneX ? (49.f+34.f) : 49.f)
// home indicator
#define HD_Default_Portrait_HOME_INDICATOR_HEIGHT (iPhoneX ? 34.f : 0.f)
///将Data内容写入本地保存,重新命名,返回保存过的路径
// Write the Data content to local save, rename, and return the saved path
- (NSString *)saveData:(NSData *)data withFileName:(NSString *)fileName;
///在Document创建子文件夹并返回创建后的路径
//Create a subfolder in Document And return to the created path
- (NSString *)createDocumentSubFolderWithName:(NSString *)folderName;
///获取在Document文件夹里的或者子文件夹里面对应文件名的路径
//Get the path to the file name in the Document folder or in the subfolder
- (NSString *)getFilePathByfileName:(NSString *)fileName andSubfolderName:(NSString *)folderName;
///检查文件夹下是否有指定文件名文件
//Check if there is a specified file name file under the folder
- (BOOL)isExistFileWithfileName:(NSString *)fileName andSubfolderName:(NSString *)folderName;
///将UIImage内容写入本地保存,重新命名,返回保存过的路径
//Write the UIImage content to local save, rename, and return the saved path
- (NSString *)saveImage:(id)img withFileName:(NSString *)fileName;
///压缩一张图片并返回
//Compress a picture and return
- (UIImage *)compressImage:(UIImage *)img withQuality:(float)quality;
///图片压缩数组,返回压缩过的图片数组
//The picture compresses the array, returns the compressed array of pictures
- (NSArray *)compressImageArray:(NSArray *)imgArray withQuality:(float)quality;
/**
从视频中截取某一帧 Intercept a frame from the video
@param videoLocalPath 视频的本地地址 The local address of the video
@param frametime 截取第几秒的一帧 Intercepting a frame of a second
@return 返回截图 Return screenshot
*/
- (UIImage *)getVideoPreViewImageWithVideoLocalPath:(NSString *)videoLocalPath withFrametime:(float)frametime;
///获取本地视频的时长
//Get the length of the local video
- (NSUInteger)getDurationWithVideoLocalPath:(NSString *)videoLocalPath;
///获取视频的分辨率
//Obtaining the resolution of video
- (CGSize)getSizeOfVideoAsset:(AVAsset *)videoAsset;
///播放音效,是否震动
//Play sound effects, set up vibration
- (void)playEffectWithLocalFilePath:(NSString *)effectLocalFilePath withShake:(BOOL)shake;
/**
播放音乐 Play music
@param musicPath 音乐的地址,可以是本地地址,也可以是网络地址 The address of the music,available with localFilePath and network address
@param repeat 是否循环播放 should play music repeat
*/
- (void)playMusicWithMusicFilePath:(NSString *)musicPath withRepeat:(BOOL)repeat;
//停止音乐播放 Stop playing music
- (void)stopMusic;
///是否有麦克风权限
//Whether have the microphone permissions
- (HDPrivatePermissionStatus)getAVMediaTypeAudioPermissionStatus;
///是否有拍照权限
//Whether have the Camera permissions
- (HDPrivatePermissionStatus)getAVMediaTypeVideoPermissionStatus;
///是否有相册权限
////Whether have the Photo album permissions
- (HDPrivatePermissionStatus)getPhotoLibraryPermissionStatus;
///是否有定位权限
//Whether have the GPS permissions
- (HDPrivatePermissionStatus)getGPSLibraryPermissionStatus;
///是否有通知权限
///Whether there is notification authority
- (HDPrivatePermissionStatus)getNotificationPermissionStatus;
///申请定位权限
//Apply the GPS permissions
- (void)requestGPSLibraryPermissionWithType:(HDGPSPermissionType)GPSPermissionType;
///申请麦克风权限
//Apply the Microphone permissions
- (void)requestAVMediaTypeAudioPermission;
///申请拍照权限
//Apply the Camera permissions
- (void)requestAVMediaTypeVideoPermission;
///申请相册权限
//Apply the Photo album permissions
- (void)requestPhotoLibraryPermission;
///申请通知权限,iOS10.0以上才可以动态通知获取到的权限
///Application of notification authority,More than iOS10.0 can dynamically notify the acquired permissions
- (void)requestNotificationPermission;
///打开系统设置
//Open the system settings
- (void)openSystemSetting;
///软件版本
//the AppVersion
- (NSString *)getAppVersionStr;
///工程的build版本
//The build version of the project
- (NSString *)getAppBuildVersionStr;
///系统的ios版本
//The IOS version of the system
- (NSString *)getIOSVersionStr;
///获取系统语言
//Get the system language
- (NSString *)getIOSLanguageStr;
///是否是英文语言环境
//Is it an English language environment
- (BOOL)isEnglishLanguage;
///返回系统使用语言
//Return to the system usage language
- (HDSystemLanguage)getLanguage;
///软件Bundle Identifier
//Software Bundle Identifier
- (NSString *)getBundleIdentifier;
///模拟软件唯一标示,如果idfa可用使用idfa,否则则使用模拟的idfa
//The only indication of the simulation software.If IDFA is available, it will return to IDFA.Otherwise, use the analog IDFA
- (NSString *)getIphoneIdfa;
///获取具体的手机型号字符串
//Get a specific handset model string
- (NSString *)getDetailModelStr;
///是否是平板
//Whether is ipad
- (BOOL)isPad;
///是否是iphoneX
//Whether is iphoneX
- (BOOL)isPhoneX;
/**
打开appstore的预览下载页面。 Open the preview download page of Appstore
@param appleID 指定软件的appid,在itunes后台可以看到。 The appid of the specified software can be seen in the iTunes background
@param jumpStoreType 跳转到appstore样式类型。 Jump to Appstore style type
*/
- (void)openAppStoreWithAppleID:(NSString *)appleID withType:(HDJumpStoreType)jumpStoreType;
/**
好评弹窗 High praise window
@param appleID 评分的appid,在itunes后台可以看到。 The appid of the specified software can be seen in the iTunes background
如果选择了kHDScoreTypeInApp,或者kHDScoreTypeAuto在10.3版本情况下,appldid无效,自动弹出就是自己app的评分
@param scoreType 评分样式类型。 Jump to Appstore style type
*/
- (void)giveScoreWithAppleID:(NSString *)appleID withType:(HDScoreType)scoreType;
/**
字符串MD5加密 String MD5 encryption
@param string 要加密的字符串 String to be encrypted
@param lowercase 是否小写 Is it a lowercase
@return 加密过的字符串 Encrypted string
*/
- (NSString *)MD5EncryptWithString:(NSString *)string withLowercase:(BOOL)lowercase;
/**
字符串aes256加密 String aes256 encryption
@param plain 要加密的字符串 String to be encrypted
@param key 加密的key值 Encrypted key values
@return 加密后的字符串 Encrypted string
*/
- (NSString *)AES256EncryptWithPlainText:(NSString *)plain andKey:(NSString *)key;
/**
字符串aes256解密
@param ciphertexts 要解密的字符串 String aes256 Decrypted
@param key 加密的key值 Encrypted key values
@return 解密后的字符串 Decrypted string
*/
- (NSString *)AES256DecryptWithCiphertext:(NSString *)ciphertexts andKey:(NSString *)key;
///获取指定时间的时间戳
//Get the timestamp of the specified time
- (NSString *)getTimestampWithDate:(NSDate *)date;
///通过时间戳获取时间
///Get the Date by timestamp
- (NSDate *)getDateWithTimestamp:(NSString *)timestamp;
/**
通过时间戳获取时间字符串
Getting time through a timestamp
@param timestamp 时间戳
@param quickFormatType 快速格式化时间 Fast formatting time type
you define foramatter
@return 格式化过的时间
*/
- (NSString *)getTimeWithTimestamp:(NSString *)timestamp withQuickFormatType:(HDQuickFormatType)quickFormatType;
/**
通过时间戳获取时间字符串
Getting time through a timestamp
@param timestamp 时间戳
@param formatter 自己定义foramatter you define foramatter
@return 格式化过的时间
*/
- (NSString *)getTimeWithTimestamp:(NSString *)timestamp withCustomFormatter:(NSDateFormatter *)formatter;
/**
比较两个日期的先后顺序
Compare the order of the two dates
@param firstDay 第一个日期
@param secondDay 第二个日期
@param ignoreTime 是否忽略时间的比较 Whether or not to ignore the comparison of time
@return 第一个日期和第二个日期比较的结果 the comparison between the first date and the second date
NSOrderedAscending:第一个日期更早 The first date is earlier
NSOrderedSame:两个日期一样 Two dates are the same
NSOrderedDescending:第一个日期更晚 The first date is later
*/
- (NSComparisonResult)compareFirstDay:(NSDate *)firstDay withSecondDay:(NSDate *)secondDay withIgnoreTime:(BOOL)ignoreTime;
#pragma mark -
#pragma mark - 中国农历和公历转换、星座生肖
///通过时间获取中国农历的对象
//get Chinese lunar calendar by time
- (ChineseLunarCalendar *)getChineseLunarCalendarWithDate:(NSDate *)date;
///通过公历时间去创建中国农历的对象
//get the Chinese lunar calendar by the calendar time
- (ChineseLunarCalendar *)getChineseLunarCalendarWithYear:(int)year andMonth:(int)month andDay:(int)day;
///通过农历的年月日获取中国农历对象
//get Chinese lunar calendar by the lunar calendar
- (ChineseLunarCalendar *)getChineseLunarCalendarWithChineseLunarYear:(int)chineseLunaryear andChineseLunarMonth:(int)chineseLunarmonth andChineseLunarDay:(int)chineseLunarday andLeap:(BOOL)isleap;
///格式化农历的字符串
///Formatting the string of Chinese calendar
- (NSString *)getChineseLunarCalendarStrWithChineseLunarCalendar:(ChineseLunarCalendar *)chineseLunarCalendar withFormatType:(HDChineseLunarCalendarFormatType)chineseLunarCalendarFormatType;
///通过农历获取公历日期
///Get the date of the Gregorian calendar through the lunar calendar
- (NSDate *)getDateWithChineseLunarCalendar:(ChineseLunarCalendar *)chineseLunarCalendar;
///通过农历获取生肖
///Get the zodiac through the lunar calendar
- (HDChineseZodiac)getChineseZodiacWithYear:(int)year;
///通过日期获得星座
///Get the constellation by date
- (HDConstellation)getConstellationWithDate:(NSDate *)date;
不骄方能师人之长,而自成其学