/**
数组排序 array=要排序的数组 attribute=要排序的字段 asc=是否是升序
排序完 传进来的引用array 就是排序后的结果
*/
void arraySort(NSMutableArray * array, NSString *attribute, BOOL asc){
NSMutableArray *sortDescriptors = [NSMutableArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:attribute ascending:asc]];
[array sortUsingDescriptors:sortDescriptors ];
}
/**
时间 转换 time 秒数
*/
NSString* formatTimeByInt(int time, NSString *format){
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:time];
[dateFormatter setDateFormat:format];
NSString *resultTime = [dateFormatter stringFromDate:date1];
[dateFormatter release];
return resultTime;
}
/**
将16进制的颜色值变成UIColor @"FFFF00"
*/
UIColor * colorFromHexRGB(NSString *inColorString){
UIColor *result = nil;
unsigned int colorCode = 0;
unsigned char redByte, greenByte, blueByte;
if (nil != inColorString)
{
NSScanner *scanner = [NSScanner scannerWithString:inColorString];
(void) [scanner scanHexInt:&colorCode]; // ignore error
}
redByte = (unsigned char) (colorCode >> 16);
greenByte = (unsigned char) (colorCode >> 8);
blueByte = (unsigned char) (colorCode); // masks off high bits
result = [UIColor
colorWithRed: (float)redByte / 0xff
green: (float)greenByte/ 0xff
blue: (float)blueByte / 0xff
alpha:1.0];
return result;
}
数组排序 array=要排序的数组 attribute=要排序的字段 asc=是否是升序
排序完 传进来的引用array 就是排序后的结果
*/
void arraySort(NSMutableArray * array, NSString *attribute, BOOL asc){
NSMutableArray *sortDescriptors = [NSMutableArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:attribute ascending:asc]];
[array sortUsingDescriptors:sortDescriptors ];
}
/**
时间 转换 time 秒数
*/
NSString* formatTimeByInt(int time, NSString *format){
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:time];
[dateFormatter setDateFormat:format];
NSString *resultTime = [dateFormatter stringFromDate:date1];
[dateFormatter release];
return resultTime;
}
/**
将16进制的颜色值变成UIColor @"FFFF00"
*/
UIColor * colorFromHexRGB(NSString *inColorString){
UIColor *result = nil;
unsigned int colorCode = 0;
unsigned char redByte, greenByte, blueByte;
if (nil != inColorString)
{
NSScanner *scanner = [NSScanner scannerWithString:inColorString];
(void) [scanner scanHexInt:&colorCode]; // ignore error
}
redByte = (unsigned char) (colorCode >> 16);
greenByte = (unsigned char) (colorCode >> 8);
blueByte = (unsigned char) (colorCode); // masks off high bits
result = [UIColor
colorWithRed: (float)redByte / 0xff
green: (float)greenByte/ 0xff
blue: (float)blueByte / 0xff
alpha:1.0];
return result;
}