Commit fdb2b0be authored by jzhang's avatar jzhang

三方库更新适配

parent 192d1ee6
This diff is collapsed.
This diff is collapsed.
......@@ -8,6 +8,14 @@
import Foundation
var NRIsTouch: Bool = false
extension AppDelegate:JPUSHRegisterDelegate{
func jpushNotificationCenter(_ center: UNUserNotificationCenter!, openSettingsFor notification: UNNotification!) {
}
func jpushNotificationAuthorization(_ status: JPAuthorizationStatus, withInfo info: [AnyHashable : Any]!) {
}
@available(iOS 10.0, *)
func jpushNotificationCenter(_ center: UNUserNotificationCenter!, willPresent notification: UNNotification!, withCompletionHandler completionHandler: ((Int) -> Void)!) {
let userInfo = notification.request.content.userInfo
......
......@@ -20,15 +20,7 @@ class BaseTableViewController: UITableViewController {
// MARK: - 生成随机字符串
open func randomMD5() -> String {
let identifier = CFUUIDCreate(nil)
let identifierString = CFUUIDCreateString(nil, identifier) as String
let cStr = identifierString.cString(using: .utf8)
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(cStr, CC_LONG(strlen(cStr)), &digest)
var output = String()
for i in digest {
output = output.appendingFormat("%02X", i)
}
var output = UUID().uuidString
return output;
}
......
//
// UIImage+Category.h
// GitHub
//
// Created by 曹云霄 on 2017/12/6.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (Category)
/**
* 对图片进行模糊
*
* @param image 要处理图片
* @param blur 模糊系数 (0.0-1.0)
*
* @return 处理后的图片
*/
+ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur;
@end
//
// UIImage+Category.m
// GitHub
//
// Created by 曹云霄 on 2017/12/6.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import "UIImage+Category.h"
#import <Accelerate/Accelerate.h>
@implementation UIImage (Category)
/**
* 对图片进行模糊
*
* @param image 要处理图片
* @param blur 模糊系数 (0.0-1.0)
*
* @return 处理后的图片
*/
+ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {
if (!image) {
return nil;
}
if ((blur < 0.0f) || (blur > 1.0f)) {
blur = 0.5f;
}
int boxSize = (int)(blur * 200);
boxSize -= (boxSize % 2) + 1;
CGImageRef img = image.CGImage;
vImage_Buffer inBuffer, outBuffer;
vImage_Error error;
void *pixelBuffer;
CGDataProviderRef inProvider = CGImageGetDataProvider(img);
CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
inBuffer.width = CGImageGetWidth(img);
inBuffer.height = CGImageGetHeight(img);
inBuffer.rowBytes = CGImageGetBytesPerRow(img);
inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img));
outBuffer.data = pixelBuffer;
outBuffer.width = CGImageGetWidth(img);
outBuffer.height = CGImageGetHeight(img);
outBuffer.rowBytes = CGImageGetBytesPerRow(img);
error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL,
0, 0, boxSize, boxSize, NULL,
kvImageEdgeExtend);
if (error) {
NSLog(@"error from convolution %ld", error);
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(
outBuffer.data,
outBuffer.width,
outBuffer.height,
8,
outBuffer.rowBytes,
colorSpace,
CGImageGetBitmapInfo(image.CGImage));
CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
UIImage *returnImage = [UIImage imageWithCGImage:imageRef];
//clean up
CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace);
free(pixelBuffer);
CFRelease(inBitmapData);
CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef);
return returnImage;
}
@end
//
// NSArray+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSArray (Category)
/**
* 防止数组越界
*
* @param index 下标
*
* @return 元素
*/
- (id)yx_objectAtIndex:(NSUInteger)index;
/**
* 读取Plist文件的
*
* @param plistName plist文件名字
*
* @return NSArray
*/
- (NSArray *)arrayFromPlistName:(NSString *)plistName;
@end
//
// NSArray+Category.m
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import "NSArray+Category.h"
@implementation NSArray (Category)
- (id)yx_objectAtIndex:(NSUInteger)index
{
if (index > self.count) {
return nil;
}else
{
return [self objectAtIndex:index];
}
}
- (NSArray *)arrayFromPlistName:(NSString *)plistName
{
NSString *path = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
return [NSArray arrayWithContentsOfFile:path];
}
@end
//
// NSBundle+Category.h
// YXKit
//
// Created by 曹云霄 on 2017/1/22.
// Copyright © 2017年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSBundle (Category)
/**
获取App icon
@return 图片路径
*/
- (NSString *)appIconPath;
/**
获取App icon
@return 图片
*/
- (UIImage *)appIcon;
@end
//
// NSBundle+Category.m
// YXKit
//
// Created by 曹云霄 on 2017/1/22.
// Copyright © 2017年 caoyunxiao. All rights reserved.
//
#import "NSBundle+Category.h"
@implementation NSBundle (Category)
/**
* 获取icon的路径
*
* @return 获得的路径
*/
- (NSString*)appIconPath {
NSString* iconFilename = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"] ;
NSString* iconBasename = [iconFilename stringByDeletingPathExtension] ;
NSString* iconExtension = [iconFilename pathExtension] ;
return [[NSBundle mainBundle] pathForResource:iconBasename
ofType:iconExtension] ;
}
/**
* 获取appIcon
*
* @return 得到的iconImage
*/
- (UIImage*)appIcon {
UIImage*appIcon = [[UIImage alloc] initWithContentsOfFile:[self appIconPath]] ;
return appIcon;
}
@end
//
// NSDate+Category.h
// YXKit
//
// Created by 曹云霄 on 2017/1/22.
// Copyright © 2017年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDate (Category)
/**
* 获取日、月、年、小时、分钟、秒
*/
- (NSUInteger)day;
- (NSUInteger)month;
- (NSUInteger)year;
- (NSUInteger)hour;
- (NSUInteger)minute;
- (NSUInteger)second;
+ (NSUInteger)day:(NSDate *)date;
+ (NSUInteger)month:(NSDate *)date;
+ (NSUInteger)year:(NSDate *)date;
+ (NSUInteger)hour:(NSDate *)date;
+ (NSUInteger)minute:(NSDate *)date;
+ (NSUInteger)second:(NSDate *)date;
/**
* 获取一年中的总天数
*/
- (NSUInteger)daysInYear;
+ (NSUInteger)daysInYear:(NSDate *)date;
/**
* 判断是否是润年
* @return YES表示润年,NO表示平年
*/
- (BOOL)isLeapYear;
+ (BOOL)isLeapYear:(NSDate *)date;
/**
* 获取该日期是该年的第几周
*/
- (NSUInteger)weekOfYear;
+ (NSUInteger)weekOfYear:(NSDate *)date;
/**
* 获取格式化为YYYY-MM-dd格式的日期字符串
*/
- (NSString *)formatYMD;
+ (NSString *)formatYMD:(NSDate *)date;
/**
* 返回当前月一共有几周(可能为4,5,6)
*/
- (NSUInteger)weeksOfMonth;
+ (NSUInteger)weeksOfMonth:(NSDate *)date;
/**
* 获取该月的第一天的日期
*/
- (NSDate *)begindayOfMonth;
+ (NSDate *)begindayOfMonth:(NSDate *)date;
/**
* 获取该月的最后一天的日期
*/
- (NSDate *)lastdayOfMonth;
+ (NSDate *)lastdayOfMonth:(NSDate *)date;
/**
* 返回day天后的日期(若day为负数,则为|day|天前的日期)
*/
- (NSDate *)dateAfterDay:(NSUInteger)day;
+ (NSDate *)dateAfterDate:(NSDate *)date day:(NSInteger)day;
/**
* 返回day月后的日期(若month为负数,则为|month|月前的日期)
*/
- (NSDate *)dateAfterMonth:(NSUInteger)month;
+ (NSDate *)dateAfterDate:(NSDate *)date month:(NSInteger)month;
/**
* 返回numYears年后的日期
*/
- (NSDate *)offsetYears:(int)numYears;
+ (NSDate *)offsetYears:(int)numYears fromDate:(NSDate *)fromDate;
/**
* 返回numMonths月后的日期
*/
- (NSDate *)offsetMonths:(int)numMonths;
+ (NSDate *)offsetMonths:(int)numMonths fromDate:(NSDate *)fromDate;
/**
* 返回numDays天后的日期
*/
- (NSDate *)offsetDays:(int)numDays;
+ (NSDate *)offsetDays:(int)numDays fromDate:(NSDate *)fromDate;
/**
* 返回numHours小时后的日期
*/
- (NSDate *)offsetHours:(int)hours;
+ (NSDate *)offsetHours:(int)numHours fromDate:(NSDate *)fromDate;
/**
* 距离该日期前几天
*/
- (NSUInteger)daysAgo;
+ (NSUInteger)daysAgo:(NSDate *)date;
/**
* 获取星期几
*/
- (NSInteger)weekday;
+ (NSInteger)weekday:(NSDate *)date;
/**
* 获取星期几(名称)
*/
- (NSString *)dayFromWeekday;
+ (NSString *)dayFromWeekday:(NSDate *)date;
/**
* 日期是否相等
*/
- (BOOL)isSameDay:(NSDate *)anotherDate;
/**
* 是否是今天
*/
- (BOOL)isToday;
/**
* 增加
*/
- (NSDate *)dateByAddingDays:(NSUInteger)days;
/**
* 获得NSString的月份
*/
+ (NSString *)monthWithMonthNumber:(NSInteger)month;
/**
* 根据日期返回字符串
*/
+ (NSString *)stringWithDate:(NSDate *)date format:(NSString *)format;
- (NSString *)stringWithFormat:(NSString *)format;
+ (NSDate *)dateWithString:(NSString *)string format:(NSString *)format;
/**
* 获取指定月份的天数
*/
- (NSUInteger)daysInMonth:(NSUInteger)month;
+ (NSUInteger)daysInMonth:(NSDate *)date month:(NSUInteger)month;
/**
* 获取当前月份的天数
*/
- (NSUInteger)daysInMonth;
+ (NSUInteger)daysInMonth:(NSDate *)date;
/**
* 返回x分钟前/x小时前/昨天/x天前/x个月前/x年前
*/
- (NSString *)timeInfo;
+ (NSString *)timeInfoWithDate:(NSDate *)date;
+ (NSString *)timeInfoWithDateString:(NSString *)dateString;
// yyyy-MM-dd HH:mm:ss
- (NSString *)httpParameterString;
// yyyy-MM-dd
- (NSString *)yearMonthDayString;
/** yyyy-MM */
- (NSString *)yearMonthString;
- (NSString *)yearString;
- (NSString *)monthString;
- (NSString *)dayString;
@end
This diff is collapsed.
//
// NSDictionary+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDictionary (Category)
/**
* 转JSON字符串
*
* @return JSON字符串
*/
- (NSString *)toJSONString;
@end
//
// NSDictionary+Category.m
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import "NSDictionary+Category.h"
@implementation NSDictionary (Category)
- (NSString *)toJSONString
{
NSData *paramsJSONData = [NSJSONSerialization dataWithJSONObject:self options:0 error:nil];
return [[NSString alloc] initWithData:paramsJSONData encoding:NSUTF8StringEncoding];
}
@end
//
// NSObject+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSObject (Category)
//app版本号
+ (NSString *)version;
//app build号
+ (NSInteger)build;
//app id
+ (NSString *)identifier;
//当前语言
+ (NSString *)currentLanguage;
//类名
- (NSString *)className;
+ (NSString *)className;
//父类名称
- (NSString *)superClassName;
+ (NSString *)superClassName;
/**
* 字典给模型赋值
* 用字典给一个类里的属性赋值,如有值是类中不存在的,常规情况下程序会崩溃
* 根据本类的属性有选择的拿字典中的key value,如果本类的属性包含字典的key,则把key的value赋值给这个属性
*/
-(void)modelWithDictionary:(NSDictionary *)dict;
/***************************************Runtime***********************************************/
/** 属性列表 */
- (NSArray *)propertiesInfo;
+ (NSArray *)propertiesInfo;
/** 格式化之后的属性列表 */
+ (NSArray *)propertiesWithCodeFormat;
/** 成员变量列表 */
- (NSArray *)ivarInfo;
+ (NSArray *)ivarInfo;
/** 对象方法列表 */
-(NSArray*)instanceMethodList;
+(NSArray*)instanceMethodList;
/** 类方法列表 */
+(NSArray*)classMethodList;
/** 协议列表 */
-(NSDictionary *)protocolList;
+(NSDictionary *)protocolList;
/** 交换实例方法 */
+ (void)SwizzlingInstanceMethodWithOldMethod:(SEL)oldMethod newMethod:(SEL)newMethod;
/** 交换类方法 */
+ (void)SwizzlingClassMethodWithOldMethod:(SEL)oldMethod newMethod:(SEL)newMethod;
/** 添加方法 */
+ (void)addMethodWithSEL:(SEL)methodSEL methodIMP:(SEL)methodIMP;
@end
This diff is collapsed.
//
// NSString+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSString (Category)
/**
* 判断字符串是否为空
*/
- (BOOL)empty;
/**
* 判断字符串是否为整数
*/
- (BOOL)isInteger;
/**
* 判断字符串是否为浮点数
*/
- (BOOL)isFloat;
/**
* 判断字符串是否含有特殊字符
*/
- (BOOL)isHasSpecialcharacters;
/**
* 判断字符串是否含有数字
*/
- (BOOL)isHasNumder;
/**
* 毫秒级时间戳转日期
*/
- (NSDate *)dateValueWithMillisecondsSince1970;
/**
* 秒级时间戳转日期
*/
- (NSDate *)dateValueWithTimeIntervalSince1970;
/**
* 计算string字数
*/
- (NSInteger)stringLength;
/**
* 检测是否含有某个字符
*/
- (BOOL)containString:(NSString *)string;
/**
* 是否含有汉字
*/
- (BOOL)containsChineseCharacter;
/**
* 计算字符串高度
*/
- (CGSize)heightWithWidth:(CGFloat)width andFont:(CGFloat)font;
/**
* 计算字符串宽度
*/
- (CGSize)widthWithHeight:(CGFloat)height andFont:(CGFloat)font;
/**
* 邮箱地址有效性
*/
- (BOOL)isEmail;
/**
* url有效性
*/
- (BOOL)isUrl;
/**
* 电话号码有效性
*/
- (BOOL)isTelephone;
/**
* 邮政编码有效性
*/
- (BOOL)isValidZipcode;
/**
* 由英文、字母或数字组成 6-18位 密码有效性
*/
- (BOOL)isPassword;
/**
* 数字有效性
*/
- (BOOL)isNumbers;
/**
* 匹配英文字母
*/
- (BOOL)isLetter;
/**
* 匹配大写英文字母
*/
- (BOOL)isCapitalLetter;
/**
* 匹配小写英文字母
*/
- (BOOL)isSmallLetter;
/**
* 日期随机数
*/
+ (NSString*)getTimeAndRandomString;
/**
* 将得到的json的回车替换转义字符
*/
- (NSString *)changeJsonEnter;
/**
* email 转换为 312******@qq.com 形式
*/
- (NSString *)emailChangeToPrivacy;
/**
* 判断字符串时候含有Emoji
*/
- (BOOL)isIncludingEmoji;
/**
* 移除掉字符串中得Emoji
*/
- (instancetype)removedEmojiString;
/**
* md5加密(32位 常规)
*
* @return 加密后的字符串
*/
- (NSString *)md5;
/**
* md5加密(16位)
*
* @return 加密后的字符串
*/
- (NSString *)md5_16;
/**
* sha1加密
*
* @return 加密后的字符串
*/
- (NSString *)sha1;
/**
* sha256加密
*
* @return 加密后的字符串
*/
- (NSString *)sha256;
/**
* sha384加密
*
* @return 加密后的字符串
*/
- (NSString *)sha384;
/**
* sha512加密
*
* @return 加密后的字符串
*/
- (NSString*)sha512;
/**
格式化字符串
*/
- (NSString *)formatString;
@end
This diff is collapsed.
//
// UIBarButtonItem+Category.h
// YXKit
//
// Created by 曹云霄 on 2017/1/22.
// Copyright © 2017年 caoyunxiao. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UIButton+Category.h"
@interface UIBarButtonItem (Category)
/**
添加LeftBarButtonItem
@param title 文字
@param imageName 图片
@param action 事件
*/
+ (instancetype)addCustomLeftBarButtonItem:(NSString *)title withTarget:(id)target withImageNamed:(NSString *)imageName withAction:(SEL)action;
/**
添加RightBarButtonItem
@param title 文字
@param imageName 图片
@param action 事件
*/
+ (instancetype)addCustomRightBarButtonItem:(NSString *)title withTarget:(id)target withImageNamed:(NSString *)imageName withAction:(SEL)action;
@end
//
// UIBarButtonItem+Category.m
// YXKit
//
// Created by 曹云霄 on 2017/1/22.
// Copyright © 2017年 caoyunxiao. All rights reserved.
//
#import "UIBarButtonItem+Category.h"
@implementation UIBarButtonItem (Category)
/**
添加LeftBarButtonItem
@param title 文字
@param imageName 图片
@param action 事件
*/
+ (instancetype)addCustomLeftBarButtonItem:(NSString *)title withTarget:(id)target withImageNamed:(NSString *)imageName withAction:(SEL)action
{
//纯图片
if ([[self class] isBlankString:title] && ![[self class] isBlankString:imageName]) {
return [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStyleDone target:target action:action];
//纯文字
}else if (![[self class] isBlankString:title] && [[self class] isBlankString:imageName]) {
return [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleDone target:target action:action];
//图片、文字
}else if (![[self class] isBlankString:title] && ![[self class] isBlankString:imageName]) {
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
[leftButton setTitle:title forState:UIControlStateNormal];
[leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[leftButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[leftButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
[leftButton horizontalCenterImageAndTitle:10.0f];
leftButton.frame = CGRectMake(0, 0, 100, 45);
return [[UIBarButtonItem alloc] initWithCustomView:leftButton];
}
return [[UIBarButtonItem alloc] init];
}
/**
添加RightBarButtonItem
@param title 文字
@param imageName 图片
@param action 事件
*/
+ (instancetype)addCustomRightBarButtonItem:(NSString *)title withTarget:(id)target withImageNamed:(NSString *)imageName withAction:(SEL)action
{
//纯图片
if ([[self class] isBlankString:title] && ![[self class] isBlankString:imageName]) {
return [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStyleDone target:target action:action];
//纯文字
}else if (![[self class] isBlankString:title] && [[self class] isBlankString:imageName]) {
return [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleDone target:target action:action];
//图片、文字
}else if (![[self class] isBlankString:title] && ![[self class] isBlankString:imageName]) {
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
[rightButton setTitle:title forState:UIControlStateNormal];
[rightButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[rightButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
[rightButton horizontalCenterImageAndTitle:10.0f];
rightButton.frame = CGRectMake(0, 0, 100, 45);
return [[UIBarButtonItem alloc] initWithCustomView:rightButton];
}
return [[UIBarButtonItem alloc] init];
}
#pragma mark - 判断字符串是否为空
+ (BOOL)isBlankString:(NSString *)string
{
if (string == nil || string == NULL) {
return YES;
}
if ([string isKindOfClass:[NSNull class]]) {
return YES;
}
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
return YES;
}
return NO;
}
@end
//
// UIButton+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/23.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIButton (Category)
/*****************************跳转图片和文字的位置*****************************/
//上下居中,图片在上,文字在下
- (void)verticalCenterImageAndTitle:(CGFloat)spacing;
//左右居中,文字在左,图片在右
- (void)horizontalCenterTitleAndImage:(CGFloat)spacing;
//左右居中,图片在左,文字在右
- (void)horizontalCenterImageAndTitle:(CGFloat)spacing;
//文字居中,图片在左边
- (void)horizontalCenterTitleAndImageLeft:(CGFloat)spacing;
//文字居中,图片在右边
- (void)horizontalCenterTitleAndImageRight:(CGFloat)spacing;
/**
* 倒计时按钮
*
* @param timeLine 倒计时总时间
* @param title 还没倒计时的title
* @param subTitle 倒计时中的子名字,如时、分
* @param mColor 还没倒计时的颜色
* @param color 倒计时中的颜色
*/
- (void)startWithTime:(NSInteger)timeLine title:(NSString *)title countDownTitle:(NSString *)subTitle mainColor:(UIColor *)mColor countColor:(UIColor *)color;
/**
快速创建按钮
@param title 标题
@param backColor 背景色
@param backImageName 背景图片名称
@param color 文字颜色
@param fontSize 字体大小
@param frame frame
@param cornerRadius 圆角
@return UIButton
*/
+(instancetype)buttonWithTitle:(NSString *)title backColor:(UIColor *)backColor backImageName:(NSString *)backImageName titleColor:(UIColor *)color fontSize:(int)fontSize frame:(CGRect)frame cornerRadius:(CGFloat)cornerRadius;
/** 显示菊花 */
- (void)showIndicator;
/** 隐藏菊花 */
- (void)hideIndicator;
@end
//
// UIButton+Category.m
// YXKit
//
// Created by 曹云霄 on 16/9/23.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import "UIButton+Category.h"
#import <objc/runtime.h>
static NSString *const IndicatorViewKey = @"indicatorView";
static NSString *const ButtonTextObjectKey = @"buttonTextObject";
NSString const *UIButton_badgeKey = @"UIButton_badgeKey";
NSString const *UIButton_badgeBGColorKey = @"UIButton_badgeBGColorKey";
NSString const *UIButton_badgeTextColorKey = @"UIButton_badgeTextColorKey";
NSString const *UIButton_badgeFontKey = @"UIButton_badgeFontKey";
NSString const *UIButton_badgePaddingKey = @"UIButton_badgePaddingKey";
NSString const *UIButton_badgeMinSizeKey = @"UIButton_badgeMinSizeKey";
NSString const *UIButton_badgeOriginXKey = @"UIButton_badgeOriginXKey";
NSString const *UIButton_badgeOriginYKey = @"UIButton_badgeOriginYKey";
NSString const *UIButton_shouldHideBadgeAtZeroKey = @"UIButton_shouldHideBadgeAtZeroKey";
NSString const *UIButton_shouldAnimateBadgeKey = @"UIButton_shouldAnimateBadgeKey";
NSString const *UIButton_badgeValueKey = @"UIButton_badgeValueKey";
@implementation UIButton (Category)
- (void)startWithTime:(NSInteger)timeLine title:(NSString *)title countDownTitle:(NSString *)subTitle mainColor:(UIColor *)mColor countColor:(UIColor *)color {
__weak typeof(self) weakSelf = self;
//倒计时时间
__block NSInteger timeOut = timeLine;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
//每秒执行一次
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0 * NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(_timer, ^{
//倒计时结束,关闭
if (timeOut <= 0) {
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.backgroundColor = mColor;
[weakSelf setTitle:title forState:UIControlStateNormal];
weakSelf.userInteractionEnabled = YES;
});
} else {
int allTime = (int)timeLine + 1;
int seconds = timeOut % allTime;
NSString *timeStr = [NSString stringWithFormat:@"%0.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.backgroundColor = color;
[weakSelf setTitle:[NSString stringWithFormat:@"%@%@",timeStr,subTitle] forState:UIControlStateNormal];
weakSelf.userInteractionEnabled = NO;
});
timeOut--;
}
});
dispatch_resume(_timer);
}
/**
快速创建按钮
*/
+(instancetype)buttonWithTitle:(NSString *)title backColor:(UIColor *)backColor backImageName:(NSString *)backImageName titleColor:(UIColor *)color fontSize:(int)fontSize frame:(CGRect)frame cornerRadius:(CGFloat)cornerRadius {
UIButton *button = [UIButton new];
[button setTitle:title forState:UIControlStateNormal];
[button setBackgroundColor:backColor];
[button setBackgroundImage:[UIImage imageNamed:backImageName] forState:UIControlStateNormal];
[button setTitleColor:color forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
[button sizeToFit];
button.frame=frame;
button.layer.cornerRadius=cornerRadius;
button.clipsToBounds=YES;
return button;
}
/**
显示菊花
*/
- (void)showIndicator
{
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
[indicator startAnimating];
NSString *currentButtonText = self.titleLabel.text;
objc_setAssociatedObject(self, &ButtonTextObjectKey, currentButtonText, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, &IndicatorViewKey, indicator, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
self.enabled = NO;
[self setTitle:@"" forState:UIControlStateNormal];
[self addSubview:indicator];
}
/**
隐藏菊花
*/
- (void)hideIndicator
{
NSString *currentButtonText = (NSString *)objc_getAssociatedObject(self, &ButtonTextObjectKey);
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)objc_getAssociatedObject(self, &IndicatorViewKey);
self.enabled = YES;
[indicator removeFromSuperview];
[self setTitle:currentButtonText forState:UIControlStateNormal];
}
- (void)verticalCenterImageAndTitle:(CGFloat)spacing
{
CGSize imageSize = self.imageView.frame.size;
CGSize titleSize = self.titleLabel.frame.size;
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, - (imageSize.height + spacing/2), 0.0);
titleSize = self.titleLabel.frame.size;
self.imageEdgeInsets = UIEdgeInsetsMake(- (titleSize.height + spacing/2), 0.0, 0.0, - titleSize.width);
}
- (void)horizontalCenterTitleAndImage:(CGFloat)spacing
{
CGSize imageSize = self.imageView.frame.size;
CGSize titleSize = self.titleLabel.frame.size;
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, 0.0, imageSize.width + spacing/2);
titleSize = self.titleLabel.frame.size;
self.imageEdgeInsets = UIEdgeInsetsMake(0.0, titleSize.width + spacing/2, 0.0, - titleSize.width);
}
- (void)horizontalCenterImageAndTitle:(CGFloat)spacing;
{
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, 0.0, - spacing/2);
self.imageEdgeInsets = UIEdgeInsetsMake(0.0, - spacing/2, 0.0, 0.0);
}
- (void)horizontalCenterTitleAndImageLeft:(CGFloat)spacing
{
self.imageEdgeInsets = UIEdgeInsetsMake(0.0, - spacing, 0.0, 0.0);
}
- (void)horizontalCenterTitleAndImageRight:(CGFloat)spacing
{
CGSize imageSize = self.imageView.frame.size;
CGSize titleSize = self.titleLabel.frame.size;
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, 0.0, 0.0);
titleSize = self.titleLabel.frame.size;
self.imageEdgeInsets = UIEdgeInsetsMake(0.0, titleSize.width + imageSize.width + spacing, 0.0, - titleSize.width);
}
@end
//
// UIColor+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (Category)
/**
* RGB颜色
*
* @param red 红色比例
* @param green 绿色比例
* @param blue 蓝色比例
* @param alpha 透明度
*
* @return UIColor
*/
+ (UIColor *)colorWithR:(CGFloat)red g:(CGFloat)green b:(CGFloat)blue a:(CGFloat)alpha;
/**
* 随机颜色
*/
+ (UIColor *)randomColor;
@end
//
// UIColor+Category.m
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import "UIColor+Category.h"
@implementation UIColor (Category)
+ (UIColor *)colorWithR:(CGFloat)red g:(CGFloat)green b:(CGFloat)blue a:(CGFloat)alpha {
return [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha];
}
+ (instancetype)randomColor {
return [UIColor colorWithRed:arc4random_uniform(256) green:arc4random_uniform(256) blue:arc4random_uniform(256)];
}
+ (instancetype)colorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue {
return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0];
}
@end
//
// UIDevice+Category.h
// YXKitDemo
//
// Created by 曹云霄 on 2017/6/30.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIDevice (Category)
/** mac地址 */
+ (NSString *)macAddress;
/** ram的size */
+ (NSUInteger)ramSize;
/** cpu个数 */
+ (NSUInteger)cpuNumber;
/** 系统的版本号 */
+ (NSString *)systemVersion;
/** 是否有摄像头 */
+ (BOOL)hasCamera;
/** 获取手机内存总量, 返回的是字节数 */
+ (NSUInteger)totalMemoryBytes;
/** 获取手机可用内存, 返回的是字节数 */
+ (NSUInteger)freeMemoryBytes;
/** 获取手机硬盘总空间, 返回的是字节数 */
+ (NSUInteger)totalDiskSpaceBytes;
/** 获取手机硬盘空闲空间, 返回的是字节数 */
+ (NSUInteger)freeDiskSpaceBytes;
@end
//
// UIDevice+Category.m
// YXKitDemo
//
// Created by 曹云霄 on 2017/6/30.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import "UIDevice+Category.h"
#include <sys/types.h>
#include <sys/sysctl.h>
#import <sys/socket.h>
#import <sys/param.h>
#import <sys/mount.h>
#import <sys/stat.h>
#import <sys/utsname.h>
#import <net/if.h>
#import <net/if_dl.h>
#import <mach/mach.h>
#import <mach/mach_host.h>
#import <mach/processor_info.h>
@implementation UIDevice (Category)
+ (NSString *)macAddress {
int mib[6];
size_t len;
char *buf;
unsigned char *ptr;
struct if_msghdr *ifm;
struct sockaddr_dl *sdl;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
if((mib[5] = if_nametoindex("en0")) == 0) {
printf("Error: if_nametoindex error\n");
return NULL;
}
if(sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 1\n");
return NULL;
}
if((buf = malloc(len)) == NULL) {
printf("Could not allocate memory. Rrror!\n");
return NULL;
}
if(sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 2");
return NULL;
}
ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);
ptr = (unsigned char *)LLADDR(sdl);
NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
*ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
free(buf);
return outstring;
}
+ (NSString *)systemVersion
{
return [[UIDevice currentDevice] systemVersion];
}
+ (BOOL)hasCamera
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
+ (NSUInteger)getSysInfo:(uint)typeSpecifier
{
size_t size = sizeof(int);
int result;
int mib[2] = {CTL_HW, typeSpecifier};
sysctl(mib, 2, &result, &size, NULL, 0);
return (NSUInteger)result;
}
+ (NSUInteger)ramSize {
return [self getSysInfo:HW_MEMSIZE];
}
+ (NSUInteger)cpuNumber {
return [self getSysInfo:HW_NCPU];
}
+ (NSUInteger)totalMemoryBytes
{
return [self getSysInfo:HW_PHYSMEM];
}
+ (NSUInteger)freeMemoryBytes
{
mach_port_t host_port = mach_host_self();
mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
vm_size_t pagesize;
vm_statistics_data_t vm_stat;
host_page_size(host_port, &pagesize);
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
return 0;
}
unsigned long mem_free = vm_stat.free_count * pagesize;
return mem_free;
}
+ (NSUInteger)freeDiskSpaceBytes
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
NSNumber *number = attributes[NSFileSystemFreeSize];
return [number unsignedIntegerValue];
}
+ (NSUInteger)totalDiskSpaceBytes
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
NSNumber *number = attributes[NSFileSystemSize];
return [number unsignedIntegerValue];
}
@end
//
// UIImage+Category.h
// YXKitDemo
//
// Created by 曹云霄 on 2017/6/30.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (Category)
//截屏
+(instancetype)snapshotCurrentScreen;
//图片模糊效果
- (UIImage *)blur;
//高效添加圆角图片
- (UIImage*)imageAddCornerWithRadius:(CGFloat)radius andSize:(CGSize)size;
/** 压缩图片 最大字节大小为maxLength */
- (NSData *)compressWithMaxLength:(NSInteger)maxLength;
/** 纠正图片的方向 */
- (UIImage *)fixOrientation;
/** 按给定的方向旋转图片 */
- (UIImage*)rotate:(UIImageOrientation)orient;
/** 压缩图片至指定尺寸 */
- (UIImage *)rescaleImageToSize:(CGSize)size;
/** 压缩图片至指定像素 */
- (UIImage *)rescaleImageToPX:(CGFloat )toPX;
/**
加载gif
@param name gif图片名称
*/
+ (UIImage *)animatedGIFNamed:(NSString *)name;
/**
* 给图片加水印图片
*
* @param image 水印图片
* @param imgRect 水印图片所在位置,大小
* @param alpha 水印图片的透明度,0~1之间,透明度太大会完全遮盖被加水印图片的那一部分
*
* @return 加完水印的图片
*/
- (UIImage*)imageWaterMarkWithImage:(UIImage *)image imageRect:(CGRect)imgRect alpha:(CGFloat)alpha;
/**
* 给图片加文字水印
*
* @param str 水印文字
* @param strPoint 文字所在的位置大小
* @param attri 文字的相关属性,自行设置
*
* @return 加完水印文字的图片
*/
- (UIImage*)imageWaterMarkWithString:(NSString*)str point:(CGPoint)strPoint attribute:(NSDictionary*)attri;
/**
* 返回加水印文字和图片的图片
*
* @param str 水印文字
* @param strPoint 文字(0,0)点所在位置
* @param attri 文字属性
* @param image 水印图片
* @param imgRect 图片(0,0)点所在位置
* @param alpha 透明度
*
* @return 加完水印的图片
*/
- (UIImage*)imageWaterMarkWithString:(NSString*)str point:(CGPoint)strPoint attribute:(NSDictionary *)attri image:(UIImage *)image imageRect:(CGRect)imgRect alpha:(CGFloat)alpha;
@end
This diff is collapsed.
//
// UITableView+Category.h
// YXKitDemo
//
// Created by 曹云霄 on 2017/6/30.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITableView (Category)
/**
* 更新回调
*/
- (void)updateWithBlock:(void (^)(UITableView *tableView))block;
/**
* 滚动
*/
- (void)scrollToRow:(NSUInteger)row inSection:(NSUInteger)section atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
/**
* 插入
*/
- (void)insertRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 刷新
*/
- (void)reloadRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 删除
*/
- (void)deleteRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 插入
*/
- (void)insertRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 刷新indexPath
*/
- (void)reloadRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 删除indexPath
*/
- (void)deleteRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 插入section
*/
- (void)insertSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 删除section
*/
- (void)deleteSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 刷新section
*/
- (void)reloadSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation;
/**
* 取消所有选中
*/
- (void)clearSelectedRowsAnimated:(BOOL)animated;
@end
//
// UITableView+Category.m
// YXKitDemo
//
// Created by 曹云霄 on 2017/6/30.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import "UITableView+Category.h"
@implementation UITableView (Category)
- (void)updateWithBlock:(void (^)(UITableView *tableView))block {
[self beginUpdates];
block(self);
[self endUpdates];
}
- (void)scrollToRow:(NSUInteger)row inSection:(NSUInteger)section atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[self scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
}
- (void)insertRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation {
[self insertRowsAtIndexPaths:@[indexPath] withRowAnimation:animation];
}
- (void)insertRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation {
NSIndexPath *toInsert = [NSIndexPath indexPathForRow:row inSection:section];
[self insertRowAtIndexPath:toInsert withRowAnimation:animation];
}
- (void)reloadRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation {
[self reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:animation];
}
- (void)reloadRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation {
NSIndexPath *toReload = [NSIndexPath indexPathForRow:row inSection:section];
[self reloadRowAtIndexPath:toReload withRowAnimation:animation];
}
- (void)deleteRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation {
[self deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:animation];
}
- (void)deleteRow:(NSUInteger)row inSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation {
NSIndexPath *toDelete = [NSIndexPath indexPathForRow:row inSection:section];
[self deleteRowAtIndexPath:toDelete withRowAnimation:animation];
}
- (void)insertSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation {
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section];
[self insertSections:sections withRowAnimation:animation];
}
- (void)deleteSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation {
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section];
[self deleteSections:sections withRowAnimation:animation];
}
- (void)reloadSection:(NSUInteger)section withRowAnimation:(UITableViewRowAnimation)animation {
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:section];
[self reloadSections:indexSet withRowAnimation:animation];
}
- (void)clearSelectedRowsAnimated:(BOOL)animated {
NSArray *indexs = [self indexPathsForSelectedRows];
[indexs enumerateObjectsUsingBlock:^(NSIndexPath* path, NSUInteger idx, BOOL *stop) {
[self deselectRowAtIndexPath:path animated:animated];
}];
}
@end
//
// UIView+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UIView (Category)
/**
* UIView/frame信息
*/
@property (assign) CGFloat x;
@property (assign) CGFloat y;
@property (assign) CGFloat width;
@property (assign) CGFloat height;
@property (assign) CGSize size;
@property (assign) CGPoint origin;
@property (assign) CGFloat left;
@property (assign) CGFloat right;
@property (assign) CGFloat top;
@property (assign) CGFloat bottom;
/**
* 添加圆角
*
* @param coefficient 圆角大小
*/
- (void)addCorner:(CGFloat)coefficient;
/**
* 添加边框
*
* @param lineWidth 宽度
* @param color 颜色
*/
- (void)addBorderWidth:(CGFloat)lineWidth lineColor:(UIColor *)color;
/**
* 设置width
*
* @param width 宽度
*/
- (void)setWidth:(CGFloat)width;
/**
* 设置height
*
* @param height 高度
*/
- (void)setHeight:(CGFloat)height;
/**
* 删除所有子视图
*/
- (void)removeAllSubViews;
/**
* 通过对象来删除子视图
*
* @param aClass 对象
*/
- (void)removeSubViewWithClass:(Class)aClass;
/**
* 通过Tag值来删除子视图
*
* @param tag tag值
*/
- (void)removeSubViewWithTag:(NSInteger)tag;
/**
* 摇动动画
*/
- (void)shakeAnimation;
/**
* 弹起动画
*/
- (void)springingAnimation;
@end
//
// UIView+Category.m
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import "UIView+Category.h"
@implementation UIView (Category)
- (CGFloat) x {
return self.frame.origin.x;
}
- (void) setX:(CGFloat)x {
CGRect nframe = self.frame;
nframe.origin.x = x;
self.frame = nframe;
}
- (CGFloat) y {
return self.frame.origin.y;
}
- (void) setY:(CGFloat)y {
CGRect nframe = self.frame;
nframe.origin.y = y;
self.frame = nframe;
}
- (CGFloat) width {
return self.frame.size.width;
}
- (void) setWidth:(CGFloat)width {
CGRect nframe = self.frame;
nframe.size.width = width;
self.frame = nframe;
}
- (CGFloat) height {
return self.frame.size.height;
}
- (void) setHeight:(CGFloat)height {
CGRect nframe = self.frame;
nframe.size.height = height;
self.frame = nframe;
}
// Retrieve and set the origin, size
- (CGPoint) origin {
return self.frame.origin;
}
- (void) setOrigin:(CGPoint)aPoint {
CGRect nframe = self.frame;
nframe.origin = aPoint;
self.frame = nframe;
}
- (CGSize) size {
return self.frame.size;
}
- (void) setSize:(CGSize)aSize {
CGRect nframe = self.frame;
nframe.size = aSize;
self.frame = nframe;
}
- (CGFloat) left {
return self.x;
}
- (void) setLeft:(CGFloat)left {
self.x = left;
}
- (CGFloat) right {
return CGRectGetMaxX(self.frame);
}
- (void) setRight:(CGFloat)right {
self.x = right - self.width;
}
- (CGFloat) top {
return self.y;
}
- (void) setTop:(CGFloat)top {
self.y = top;
}
- (CGFloat) bottom {
return CGRectGetMaxY(self.frame);
}
- (void) setBottom:(CGFloat)bottom {
self.y = bottom - self.height;
}
- (void)addCorner:(CGFloat)coefficient
{
self.layer.cornerRadius = coefficient;
self.layer.masksToBounds = YES;
}
- (void)addBorderWidth:(CGFloat)lineWidth lineColor:(UIColor *)color
{
self.layer.borderWidth = lineWidth;
self.layer.borderColor = color.CGColor;
}
- (id)viewWithClass:(Class)aClass {
__block id machedView = nil;
[self.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:aClass]) {
machedView = obj;
*stop = YES;
}
}];
return machedView;
}
- (void)removeSubViewWithClass:(Class)aClass {
[[self viewWithClass:aClass] removeFromSuperview];
}
- (void)removeSubViewWithTag:(NSInteger)tag {
[[self viewWithTag:tag] removeFromSuperview];
}
- (void)removeAllSubViews {
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
- (void)shakeAnimation {
CALayer* layer = [self layer];
CGPoint position = [layer position];
CGPoint y = CGPointMake(position.x - 8.0f, position.y);
CGPoint x = CGPointMake(position.x + 8.0f, position.y);
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setFromValue:[NSValue valueWithCGPoint:x]];
[animation setToValue:[NSValue valueWithCGPoint:y]];
[animation setAutoreverses:YES];
[animation setDuration:0.08f];
[animation setRepeatCount:3];
[layer addAnimation:animation forKey:nil];
}
- (void)springingAnimation
{
CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
popAnimation.duration = 0.4;
popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DIdentity]];
popAnimation.keyTimes = @[@0.2f, @0.5f, @0.75f, @1.0f];
popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self layer] addAnimation:popAnimation forKey:nil];
}
@end
//
// UIViewController+Category.h
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (Category)
/**
push
@param viewController viewcontroller
@param animated 动画
*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
/**
pop
@param animated 是否动画
*/
- (void)popViewControllerAnimated:(BOOL)animated;
/**
pop to root
@param animated 是否动画
*/
- (void)popToRootViewControllerAnimated:(BOOL)animated;
/**
pop to UIViewController
@param viewController viewcontroller
@param animated 是否动画
*/
- (void)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
@end
//
// UIViewController+Category.m
// YXKit
//
// Created by 曹云霄 on 16/9/22.
// Copyright © 2016年 caoyunxiao. All rights reserved.
//
#import "UIViewController+Category.h"
@implementation UIViewController (Category)
/**
push
@param viewController viewcontroller
@param animated 是否动画
*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[self.navigationController pushViewController:viewController animated:YES];
}
/**
pop
@param animated 是否动画
*/
- (void)popViewControllerAnimated:(BOOL)animated
{
[self.navigationController popViewControllerAnimated:animated];
}
/**
pop to root
@param animated 是否动画
*/
- (void)popToRootViewControllerAnimated:(BOOL)animated
{
[self.navigationController popToRootViewControllerAnimated:animated];
}
/**
pop to UIViewController
@param viewController viewcontroller
@param animated 是否动画
*/
- (void)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[self.navigationController popToViewController:viewController animated:animated];
}
@end
//
// CalculateHelper.h
// YXKit
//
// Created by 曹云霄 on 2017/6/30.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CalculateType) {
CalculateTypeAdd = 0, //加
CalculateTypeSub, //减
CalculateTypeMul, //乘
CalculateTypeDiv //除
};
@interface CalculateHelper : NSObject
/*
NSRoundPlain, // Round up on a tie //貌似取整
NSRoundDown, // Always down == truncate //只舍不入
NSRoundUp, // Always up // 只入不舍
NSRoundBankers // on a tie round so last digit is even 貌似四舍五入
*/
/**
* 计算
*
* @param num1 第一个数字
* @param num2 第二个数字
* @param type 计算类型(加减乘除)
* @param roundingType 四舍五入类型
* @param coutLenth 小数点后面保留几位
*
* @return 结算结果
*/
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type roundingType:(NSRoundingMode)roundingType cutLenth:(NSInteger)coutLenth;
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type;
/** add */
+ (NSDecimalNumber *)add:(id)num1 num2:(id)num2;
/** sub */
+ (NSDecimalNumber *)sub:(id)num1 num2:(id)num2;
/** mul */
+ (NSDecimalNumber *)mul:(id)num1 num2:(id)num2;
/** div */
+ (NSDecimalNumber *)div:(id)num1 num2:(id)num2;
/** 一百倍 */
+ (NSDecimalNumber *)oneHundredTimes:(id)num;
/** 计算百分比 */
+ (NSString *)getPercent:(id)num1 num:(id)num2;
/** 获取金额 保留两位小数*/
+ (NSString *)getMoneyStringFrom:(id)num;
/** 获取金额 */
+ (NSString *)getMoneyStringFrom:(id)num Lenth:(NSInteger)cutLenth isSeparate:(BOOL)isSeparate;
+ (NSString *)getMoneyStringFromString:(NSString *)originString;
//获取金额包涵正负号
+ (NSString *)moneyStringWithPrefix:(id)num;
//获得绝对值
+ (NSString *)getABSValue:(NSString *)string;
/** 每3位加逗号 */
+ (NSString *)separateMoney:(id)num;
/** 把非decimalNumber转化 */
+ (NSDecimalNumber *)decimalNumber:(id)number;
/**
* 判断数字是否在给定的范围内,num1和num2的顺序不影响判断
*
* @param num 需要判断的数字
* @param num1 范围区间
* @param num2 范围区间
*
* @return 是否在区间内
*/
+ (BOOL)number:(id)num isInNum1:(id)num1 num2:(id)num2;
@end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
//
// YXKitHeader.h
// YXKitHeader
//
// Created by 曹云霄 on 2017/1/22.
// Copyright © 2017年 曹云霄. All rights reserved.
//
#ifndef YXKitHeader_h
#define YXKitHeader_h
#import "NSDictionary+Category.h"
#import "NSArray+Category.h"
#import "NSBundle+Category.h"
#import "NSDate+Category.h"
#import "NSObject+Category.h"
#import "NSString+Category.h"
#import "UIBarButtonItem+Category.h"
#import "UIButton+Category.h"
#import "UIColor+Category.h"
#import "UIView+Category.h"
#import "UIViewController+Category.h"
#import "CalculateHelper.h"
#import "XYDownMenuViewController.h"
#import "YXKitTool.h"
#import "UITableView+Category.h"
#import "UIImage+Category.h"
#import "UIDevice+Category.h"
#endif /* YXKitHeader_h */
This diff is collapsed.
This diff is collapsed.
......@@ -7,7 +7,6 @@
#import "YXKitHeader.h"
#import "YXPickerManager.h"
@import YXAlertController;
@import YXKit;
#import "IQTextView.h"
#import "UIDevice+Helper.h"
#import "NSString+Helper.h"
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment