675 lines
20 KiB
Objective-C
675 lines
20 KiB
Objective-C
//
|
||
// dataContorl.m
|
||
// Ifish
|
||
//
|
||
// Created by imac on 15/10/13.
|
||
// Copyright © 2015年 imac. All rights reserved.
|
||
//
|
||
|
||
#import "dataContorl.h"
|
||
|
||
|
||
@implementation dataContorl
|
||
// NSdata进制转十六进制字符串
|
||
+(NSString *) dataToHexString:(NSData*)data
|
||
{
|
||
NSUInteger len = [data length];
|
||
char * chars = (char *)[data bytes];
|
||
NSMutableString * hexString = [[NSMutableString alloc] init];
|
||
|
||
for(NSUInteger i = 0; i < len; i++ )
|
||
[hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]];
|
||
return hexString;
|
||
}
|
||
|
||
// 十六进制字符串转NSdata进制
|
||
+(NSData *) stringToHexData:(NSString*)string{
|
||
|
||
NSInteger len = [string length] / 2; // Target length
|
||
unsigned char *buf = malloc(len);
|
||
unsigned char *whole_byte = buf;
|
||
char byte_chars[3] = {'\0','\0','\0'};
|
||
|
||
int i;
|
||
for (i=0; i < [string length] / 2; i++) {
|
||
byte_chars[0] = [string characterAtIndex:i*2];
|
||
byte_chars[1] = [string characterAtIndex:i*2+1];
|
||
*whole_byte = strtol(byte_chars, NULL, 16);
|
||
whole_byte++;
|
||
}
|
||
NSData *data = [NSData dataWithBytes:buf length:len];
|
||
free( buf );
|
||
return data;
|
||
|
||
}
|
||
// 普通字符串转为十六进制
|
||
+(NSString *)hexStringFromString:(NSString *)string{
|
||
NSData *myD = [string dataUsingEncoding:NSUTF8StringEncoding];
|
||
Byte *bytes = (Byte *)[myD bytes];
|
||
//下面是Byte 转换为16进制。
|
||
NSString *hexStr=@"";
|
||
for(int i=0;i<[myD length];i++)
|
||
{
|
||
NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff];///16进制数
|
||
|
||
if([newHexStr length]==1)
|
||
|
||
hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];
|
||
|
||
else
|
||
|
||
hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];
|
||
}
|
||
return hexStr;
|
||
}
|
||
|
||
+(NSString*)leftAddZero:(NSInteger)totle andStr:(NSString*)str{
|
||
NSMutableString*str1=[NSMutableString string];
|
||
NSInteger strLenth=str.length;
|
||
|
||
while (strLenth<totle) {
|
||
[str1 appendString:@"0"];
|
||
strLenth++;
|
||
}
|
||
[str1 appendString:str];
|
||
return str1;
|
||
}
|
||
|
||
// 十 转十六
|
||
+(NSString *)ToHex:(long long int)tmpid
|
||
{
|
||
NSString *nLetterValue;
|
||
NSString *str =@"";
|
||
long long int ttmpig;
|
||
for (int i = 0; i<9; i++) {
|
||
ttmpig=tmpid%16;
|
||
tmpid=tmpid/16;
|
||
switch (ttmpig)
|
||
{
|
||
case 10:
|
||
nLetterValue =@"A";break;
|
||
case 11:
|
||
nLetterValue =@"B";break;
|
||
case 12:
|
||
nLetterValue =@"C";break;
|
||
case 13:
|
||
nLetterValue =@"D";break;
|
||
case 14:
|
||
nLetterValue =@"E";break;
|
||
case 15:
|
||
nLetterValue =@"F";break;
|
||
default:nLetterValue=[[NSString alloc]initWithFormat:@"%lli",ttmpig];
|
||
|
||
}
|
||
str = [nLetterValue stringByAppendingString:str];
|
||
if (tmpid == 0) {
|
||
break;
|
||
}
|
||
|
||
}
|
||
return str;
|
||
}
|
||
|
||
/// 1 - 10组
|
||
+(NSString *)groupNumberTohex:(NSInteger)number{
|
||
NSString *str = @"";
|
||
switch (number) {
|
||
case 0:
|
||
str = @"00";
|
||
break;
|
||
case 1:
|
||
str = @"01";
|
||
break;
|
||
case 2:
|
||
str = @"02";
|
||
break;
|
||
case 3:
|
||
str = @"03";
|
||
break;
|
||
case 4:
|
||
str = @"04";
|
||
break;
|
||
case 5:
|
||
str = @"05";
|
||
break;
|
||
case 6:
|
||
str = @"06";
|
||
break;
|
||
case 7:
|
||
str = @"07";
|
||
break;
|
||
case 8:
|
||
str = @"08";
|
||
break;
|
||
case 9:
|
||
str = @"09";
|
||
break;
|
||
case 10:
|
||
str = @"0a";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return str;
|
||
}
|
||
|
||
// 十六转十
|
||
+(UInt64)hexToTen:(NSString*)str{
|
||
// unsigned long long result = 0;
|
||
//
|
||
// NSScanner *scanner = [NSScanner scannerWithString:data];
|
||
//
|
||
// [scanner scanHexLongLong:&result];
|
||
// return scanner;
|
||
UInt64 mac1 = 0;
|
||
if (str) {
|
||
|
||
mac1 = strtoul([str UTF8String], 0, 16);
|
||
|
||
}
|
||
return mac1;
|
||
|
||
}
|
||
// 十六转串
|
||
+ (NSString *)stringFromHexString:(NSString *)hexString { //
|
||
char *myBuffer = (char *)malloc((int)[hexString length] / 2 + 1);
|
||
bzero(myBuffer, [hexString length] / 2 + 1);
|
||
for (int i = 0; i < [hexString length] - 1; i += 2) {
|
||
unsigned int anInt;
|
||
NSString * hexCharStr = [hexString substringWithRange:NSMakeRange(i, 2)];
|
||
NSScanner * scanner = [[NSScanner alloc] initWithString:hexCharStr];
|
||
[scanner scanHexInt:&anInt];
|
||
myBuffer[i / 2] = (char)anInt;
|
||
}
|
||
NSString *unicodeString = [NSString stringWithCString:myBuffer encoding:4];
|
||
NSLog(@"------字符串=======%@",unicodeString);
|
||
return unicodeString;
|
||
}
|
||
//时间转四位十六进制 如01:15——> 010f
|
||
+(NSString*)dateStringToHexString:(NSString *)dateString{
|
||
|
||
//NSString*hour=[dateString substringWithRange:NSMakeRange(0, 2)];// 0~23 小时
|
||
NSRange range=[dateString rangeOfString:@":"];
|
||
NSString*hour=[dateString substringToIndex:range.location];
|
||
// NSString*minite=[dateString substringWithRange:NSMakeRange(3, 2)];// 0~59 分钟
|
||
NSString*minite=[dateString substringFromIndex:range.location+1];
|
||
NSString*hexHour=@"";//
|
||
NSString*hexMinite=@"";
|
||
// if ([hour hasPrefix:@"0"]) {
|
||
// hexHour=[NSString stringWithFormat:@"0%@",[[NSString alloc] initWithFormat:@"%1x",[hour intValue]]];
|
||
// // NSLog(@"hex0带 %@",hexHour);
|
||
//
|
||
//
|
||
// }else{
|
||
hexHour=[NSString stringWithFormat:@"%@",[[NSString alloc] initWithFormat:@"%1x",[hour intValue]]];
|
||
// NSLog(@"hex %@",hexHour);
|
||
// }
|
||
|
||
if ([minite hasPrefix:@"0"]) {
|
||
hexMinite=[NSString stringWithFormat:@"0%@",[[NSString alloc] initWithFormat:@"%1x",[minite intValue]]];
|
||
}else{
|
||
hexMinite=[NSString stringWithFormat:@"%@",[[NSString alloc] initWithFormat:@"%1x",[minite intValue]]];;
|
||
}
|
||
|
||
|
||
if (hexHour.length==1) {
|
||
hexHour=[NSString stringWithFormat:@"0%@",hexHour];
|
||
}
|
||
if (hexMinite.length==1) {
|
||
hexMinite=[NSString stringWithFormat:@"0%@",hexMinite];
|
||
}
|
||
|
||
NSString*fomatString=[NSString stringWithFormat:@"%@%@",hexHour,hexMinite];
|
||
|
||
|
||
return fomatString;
|
||
|
||
}
|
||
//1-40C 十进制温度数据 转四位 十六进制数据串
|
||
// 1C 1*10 / 10C 10*10 /20C 20*10/ 26C 26*10
|
||
// 10-000a 100-0064 200-00C8 260-0104
|
||
|
||
+(NSString*)tpIntStringToFourHex:(int)intString{
|
||
NSString*siWeihexString=@"";
|
||
if (intString==10) {
|
||
|
||
NSString*hexString=[NSString stringWithFormat:@"%@",[[NSString alloc]initWithFormat:@"%1x",intString]];
|
||
siWeihexString=[NSString stringWithFormat:@"000%@",hexString];
|
||
|
||
}else if (intString>10&&intString<260)
|
||
{
|
||
NSString*hexString=[NSString stringWithFormat:@"%@",[[NSString alloc]initWithFormat:@"%1x",intString]];
|
||
siWeihexString=[NSString stringWithFormat:@"00%@",hexString];
|
||
|
||
|
||
}else if (intString>=260)
|
||
{
|
||
NSString*hexString=[NSString stringWithFormat:@"%@",[[NSString alloc]initWithFormat:@"%1x",intString]];
|
||
siWeihexString=[NSString stringWithFormat:@"0%@",hexString];
|
||
|
||
}
|
||
return siWeihexString;
|
||
}
|
||
//四位 十六进制转时间 如 010f——> 01:15
|
||
+(NSString*)hexStringToDateString:(NSString*)hexString{
|
||
|
||
NSString*shiString=@"";
|
||
NSString*fenString=@"";
|
||
UInt64 shi =strtoul([[hexString substringWithRange:NSMakeRange(0, 2)] UTF8String], 0, 16);
|
||
|
||
shiString=[NSString stringWithFormat:@"%llu",shi];
|
||
if ([shiString isEqualToString:@"0"]) {
|
||
shiString = @"00";
|
||
}else if ([shiString isEqualToString:@"1"]){
|
||
shiString = @"01";
|
||
}else if ([shiString isEqualToString:@"2"]){
|
||
shiString = @"02";
|
||
}else if ([shiString isEqualToString:@"3"]){
|
||
shiString = @"03";
|
||
}else if ([shiString isEqualToString:@"4"]){
|
||
shiString = @"04";
|
||
}else if ([shiString isEqualToString:@"5"]){
|
||
shiString = @"05";
|
||
}else if ([shiString isEqualToString:@"6"]){
|
||
shiString = @"06";
|
||
}else if ([shiString isEqualToString:@"7"]){
|
||
shiString = @"07";
|
||
}else if ([shiString isEqualToString:@"8"]){
|
||
shiString = @"08";
|
||
}else if ([shiString isEqualToString:@"9"]){
|
||
shiString = @"09";
|
||
}
|
||
// NSLog(@"str2 %@",shiString);
|
||
|
||
|
||
UInt64 fen = strtoul([[hexString substringWithRange:NSMakeRange(2, 2)] UTF8String], 0, 16);
|
||
if (fen<=9) {
|
||
fenString=[NSString stringWithFormat:@"0%llu",fen
|
||
];
|
||
// NSLog(@"str3 %@",fenString);
|
||
}else{
|
||
fenString=[NSString stringWithFormat:@"%llu",fen
|
||
];
|
||
// NSLog(@"str4 %@",fenString);
|
||
}
|
||
|
||
NSString*formatString=[NSString stringWithFormat:@"%@:%@",shiString,fenString];
|
||
|
||
//NSLog(@"str5 %@",formatString);
|
||
|
||
return formatString;
|
||
|
||
}
|
||
//阿拉伯数字转化为汉语数字
|
||
+(NSString *)translation:(NSString *)arebic
|
||
|
||
{ NSString *str = arebic;
|
||
NSArray *arabic_numerals = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"0"];
|
||
NSArray *chinese_numerals = @[@"一",@"二",@"三",@"四",@"五",@"六",@"七",@"八",@"九",@"零"];
|
||
NSArray *digits = @[@"个",@"十",@"百",@"千",@"万",@"十",@"百",@"千",@"亿",@"十",@"百",@"千",@"兆"];
|
||
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:chinese_numerals forKeys:arabic_numerals];
|
||
|
||
NSMutableArray *sums = [NSMutableArray array];
|
||
for (int i = 0; i < str.length; i ++) {
|
||
NSString *substr = [str substringWithRange:NSMakeRange(i, 1)];
|
||
NSString *a = [dictionary objectForKey:substr];
|
||
NSString *b = digits[str.length -i-1];
|
||
NSString *sum = [a stringByAppendingString:b];
|
||
if ([a isEqualToString:chinese_numerals[9]])
|
||
{
|
||
if([b isEqualToString:digits[4]] || [b isEqualToString:digits[8]])
|
||
{
|
||
sum = b;
|
||
if ([[sums lastObject] isEqualToString:chinese_numerals[9]])
|
||
{
|
||
[sums removeLastObject];
|
||
}
|
||
}else
|
||
{
|
||
sum = chinese_numerals[9];
|
||
}
|
||
|
||
if ([[sums lastObject] isEqualToString:sum])
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
[sums addObject:sum];
|
||
}
|
||
|
||
NSString *sumStr = [sums componentsJoinedByString:@""];
|
||
NSString *chinese = [sumStr substringToIndex:sumStr.length-1];
|
||
NSLog(@"%@",str);
|
||
NSLog(@"%@",chinese);
|
||
return chinese;
|
||
}
|
||
|
||
|
||
+(NSString *)get10LengthString
|
||
{
|
||
NSString *string = [[NSString alloc]init];
|
||
for (int i = 0; i < 10; i++) {
|
||
int number = arc4random() % 36;
|
||
if (number < 10) {
|
||
int figure = arc4random() % 10;
|
||
NSString *tempString = [NSString stringWithFormat:@"%d", figure];
|
||
string = [string stringByAppendingString:tempString];
|
||
}else {
|
||
int figure = (arc4random() % 26) + 97;
|
||
char character = figure;
|
||
NSString *tempString = [NSString stringWithFormat:@"%c", character];
|
||
string = [string stringByAppendingString:tempString];
|
||
}
|
||
}
|
||
|
||
return string;
|
||
|
||
|
||
}
|
||
//获取时间戳 当前时间long型的毫秒数除以1000
|
||
|
||
+(NSString *)getCurrentSyatemTime
|
||
{
|
||
//获取系统当前的时间戳 秒级
|
||
|
||
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
|
||
|
||
NSTimeInterval time=[dat timeIntervalSince1970];
|
||
long longTime = (long)time;
|
||
NSString *timeString = [NSString stringWithFormat:@"%ld",longTime];
|
||
return timeString;
|
||
|
||
|
||
}
|
||
|
||
+(NSString *)getYearmonthaddDay{
|
||
|
||
NSDate * date=[NSDate date];
|
||
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
|
||
dateFormatter.dateFormat=@"yyyy-MM-dd";
|
||
NSString *foamtDate = [dateFormatter stringFromDate:date];
|
||
return foamtDate;
|
||
}
|
||
|
||
+(NSString *)getMonthAndDay:(NSDate *)date{
|
||
|
||
NSDate * day=[NSDate date];
|
||
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
|
||
dateFormatter.dateFormat=@"MM-dd";
|
||
NSString *foamtDate = [dateFormatter stringFromDate:day];
|
||
return foamtDate;
|
||
}
|
||
|
||
+(NSString *)getHmWithDate:(NSDate *)date{
|
||
|
||
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
|
||
dateFormatter.dateFormat=@"HH:mm";
|
||
NSString *foamtDate = [dateFormatter stringFromDate:date];
|
||
return foamtDate;
|
||
|
||
}
|
||
|
||
+(NSString *)getYearmonthaddDayWithDate:(NSDate *)date{
|
||
|
||
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
|
||
dateFormatter.dateFormat=@"yyyy-MM-dd";
|
||
NSString *foamtDate = [dateFormatter stringFromDate:date];
|
||
return foamtDate;
|
||
|
||
}
|
||
//判断手机号码格式是否正确
|
||
|
||
+ (BOOL)valiMobile:(NSString *)mobile
|
||
|
||
{
|
||
|
||
NSString * MOBILE = @"^[1][3-8]\\d{9}$|^([6|9])\\d{7}$|^[0][9]\\d{8}$|^[6]([8|6])\\d{5}$";
|
||
NSPredicate*regextestmobile=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE];
|
||
BOOL isMacth=[regextestmobile evaluateWithObject:mobile];
|
||
/* 正则表达式:^[1][3-8]\\d{9}$|^([6|9])\\d{7}$|^[0][9]\\d{8}$|^[6]([8|6])\\d{5}$
|
||
|
||
规则说明:
|
||
|
||
中国大陆:开头1 3-8号段,后边跟9位数字
|
||
|
||
台湾:09开头后面跟8位数字
|
||
|
||
香港:9或6开头后面跟7位数字
|
||
|
||
澳门:66或68开头后面跟5位数字
|
||
|
||
注意:以上表达式只验证港澳台及大陆手机号码,不包含座机小灵通及区号等验证
|
||
|
||
*/
|
||
if (isMacth) {
|
||
|
||
return YES;
|
||
}else{
|
||
|
||
return NO;
|
||
}
|
||
|
||
}
|
||
|
||
+ (NSString*)areaCode:(NSString *)phoneNumb{
|
||
|
||
NSString *zone= nil;
|
||
//中国大陆:开头1 3-8号段
|
||
NSString *prenumb = [phoneNumb substringWithRange:NSMakeRange(0, 2)];
|
||
NSString * MOBILE1 = @"^[1][3-8]$";
|
||
NSPredicate*regextestmobile1=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE1];
|
||
|
||
BOOL isMacth1=[regextestmobile1 evaluateWithObject:prenumb];
|
||
|
||
// 台湾:09开头后面跟8位数字
|
||
NSString * MOBILE2 = @"^[0][9]$";
|
||
NSPredicate*regextestmobile2=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE2];
|
||
|
||
BOOL isMacth2=[regextestmobile2 evaluateWithObject:prenumb];
|
||
//香港
|
||
NSString *prenumb1 = [phoneNumb substringWithRange:NSMakeRange(0, 1)];
|
||
NSString * MOBILE3 = @"^([5|6|9])$";
|
||
NSPredicate*regextestmobile3=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE3];
|
||
BOOL isMacth3=[regextestmobile3 evaluateWithObject:prenumb1];
|
||
|
||
//澳门
|
||
|
||
NSString * MOBILE4 = @"^[6]([8|6])$";
|
||
NSPredicate*regextestmobile4=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE4];
|
||
BOOL isMacth4=[regextestmobile4 evaluateWithObject:prenumb];
|
||
|
||
|
||
|
||
if (isMacth1) {
|
||
//大陆
|
||
zone = @"86";
|
||
|
||
}else if (isMacth2)
|
||
{
|
||
//台湾
|
||
zone = @"886";
|
||
|
||
}else if (isMacth3){
|
||
//香港
|
||
zone = @"852";
|
||
|
||
}else if (isMacth4){
|
||
//澳门
|
||
zone = @"853";
|
||
}
|
||
|
||
return zone;
|
||
}
|
||
|
||
+(NSString *)dataControlGetUserIdInfo
|
||
{
|
||
|
||
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
|
||
NSString *userId =[NSString stringWithFormat:@"%@",model.userId];
|
||
|
||
return userId;
|
||
|
||
}
|
||
|
||
+(UserModel*)getUserInfo
|
||
{
|
||
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
|
||
NSString *callId=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff];
|
||
model.callId = callId;
|
||
return model;
|
||
|
||
}
|
||
|
||
//修改
|
||
+(void)resetUser:(UserModel *)model
|
||
{
|
||
|
||
[[DataCenter defaultDtacenter] setValue:model forKey:@"UserLogIn"];
|
||
|
||
}
|
||
+(NSArray *)getallCameras{
|
||
|
||
NSArray*cameraArr =[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"];
|
||
|
||
return cameraArr;
|
||
|
||
}
|
||
|
||
+(void)saveCameraArr:(NSArray*)cameraArr{
|
||
if (!cameraArr) {
|
||
cameraArr = [[NSArray alloc] init];
|
||
}
|
||
[[DataCenter defaultDtacenter] setValue:cameraArr forKey:@"cameraArr"];
|
||
|
||
}
|
||
|
||
+(NSArray *)getallDevices
|
||
{
|
||
NSArray*deviceArr =[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||
return deviceArr;
|
||
}
|
||
|
||
|
||
+ (UIImage *)handleImage:(UIImage *)originalImage withSize:(CGSize)size
|
||
{
|
||
CGSize originalsize = [originalImage size];
|
||
NSLog(@"改变前图片的宽度为%f,图片的高度为%f",originalsize.width,originalsize.height);
|
||
|
||
//原图长宽均小于标准长宽的,不作处理返回原图
|
||
if (originalsize.width<size.width && originalsize.height<size.height)
|
||
{
|
||
return originalImage;
|
||
}
|
||
|
||
//原图长宽均大于标准长宽的,按比例缩小至最大适应值
|
||
else if(originalsize.width>size.width && originalsize.height>size.height)
|
||
{
|
||
CGFloat rate = 1.0;
|
||
CGFloat widthRate = originalsize.width/size.width;
|
||
CGFloat heightRate = originalsize.height/size.height;
|
||
|
||
rate = widthRate>heightRate?heightRate:widthRate;
|
||
|
||
CGImageRef imageRef = nil;
|
||
|
||
if (heightRate>widthRate)
|
||
{
|
||
imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(0, originalsize.height/2-size.height*rate/2, originalsize.width, size.height*rate));//获取图片整体部分
|
||
}
|
||
else
|
||
{
|
||
imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(originalsize.width/2-size.width*rate/2, 0, size.width*rate, originalsize.height));//获取图片整体部分
|
||
}
|
||
UIGraphicsBeginImageContext(size);//指定要绘画图片的大小
|
||
CGContextRef con = UIGraphicsGetCurrentContext();
|
||
|
||
CGContextTranslateCTM(con, 0.0, size.height);
|
||
CGContextScaleCTM(con, 1.0, -1.0);
|
||
|
||
CGContextDrawImage(con, CGRectMake(0, 0, size.width, size.height), imageRef);
|
||
|
||
UIImage *standardImage = UIGraphicsGetImageFromCurrentImageContext();
|
||
NSLog(@"改变后图片的宽度为%f,图片的高度为%f",[standardImage size].width,[standardImage size].height);
|
||
|
||
UIGraphicsEndImageContext();
|
||
CGImageRelease(imageRef);
|
||
|
||
return standardImage;
|
||
}
|
||
|
||
//原图长宽有一项大于标准长宽的,对大于标准的那一项进行裁剪,另一项保持不变
|
||
else if(originalsize.height>size.height || originalsize.width>size.width)
|
||
{
|
||
CGImageRef imageRef = nil;
|
||
|
||
if(originalsize.height>size.height)
|
||
{
|
||
imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(0, originalsize.height/2-size.height/2, originalsize.width, size.height));//获取图片整体部分
|
||
}
|
||
else if (originalsize.width>size.width)
|
||
{
|
||
imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(originalsize.width/2-size.width/2, 0, size.width, originalsize.height));//获取图片整体部分
|
||
}
|
||
|
||
UIGraphicsBeginImageContext(size);//指定要绘画图片的大小
|
||
CGContextRef con = UIGraphicsGetCurrentContext();
|
||
|
||
CGContextTranslateCTM(con, 0.0, size.height);
|
||
CGContextScaleCTM(con, 1.0, -1.0);
|
||
|
||
CGContextDrawImage(con, CGRectMake(0, 0, size.width, size.height), imageRef);
|
||
|
||
UIImage *standardImage = UIGraphicsGetImageFromCurrentImageContext();
|
||
NSLog(@"改变后图片的宽度为%f,图片的高度为%f",[standardImage size].width,[standardImage size].height);
|
||
|
||
UIGraphicsEndImageContext();
|
||
CGImageRelease(imageRef);
|
||
|
||
return standardImage;
|
||
}
|
||
|
||
//原图为标准长宽的,不做处理
|
||
else
|
||
{
|
||
return originalImage;
|
||
}
|
||
}
|
||
|
||
+(IfishUserAsset*)getAllIfishUserAsset{
|
||
|
||
IfishUserAsset*model=[[DataCenter defaultDtacenter]valueForKey:@"IfishUserAsset"];
|
||
return model;
|
||
}
|
||
|
||
+(void)resetUserAsset:(IfishUserAsset *)model
|
||
{
|
||
[[DataCenter defaultDtacenter] setValue:model forKey:@"IfishUserAsset"];
|
||
|
||
}
|
||
|
||
+(NSDate*)formatDateTime:(NSString *)timerstr
|
||
{
|
||
|
||
NSString *string = timerstr;
|
||
NSTimeInterval second = string.longLongValue / 1000.0;
|
||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
|
||
return date;
|
||
}
|
||
|
||
//判断是否包含特殊字符串 即非数字字母下划线
|
||
+(BOOL)isIncludeSpecialCharact:(NSString *)str {
|
||
|
||
// NSString *regex =@"(^[a-zA-Z0-9_\u4e00-\u9fa5]+$)";
|
||
// NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
|
||
// BOOL isRight = [pred evaluateWithObject:str];
|
||
|
||
BOOL isRight=YES;//仅有“‘不可以
|
||
if ([str containsString:@"’"]||[str containsString:@"”"]||[str containsString:@"'"]||[str containsString:@"\""]) {
|
||
isRight=NO;
|
||
}
|
||
return isRight;
|
||
}
|
||
|
||
@end
|