├── .DS_Store ├── README.md ├── catagory ├── .DS_Store ├── CALayer+XibConfiguration.h ├── CALayer+XibConfiguration.m ├── Classes │ ├── .DS_Store │ ├── MCSCollectionUtility.h │ ├── NSArray+MCSCollectionUtility.h │ ├── NSArray+MCSCollectionUtility.m │ ├── NSDictionary+MCSCollectionUtility.h │ ├── NSDictionary+MCSCollectionUtility.m │ ├── NSSet+MCSCollectionUtility.h │ └── NSSet+MCSCollectionUtility.m ├── DES3Util.h ├── DES3Util.m ├── NSArray+SLExt.h ├── NSArray+SLExt.m ├── NSDate+SLExtend.h ├── NSDate+SLExtend.m ├── NSObject+HUD.h ├── NSObject+HUD.m ├── NSObject+filterPropertys.h ├── NSObject+filterPropertys.m ├── NSString+SLExt.h ├── NSString+SLExt.m ├── UIViewExt.h ├── UIViewExt.m ├── Utility.h ├── Utility.m ├── Utils.h ├── ViewUtilFactory.h └── ViewUtilFactory.m └── my_Control ├── .DS_Store ├── ICSwitchControl.h └── ICSwitchControl.m /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AugustRush/Collection_devClass/92b49c9877da73da24db3ce5b5b7324175c54ebb/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Collection_devClass 2 | =================== 3 | 4 | 一些工具类 5 | 6 | ///// 7 | 2014.5.11 添加mycontrol文件夹,添加自定义switchconotrol 8 | -------------------------------------------------------------------------------- /catagory/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AugustRush/Collection_devClass/92b49c9877da73da24db3ce5b5b7324175c54ebb/catagory/.DS_Store -------------------------------------------------------------------------------- /catagory/CALayer+XibConfiguration.h: -------------------------------------------------------------------------------- 1 | // 2 | // CALayer+XibConfiguration.h 3 | // schoolfellow 4 | // 5 | // Created by EasyitsApp on 13-12-4. 6 | // Copyright (c) 2013年 www.easyits.net. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CALayer (XibConfiguration) 12 | 13 | // This assigns a CGColor to borderColor. 14 | @property(nonatomic, assign) UIColor *borderUIColor; 15 | @property(nonatomic, assign) UIColor *shadowUIColor; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /catagory/CALayer+XibConfiguration.m: -------------------------------------------------------------------------------- 1 | // 2 | // CALayer+XibConfiguration.m 3 | // schoolfellow 4 | // 5 | // Created by EasyitsApp on 13-12-4. 6 | // Copyright (c) 2013年 www.easyits.net. All rights reserved. 7 | // 8 | 9 | #import "CALayer+XibConfiguration.h" 10 | 11 | @implementation CALayer (XibConfiguration) 12 | 13 | -(void)setBorderUIColor:(UIColor*)color 14 | { 15 | self.borderColor = color.CGColor; 16 | } 17 | 18 | -(UIColor *)borderUIColor 19 | { 20 | return [UIColor colorWithCGColor:self.borderColor]; 21 | } 22 | 23 | - (void)setShadowUIColor:(UIColor *)color 24 | { 25 | self.shadowColor = color.CGColor; 26 | } 27 | 28 | - (UIColor *)shadowUIColor 29 | { 30 | return [UIColor colorWithCGColor:self.shadowColor]; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /catagory/Classes/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AugustRush/Collection_devClass/92b49c9877da73da24db3ce5b5b7324175c54ebb/catagory/Classes/.DS_Store -------------------------------------------------------------------------------- /catagory/Classes/MCSCollectionUtility.h: -------------------------------------------------------------------------------- 1 | // 2 | // MCSCollectionUtility.h 3 | // MCKCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 21.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MCSCollectionUtility.h" 10 | #import "NSDictionary+MCSCollectionUtility.h" 11 | #import "NSSet+MCSCollectionUtility.h" 12 | -------------------------------------------------------------------------------- /catagory/Classes/NSArray+MCSCollectionUtility.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MCSCollectionUtility.h 3 | // MCSCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 12.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (MCSCollectionUtility) 12 | 13 | - (void)mcs_each:(void(^)(id object))block; 14 | - (void)mcs_eachWithIndex:(void(^)(id object, NSUInteger index))block; 15 | 16 | - (NSArray *)mcs_skip:(NSInteger)number; 17 | - (NSArray *)mcs_skipWhile:(BOOL(^)(id object))block; 18 | 19 | - (NSArray *)mcs_take:(NSInteger)number; 20 | - (NSArray *)mcs_takeWhile:(BOOL(^)(id object))block; 21 | 22 | - (NSArray *)mcs_where:(BOOL(^)(id object))block; 23 | 24 | - (NSArray *)mcs_unique; 25 | - (NSArray *)mcs_unique:(BOOL(^)(id object1, id object2))block; 26 | 27 | - (NSArray *)mcs_union:(NSArray *)array; 28 | - (NSArray *)mcs_union:(NSArray *)array comparator:(BOOL(^)(id object1, id object2))block; 29 | 30 | - (NSArray *)mcs_select:(id(^)(id object))block; 31 | - (NSArray *)mcs_selectMany:(NSArray *(^)(id object))block; 32 | - (NSArray *)mcs_map:(id(^)(id object))block; 33 | 34 | - (NSInteger)mcs_count:(BOOL(^)(id object))block; 35 | 36 | - (NSInteger)mcs_minInteger:(NSInteger(^)(id object))block; 37 | - (CGFloat)mcs_minFloat:(CGFloat(^)(id object))block; 38 | 39 | - (NSInteger)mcs_maxInteger:(NSInteger(^)(id object))block; 40 | - (CGFloat)mcs_maxFloat:(CGFloat(^)(id object))block; 41 | 42 | - (NSInteger)mcs_sumInteger:(NSInteger(^)(id object))block; 43 | - (CGFloat)mcs_sumFloat:(CGFloat(^)(id object))block; 44 | 45 | - (NSInteger)mcs_averageInteger:(NSInteger(^)(id object))block; 46 | - (CGFloat)mcs_averageFloat:(CGFloat(^)(id object))block; 47 | 48 | - (BOOL)mcs_single:(BOOL(^)(id object))block; 49 | - (BOOL)mcs_any:(BOOL(^)(id object))block; 50 | - (BOOL)mcs_all:(BOOL(^)(id object))block; 51 | 52 | - (id)mcs_first:(id(^)(id object))block; 53 | - (id)mcs_last:(id(^)(id object))block; 54 | 55 | - (NSArray *)mcs_reverse; 56 | 57 | - (BOOL)mcs_hasAnyElement; 58 | 59 | - (id)mcs_sample; 60 | 61 | - (NSArray *)mcs_rotate:(NSInteger)shift; 62 | 63 | - (NSArray *)mcs_sort; 64 | - (NSArray *)mcs_sortInDescendingOrder; 65 | 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /catagory/Classes/NSArray+MCSCollectionUtility.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MCSCollectionUtility.m 3 | // MCSCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 12.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MCSCollectionUtility.h" 10 | 11 | @implementation NSArray (MCSCollectionUtility) 12 | 13 | - (NSArray *)mcs_take:(NSInteger)number 14 | { 15 | NSInteger count = [self count]; 16 | number = MIN(count, number); 17 | 18 | return [self subarrayWithRange:NSMakeRange(0, number)]; 19 | } 20 | 21 | - (NSArray *)mcs_takeWhile:(BOOL (^)(id))block 22 | { 23 | NSInteger index = [self indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { 24 | 25 | return !block(obj); 26 | 27 | }]; 28 | 29 | if (index == NSNotFound) { 30 | return [self copy]; 31 | } 32 | 33 | return [self subarrayWithRange:NSMakeRange(0, index)]; 34 | } 35 | 36 | - (NSArray *)mcs_skip:(NSInteger)number 37 | { 38 | return [[self mcs_rotate:-number] mcs_take:([self count] - number)]; 39 | } 40 | 41 | - (NSArray *)mcs_skipWhile:(BOOL (^)(id))block 42 | { 43 | NSUInteger index = [self indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { 44 | 45 | return !block(obj); 46 | 47 | }]; 48 | 49 | if (index == NSNotFound) { 50 | return [NSArray array]; 51 | } 52 | 53 | return [[self mcs_rotate:-index] mcs_take:([self count] - index)]; 54 | } 55 | 56 | - (NSArray *)mcs_where:(BOOL (^)(id))block 57 | { 58 | NSMutableArray *resultArray = [NSMutableArray array]; 59 | 60 | [self mcs_each:^(id object) { 61 | 62 | if (block(object)) { 63 | [resultArray addObject:object]; 64 | } 65 | 66 | }]; 67 | 68 | return [NSArray arrayWithArray:resultArray]; 69 | } 70 | 71 | - (NSArray *)mcs_unique 72 | { 73 | return [self mcs_unique:^BOOL(id object1, id object2) { 74 | return [object1 isEqual:object2]; 75 | }]; 76 | } 77 | 78 | - (NSArray *)mcs_unique:(BOOL (^)(id, id))block 79 | { 80 | NSMutableArray *resultArray = [NSMutableArray array]; 81 | 82 | [self mcs_each:^(id object) { 83 | 84 | BOOL unique = 85 | ![resultArray mcs_any:^BOOL(id objectAlreadyContained) { 86 | return block(object, objectAlreadyContained); 87 | }]; 88 | 89 | if (unique) { 90 | [resultArray addObject:object]; 91 | } 92 | 93 | }]; 94 | 95 | return [NSArray arrayWithArray:resultArray]; 96 | } 97 | 98 | - (NSArray *)mcs_union:(NSArray *)array 99 | { 100 | return [self mcs_union:array comparator:^BOOL(id object1, id object2) { 101 | return [object1 isEqual:object2]; 102 | }]; 103 | } 104 | 105 | - (NSArray *)mcs_union:(NSArray *)array comparator:(BOOL (^)(id, id))block 106 | { 107 | NSMutableArray *resultArray = [NSMutableArray arrayWithArray:self]; 108 | 109 | [array mcs_each:^(id objectToAdd) { 110 | 111 | BOOL unique = ![resultArray mcs_any:^BOOL(id object) { 112 | return block(objectToAdd, object); 113 | }]; 114 | 115 | if (unique) { 116 | [resultArray addObject:objectToAdd]; 117 | } 118 | 119 | }]; 120 | 121 | return [NSArray arrayWithArray:resultArray]; 122 | } 123 | 124 | - (NSArray *)mcs_select:(id (^)(id))block 125 | { 126 | NSMutableArray *resultArray = [NSMutableArray array]; 127 | 128 | [self mcs_each:^(id object) { 129 | 130 | id returnedObject = block(object); 131 | if (returnedObject) { 132 | [resultArray addObject:object]; 133 | } 134 | 135 | }]; 136 | 137 | return [NSArray arrayWithArray:resultArray]; 138 | } 139 | 140 | - (NSArray *)mcs_selectMany:(NSArray *(^)(id))block 141 | { 142 | NSMutableArray *resultArray = [NSMutableArray array]; 143 | 144 | [self mcs_each:^(id object) { 145 | 146 | [resultArray addObjectsFromArray:block(object)]; 147 | 148 | }]; 149 | 150 | return [NSArray arrayWithArray:resultArray]; 151 | } 152 | 153 | - (NSArray *)mcs_map:(id (^)(id))block 154 | { 155 | NSMutableArray *resultArray = [NSMutableArray array]; 156 | 157 | [self mcs_each:^(id object) { 158 | 159 | [resultArray addObject:object]; 160 | 161 | }]; 162 | 163 | return [NSArray arrayWithArray:resultArray]; 164 | } 165 | 166 | - (void)mcs_each:(void (^)(id))block 167 | { 168 | [self mcs_eachWithIndex:^(id object, NSUInteger index) { 169 | 170 | block(object); 171 | 172 | }]; 173 | } 174 | 175 | - (void)mcs_eachWithIndex:(void (^)(id, NSUInteger))block 176 | { 177 | NSUInteger index = 0; 178 | 179 | for (id object in self) { 180 | 181 | block(object, index); 182 | index++; 183 | 184 | } 185 | } 186 | 187 | - (NSInteger)mcs_count:(BOOL (^)(id))block 188 | { 189 | return [[self mcs_where:block] count]; 190 | } 191 | 192 | - (NSInteger)mcs_minInteger:(NSInteger (^)(id))block 193 | { 194 | __block NSInteger min = NSIntegerMax; 195 | 196 | [self mcs_each:^(id object) { 197 | 198 | min = MIN(min, block(object)); 199 | 200 | }]; 201 | 202 | return min; 203 | } 204 | 205 | - (CGFloat)mcs_minFloat:(CGFloat (^)(id))block 206 | { 207 | __block CGFloat min = CGFLOAT_MAX; 208 | 209 | [self mcs_each:^(id object) { 210 | 211 | min = MIN(min, block(object)); 212 | 213 | }]; 214 | 215 | return min; 216 | } 217 | 218 | - (NSInteger)mcs_maxInteger:(NSInteger (^)(id))block 219 | { 220 | __block NSInteger max = NSIntegerMin; 221 | 222 | [self mcs_each:^(id object) { 223 | 224 | max = MAX(block(object), max); 225 | 226 | }]; 227 | 228 | return max; 229 | } 230 | 231 | - (CGFloat)mcs_maxFloat:(CGFloat (^)(id))block 232 | { 233 | __block CGFloat max = CGFLOAT_MIN; 234 | 235 | [self mcs_each:^(id object) { 236 | 237 | max = MAX(block(object), max); 238 | 239 | }]; 240 | 241 | return max; 242 | } 243 | 244 | - (NSInteger)mcs_sumInteger:(NSInteger (^)(id))block 245 | { 246 | __block NSInteger sum = 0; 247 | 248 | [self mcs_each:^(id object) { 249 | 250 | sum += block(object); 251 | 252 | }]; 253 | 254 | return sum; 255 | } 256 | 257 | - (CGFloat)mcs_sumFloat:(CGFloat (^)(id))block 258 | { 259 | __block CGFloat sum = 0; 260 | 261 | [self mcs_each:^(id object) { 262 | 263 | sum += block(object); 264 | 265 | }]; 266 | 267 | return sum; 268 | } 269 | 270 | - (NSInteger)mcs_averageInteger:(NSInteger (^)(id))block 271 | { 272 | return [self mcs_hasAnyElement] ? [self mcs_sumInteger:block]/[self count] : 0; 273 | } 274 | 275 | - (CGFloat)mcs_averageFloat:(CGFloat (^)(id))block 276 | { 277 | return [self mcs_hasAnyElement] ? [self mcs_sumFloat:block]/[self count] : 0.0; 278 | } 279 | 280 | - (BOOL)mcs_single:(BOOL (^)(id))block 281 | { 282 | return [self mcs_count:block] == 1; 283 | } 284 | 285 | - (BOOL)mcs_any:(BOOL (^)(id))block 286 | { 287 | return [self mcs_count:block] > 0; 288 | } 289 | 290 | - (BOOL)mcs_all:(BOOL (^)(id))block 291 | { 292 | return [self mcs_count:block] == [self count]; 293 | } 294 | 295 | - (NSArray *)mcs_reverse 296 | { 297 | return [[[self reverseObjectEnumerator] allObjects] copy]; 298 | } 299 | 300 | - (BOOL)mcs_hasAnyElement 301 | { 302 | return [self count] > 0; 303 | } 304 | 305 | - (id)mcs_sample 306 | { 307 | return [self mcs_hasAnyElement] ? self[arc4random_uniform((u_int32_t)[self count])] : nil; 308 | } 309 | 310 | - (NSArray *)mcs_rotate:(NSInteger)shift 311 | { 312 | shift = shift % (NSInteger)[self count]; 313 | shift = shift < 0 ? shift + (NSInteger)[self count] : shift; 314 | 315 | if (shift == 0) { 316 | return [self copy]; 317 | } 318 | 319 | NSRange leftRange = NSMakeRange([self count] - shift, shift); 320 | NSRange rightRange = NSMakeRange(0, [self count] - shift); 321 | 322 | NSArray *leftArray = [self subarrayWithRange:leftRange]; 323 | NSArray *rightArray = [self subarrayWithRange:rightRange]; 324 | 325 | return [leftArray arrayByAddingObjectsFromArray:rightArray]; 326 | } 327 | 328 | 329 | - (id)mcs_first:(id (^)(id))block 330 | { 331 | id resultObject; 332 | 333 | for (id object in self) { 334 | if (block(object)) { 335 | resultObject = object; 336 | break; 337 | } 338 | } 339 | 340 | return resultObject; 341 | } 342 | 343 | - (id)mcs_last:(id (^)(id))block 344 | { 345 | id resultObject; 346 | 347 | for (id object in [self reverseObjectEnumerator]) { 348 | if (block(object)) { 349 | resultObject = object; 350 | break; 351 | } 352 | } 353 | 354 | return resultObject; 355 | } 356 | 357 | #pragma mark - Sorting 358 | 359 | - (NSArray *)mcs_sort 360 | { 361 | return [self sortedArrayUsingSelector:@selector(compare:)]; 362 | } 363 | 364 | - (NSArray *)mcs_sortInDescendingOrder 365 | { 366 | return [[self mcs_sort] mcs_reverse]; 367 | } 368 | 369 | @end -------------------------------------------------------------------------------- /catagory/Classes/NSDictionary+MCSCollectionUtility.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+MCSCollectionUtility.h 3 | // MCSCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 15.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDictionary (MCSCollectionUtility) 12 | 13 | - (void)mcs_each:(void(^)(id key, id object))block; 14 | 15 | - (NSArray *)mcs_sortedKeysArray; 16 | - (NSArray *)mcs_sortedValuesArray; 17 | 18 | - (NSArray *)mcs_sortedKeysArray:(NSComparisonResult(^)(id key1, id key2))block; 19 | - (NSArray *)mcs_sortedValuesArray:(NSComparator)block; 20 | 21 | - (NSDictionary *)mcs_where:(BOOL(^)(id key, id object))block; 22 | 23 | - (NSInteger)mcs_count:(BOOL(^)(id key, id object))block; 24 | 25 | - (NSInteger)mcs_minInteger:(NSInteger(^)(id key, id object))block; 26 | - (CGFloat)mcs_minFloat:(CGFloat(^)(id key, id object))block; 27 | 28 | - (NSInteger)mcs_maxInteger:(NSInteger(^)(id key, id object))block; 29 | - (CGFloat)mcs_maxFloat:(CGFloat(^)(id key, id object))block; 30 | 31 | - (NSInteger)mcs_sumInteger:(NSInteger(^)(id key, id object))block; 32 | - (CGFloat)mcs_sumFloat:(CGFloat(^)(id key, id object))block; 33 | 34 | - (NSInteger)mcs_averageInteger:(NSInteger(^)(id key, id object))block; 35 | - (CGFloat)mcs_averageFloat:(CGFloat(^)(id key, id object))block; 36 | 37 | - (BOOL)mcs_single:(BOOL(^)(id key, id object))block; 38 | - (BOOL)mcs_any:(BOOL(^)(id key, id object))block; 39 | - (BOOL)mcs_all:(BOOL(^)(id key, id object))block; 40 | 41 | - (BOOL)mcs_hasAnyElement; 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /catagory/Classes/NSDictionary+MCSCollectionUtility.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+MCSCollectionUtility.m 3 | // MCSCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 15.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+MCSCollectionUtility.h" 10 | #import "NSArray+MCSCollectionUtility.h" 11 | 12 | @implementation NSDictionary (MCSCollectionUtility) 13 | 14 | - (void)mcs_each:(void (^)(id , id))block 15 | { 16 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 17 | block(key, obj); 18 | }]; 19 | } 20 | 21 | - (NSDictionary *)mcs_where:(BOOL (^)(id , id))block 22 | { 23 | NSMutableDictionary *resultDictionary = [[NSMutableDictionary alloc] init]; 24 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 25 | if (block(key, obj)) { 26 | resultDictionary[key] = obj; 27 | } 28 | }]; 29 | 30 | return [NSDictionary dictionaryWithDictionary:resultDictionary]; 31 | } 32 | 33 | - (NSArray *)mcs_sortedKeysArray 34 | { 35 | return [[self allKeys] mcs_sort]; 36 | } 37 | 38 | - (NSArray *)mcs_sortedKeysArray:(NSComparisonResult (^)(id key1, id key2))block 39 | { 40 | return [[self allKeys] sortedArrayUsingComparator:block]; 41 | } 42 | 43 | - (NSArray *)mcs_sortedValuesArray 44 | { 45 | return [[self allValues] mcs_sort]; 46 | } 47 | 48 | - (NSArray *)mcs_sortedValuesArray:(NSComparator)block 49 | { 50 | return [[self allValues] sortedArrayUsingComparator:block]; 51 | } 52 | 53 | - (NSInteger)mcs_count:(BOOL (^)(id , id))block 54 | { 55 | __block NSInteger counter = 0; 56 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 57 | if (block(key, obj)) { 58 | counter++; 59 | } 60 | }]; 61 | 62 | return counter; 63 | } 64 | 65 | - (NSInteger)mcs_minInteger:(NSInteger (^)(id , id))block 66 | { 67 | __block NSInteger min = NSIntegerMax; 68 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 69 | NSInteger evaluationResult = block(key, obj); 70 | if (evaluationResult < min) { 71 | min = evaluationResult; 72 | } 73 | }]; 74 | 75 | return min; 76 | } 77 | 78 | - (CGFloat)mcs_minFloat:(CGFloat (^)(id , id))block 79 | { 80 | __block CGFloat min = CGFLOAT_MAX; 81 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 82 | CGFloat evaluationResult = block(key, obj); 83 | if (evaluationResult < min) { 84 | min = evaluationResult; 85 | } 86 | }]; 87 | 88 | return min; 89 | } 90 | 91 | - (NSInteger)mcs_maxInteger:(NSInteger (^)(id , id))block 92 | { 93 | __block NSInteger max = NSIntegerMin; 94 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 95 | NSInteger evaluationResult = block(key, obj); 96 | if (evaluationResult > max) { 97 | max = evaluationResult; 98 | } 99 | }]; 100 | 101 | return max; 102 | } 103 | 104 | - (CGFloat)mcs_maxFloat:(CGFloat (^)(id , id))block 105 | { 106 | __block CGFloat max = CGFLOAT_MIN; 107 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 108 | CGFloat evaluationResult = block(key, obj); 109 | if (evaluationResult > max) { 110 | max = evaluationResult; 111 | } 112 | }]; 113 | 114 | return max; 115 | } 116 | 117 | - (NSInteger)mcs_sumInteger:(NSInteger (^)(id , id))block 118 | { 119 | __block NSInteger sum = 0; 120 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 121 | sum += block(key, obj); 122 | }]; 123 | 124 | return sum; 125 | } 126 | 127 | - (CGFloat)mcs_sumFloat:(CGFloat (^)(id , id))block 128 | { 129 | __block CGFloat sum = 0; 130 | [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 131 | sum += block(key, obj); 132 | }]; 133 | 134 | return sum; 135 | } 136 | 137 | - (NSInteger)mcs_averageInteger:(NSInteger (^)(id , id))block 138 | { 139 | return [self mcs_hasAnyElement] ? [self mcs_sumInteger:block]/[self count] : 0; 140 | } 141 | 142 | - (CGFloat)mcs_averageFloat:(CGFloat (^)(id , id))block 143 | { 144 | return [self mcs_hasAnyElement] ? [self mcs_sumFloat:block]/[self count] : 0.0; 145 | } 146 | 147 | - (BOOL)mcs_single:(BOOL (^)(id , id))block 148 | { 149 | return [self mcs_count:block] == 1; 150 | } 151 | 152 | - (BOOL)mcs_any:(BOOL (^)(id , id))block 153 | { 154 | return [self mcs_count:block] > 0; 155 | } 156 | 157 | - (BOOL)mcs_all:(BOOL (^)(id , id))block 158 | { 159 | return [self mcs_count:block] == [self count]; 160 | } 161 | 162 | - (BOOL)mcs_hasAnyElement 163 | { 164 | return [self count] > 0; 165 | } 166 | 167 | @end 168 | -------------------------------------------------------------------------------- /catagory/Classes/NSSet+MCSCollectionUtility.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSSet+MCSCollectionUtility.h 3 | // MCSCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 18.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSSet (MCSCollectionUtility) 12 | 13 | - (NSArray *)mcs_sort:(NSComparator)block; 14 | 15 | - (NSSet *)mcs_where:(BOOL(^)(id object))block; 16 | 17 | - (NSSet *)mcs_union:(NSSet *)set; 18 | - (NSSet *)mcs_union:(NSSet *)set comparator:(BOOL(^)(id obj1, id obj2))block; 19 | 20 | - (NSSet *)mcs_unique; 21 | - (NSSet *)mcs_unique:(BOOL(^)(id obj1, id obj2))block; 22 | 23 | - (NSSet *)mcs_select:(id(^)(id object))block; 24 | - (NSSet *)mcs_selectMany:(NSArray *(^)(id object))block; 25 | - (NSSet *)mcs_map:(id(^)(id object))block; 26 | 27 | - (void)mcs_each:(void(^)(id object))block; 28 | 29 | - (NSInteger)mcs_count:(BOOL(^)(id object))block; 30 | 31 | - (NSInteger)mcs_minInteger:(NSInteger(^)(id object))block; 32 | - (CGFloat)mcs_minFloat:(CGFloat(^)(id object))block; 33 | 34 | - (NSInteger)mcs_maxInteger:(NSInteger(^)(id object))block; 35 | - (CGFloat)mcs_maxFloat:(CGFloat(^)(id object))block; 36 | 37 | - (NSInteger)mcs_sumInteger:(NSInteger(^)(id object))block; 38 | - (CGFloat)mcs_sumFloat:(CGFloat(^)(id object))block; 39 | 40 | - (NSInteger)mcs_averageInteger:(NSInteger(^)(id object))block; 41 | - (CGFloat)mcs_averageFloat:(CGFloat(^)(id object))block; 42 | 43 | - (BOOL)mcs_single:(BOOL(^)(id object))block; 44 | - (BOOL)mcs_any:(BOOL(^)(id object))block; 45 | - (BOOL)mcs_all:(BOOL(^)(id object))block; 46 | 47 | - (BOOL)mcs_hasAnyElement; 48 | 49 | - (NSSet *)mcs_sample; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /catagory/Classes/NSSet+MCSCollectionUtility.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSSet+MCSCollectionUtility.m 3 | // MCSCollectionUtility 4 | // 5 | // Created by Rafał Augustyniak on 18.03.2014. 6 | // Copyright (c) 2014 Macoscope. All rights reserved. 7 | // 8 | 9 | #import "NSSet+MCSCollectionUtility.h" 10 | #import "NSArray+MCSCollectionUtility.h" 11 | 12 | @implementation NSSet (MCSCollectionUtility) 13 | 14 | 15 | - (NSArray *)mcs_sort:(NSComparator)block 16 | { 17 | NSArray *resultArray = [self allObjects]; 18 | return [resultArray sortedArrayUsingComparator:block]; 19 | } 20 | 21 | - (NSSet *)mcs_where:(BOOL (^)(id))block 22 | { 23 | NSArray *resultArray = [[self allObjects] mcs_where:block]; 24 | return [NSSet setWithArray:resultArray]; 25 | } 26 | 27 | - (NSSet *)mcs_union:(NSSet *)set 28 | { 29 | NSArray *resultArray = [[[self allObjects] mcs_union:[set allObjects]] mcs_unique]; 30 | return [NSSet setWithArray:resultArray]; 31 | } 32 | 33 | - (NSSet *)mcs_union:(NSSet *)set comparator:(BOOL(^)(id obj1, id obj2))block 34 | { 35 | NSArray *resultArray = [[self allObjects] mcs_union:[set allObjects] comparator:block]; 36 | return [NSSet setWithArray:resultArray]; 37 | } 38 | 39 | - (NSSet *)mcs_unique 40 | { 41 | NSArray *resultArray = [[self allObjects] mcs_unique]; 42 | return [NSSet setWithArray:resultArray]; 43 | } 44 | 45 | - (NSSet *)mcs_unique:(BOOL (^)(id, id))block 46 | { 47 | NSArray *resultArray = [[self allObjects] mcs_unique:block]; 48 | return [NSSet setWithArray:resultArray]; 49 | } 50 | 51 | - (NSSet *)mcs_select:(id (^)(id))block 52 | { 53 | NSArray *resultArray = [[self allObjects] mcs_select:block]; 54 | return [NSSet setWithArray:resultArray]; 55 | } 56 | 57 | - (NSSet *)mcs_selectMany:(NSArray *(^)(id))block 58 | { 59 | NSArray *resultArray = [[self allObjects] mcs_selectMany:block]; 60 | return [NSSet setWithArray:resultArray]; 61 | } 62 | 63 | - (NSSet *)mcs_map:(id (^)(id))block 64 | { 65 | NSArray *resultArray = [[self allObjects] mcs_map:block]; 66 | return [NSSet setWithArray:resultArray]; 67 | } 68 | 69 | - (void)mcs_each:(void (^)(id))block 70 | { 71 | [[self allObjects] mcs_each:block]; 72 | } 73 | 74 | - (NSInteger)mcs_count:(BOOL (^)(id))block 75 | { 76 | return [[self mcs_where:block] count]; 77 | } 78 | 79 | - (NSInteger)mcs_minInteger:(NSInteger (^)(id))block 80 | { 81 | return [[self allObjects] mcs_minInteger:block]; 82 | } 83 | 84 | - (CGFloat)mcs_minFloat:(CGFloat (^)(id))block 85 | { 86 | return [[self allObjects] mcs_minFloat:block]; 87 | } 88 | 89 | - (NSInteger)mcs_maxInteger:(NSInteger (^)(id))block 90 | { 91 | return [[self allObjects] mcs_maxInteger:block]; 92 | } 93 | 94 | - (CGFloat)mcs_maxFloat:(CGFloat (^)(id))block 95 | { 96 | return [[self allObjects] mcs_maxFloat:block]; 97 | } 98 | 99 | - (NSInteger)mcs_sumInteger:(NSInteger (^)(id))block 100 | { 101 | return [[self allObjects] mcs_sumInteger:block]; 102 | } 103 | 104 | - (CGFloat)mcs_sumFloat:(CGFloat (^)(id))block 105 | { 106 | return [[self allObjects] mcs_sumFloat:block]; 107 | } 108 | 109 | - (NSInteger)mcs_averageInteger:(NSInteger (^)(id))block 110 | { 111 | return [self mcs_hasAnyElement] ? [self mcs_sumInteger:block]/[self count] : 0; 112 | } 113 | 114 | - (CGFloat)mcs_averageFloat:(CGFloat (^)(id))block 115 | { 116 | return [self mcs_hasAnyElement] ? [self mcs_sumFloat:block]/[self count] : 0.0; 117 | } 118 | 119 | - (BOOL)mcs_single:(BOOL (^)(id))block 120 | { 121 | return [self mcs_count:block] == 1; 122 | } 123 | 124 | - (BOOL)mcs_any:(BOOL (^)(id))block 125 | { 126 | return [self mcs_count:block] > 0; 127 | } 128 | 129 | - (BOOL)mcs_all:(BOOL (^)(id))block 130 | { 131 | return [self mcs_count:block] == [self count]; 132 | } 133 | 134 | - (BOOL)mcs_hasAnyElement 135 | { 136 | return [self count] > 0; 137 | } 138 | 139 | - (NSSet *)mcs_sample 140 | { 141 | return [[self allObjects] mcs_sample]; 142 | } 143 | 144 | @end 145 | -------------------------------------------------------------------------------- /catagory/DES3Util.h: -------------------------------------------------------------------------------- 1 | // 2 | // DES3Util.h 3 | // bluetoothTest 4 | // 5 | // Created by 刘平伟 on 14-1-10. 6 | // Copyright (c) 2014年 刘平伟. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DES3Util : NSObject 12 | // 加密方法 13 | + (NSString*)encrypt:(NSString*)plainText; 14 | 15 | // 解密方法 16 | + (NSString*)decrypt:(NSString*)encryptText; 17 | @end 18 | -------------------------------------------------------------------------------- /catagory/DES3Util.m: -------------------------------------------------------------------------------- 1 | // 2 | // DES3Util.m 3 | // bluetoothTest 4 | // 5 | // Created by 刘平伟 on 14-1-10. 6 | // Copyright (c) 2014年 刘平伟. All rights reserved. 7 | // 8 | 9 | #import "DES3Util.h" 10 | 11 | #import 12 | #import "GTMBase64.h" 13 | 14 | #define gkey @"894D94361A243577F0A497C4EAB6462A178900022D1D95B2EAE04" 15 | #define gIv @"01234567" 16 | 17 | @implementation DES3Util 18 | 19 | // 加密方法 20 | + (NSString*)encrypt:(NSString*)plainText { 21 | NSData* data = [plainText dataUsingEncoding:NSUTF8StringEncoding]; 22 | size_t plainTextBufferSize = [data length]; 23 | const void *vplainText = (const void *)[data bytes]; 24 | 25 | CCCryptorStatus ccStatus; 26 | uint8_t *bufferPtr = NULL; 27 | size_t bufferPtrSize = 0; 28 | size_t movedBytes = 0; 29 | 30 | bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1); 31 | bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t)); 32 | memset((void *)bufferPtr, 0x0, bufferPtrSize); 33 | 34 | const void *vkey = (const void *) [gkey UTF8String]; 35 | const void *vinitVec = (const void *) [gIv UTF8String]; 36 | 37 | ccStatus = CCCrypt(kCCEncrypt, 38 | kCCAlgorithm3DES, 39 | kCCOptionPKCS7Padding, 40 | vkey, 41 | kCCKeySize3DES, 42 | vinitVec, 43 | vplainText, 44 | plainTextBufferSize, 45 | (void *)bufferPtr, 46 | bufferPtrSize, 47 | &movedBytes); 48 | 49 | NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes]; 50 | NSString *result = [GTMBase64 stringByEncodingData:myData]; 51 | free(bufferPtr); 52 | return result; 53 | } 54 | 55 | // 解密方法 56 | + (NSString*)decrypt:(NSString*)encryptText { 57 | NSData *encryptData = [GTMBase64 decodeData:[encryptText dataUsingEncoding:NSUTF8StringEncoding]]; 58 | size_t plainTextBufferSize = [encryptData length]; 59 | const void *vplainText = [encryptData bytes]; 60 | 61 | CCCryptorStatus ccStatus; 62 | uint8_t *bufferPtr = NULL; 63 | size_t bufferPtrSize = 0; 64 | size_t movedBytes = 0; 65 | 66 | bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1); 67 | bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t)); 68 | memset((void *)bufferPtr, 0x0, bufferPtrSize); 69 | 70 | const void *vkey = (const void *) [gkey UTF8String]; 71 | const void *vinitVec = (const void *) [gIv UTF8String]; 72 | 73 | ccStatus = CCCrypt(kCCDecrypt, 74 | kCCAlgorithm3DES, 75 | kCCOptionPKCS7Padding, 76 | vkey, 77 | kCCKeySize3DES, 78 | vinitVec, 79 | vplainText, 80 | plainTextBufferSize, 81 | (void *)bufferPtr, 82 | bufferPtrSize, 83 | &movedBytes); 84 | 85 | NSString *result = [[[NSString alloc] initWithData:[NSData dataWithBytes:(const void *)bufferPtr 86 | length:(NSUInteger)movedBytes] encoding:NSUTF8StringEncoding] autorelease]; 87 | free(bufferPtr); 88 | return result; 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /catagory/NSArray+SLExt.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+SLExt.h 3 | // BodyScaleProduction 4 | // 5 | // Created by Go Salo on 14-3-17. 6 | // Copyright (c) 2014年 Go Salo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (SLExt) 12 | 13 | - (id)firstObject; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /catagory/NSArray+SLExt.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+SLExt.m 3 | // BodyScaleProduction 4 | // 5 | // Created by Go Salo on 14-3-17. 6 | // Copyright (c) 2014年 Go Salo. All rights reserved. 7 | // 8 | 9 | #import "NSArray+SLExt.h" 10 | 11 | @implementation NSArray (SLExt) 12 | 13 | - (id)firstObject { 14 | if (self.count > 0) { 15 | return self[0]; 16 | } else { 17 | return nil; 18 | } 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /catagory/NSDate+SLExtend.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+SLExtend.h 3 | // schoolfellow 4 | // 5 | // Created by EasyitsApp on 14-1-4. 6 | // Copyright (c) 2014年 www.easyits.net. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDate (SLExtend) 12 | 13 | // 判断是否是本周更早 14 | - (BOOL)isThisWeekEarlier; 15 | // 判断是否是本周晚些 16 | - (BOOL)isThisWeekLater; 17 | // 判断是否是下一周或者更远 18 | - (BOOL)isNextWeekOrLater; 19 | // 判断是否是上一周或者更早 20 | - (BOOL)isLastWeekOrEarlier; 21 | // 判断是否是昨天或更早 22 | - (BOOL)isYesterdayOrEarlier; 23 | // 判断是否是明天或更晚 24 | - (BOOL)isTomorrowOrLater; 25 | // 判断是否是前天 26 | - (BOOL)isTheDayBeforeYesterday; 27 | // 判断是否是昨天 28 | - (BOOL)isYesterDay; 29 | // 判断是否是今天 30 | - (BOOL)isToday; 31 | // 判断是否是明天 32 | - (BOOL)isTomorrow; 33 | // 判断是否是后天 34 | - (BOOL)isTheDayAfterTomorrow; 35 | 36 | // 转换成年月日(其他补0) 37 | - (NSDate *)convertDefinitionToDate; 38 | // 转换标准时间 39 | - (NSString *)convertToStandardDateFormat; 40 | // 转换本星期标准时间 41 | - (NSString *)convertToStandardThisWeekDateFormat; 42 | // 转换成标准前天、昨天、今天、明天、后天时间 43 | - (NSString *)convertToStandardRecentlyDateFormat; 44 | // 转换成时间 45 | - (NSString *)convertToStandardTimeDateFormat; 46 | // 转换成标准时间(不带星期) 47 | - (NSString *)convertToStandardNormalDateFormat; 48 | // 转换成YYYY-MM-DD HH:MM:SS格式时间 49 | - (NSString *)convertToStandardYYYYMMDDHHMMSSDateFormat; 50 | // 转换成YYYY-MM-DD 51 | - (NSString *)convertToStandardYYYYMMDDDateFormat; 52 | // 转换成YYYYMMDDHHMMSS 53 | - (NSString *)convertToYYYYMMDDHHMMSSDateFormat; 54 | 55 | // 指定日期是星期几,1表示一周的第一天周日 56 | + (NSInteger)weekdayByDate:(NSDate *)date; 57 | + (NSString *)weekdayInChineseByDate:(NSDate *)date; 58 | 59 | // 指定时间往前推多少天 60 | + (NSDate *)dateWithDays:(NSUInteger)days beforDate:(NSDate *)date; 61 | + (NSDate *)dateWithDays:(NSUInteger)days afterDate:(NSDate *)date; 62 | 63 | // 获取某个时间点前多少天的总集合 64 | + (NSArray *)dayNamesAtDays:(NSInteger)days beforDate:(NSDate *)date; 65 | 66 | // 获取年 67 | + (NSInteger)yearByDate:(NSDate *)date; 68 | 69 | // 获取月 70 | + (NSInteger)monthByDate:(NSDate *)date; 71 | 72 | // 获取日 73 | + (NSInteger)dayByDate:(NSDate *)date; 74 | 75 | // 该日期处于一年中的第几周 76 | + (NSInteger)weekOfYearByDate:(NSDate *)date; 77 | 78 | //获取当前的时间HH:mm 79 | + (NSString *)getCurrentDateHHMM; 80 | 81 | // 该月有多少天 82 | + (NSUInteger)daysInMonthByDate:(NSDate *)date; 83 | 84 | + (NSString *)convertToyyyMMddHHmmssString:(NSDate *)date; 85 | 86 | 87 | 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /catagory/NSDate+SLExtend.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+SLExtend.m 3 | // schoolfellow 4 | // 5 | // Created by EasyitsApp on 14-1-4. 6 | // Copyright (c) 2014年 www.easyits.net. All rights reserved. 7 | // 8 | 9 | #import "NSDate+SLExtend.h" 10 | 11 | @implementation NSDate (SLExtend) 12 | 13 | - (NSDate *)dateStartOfWeek 14 | { 15 | NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 16 | 17 | [gregorian setFirstWeekday:2]; //monday is first day 18 | 19 | NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:self]; 20 | 21 | NSDateComponents *componentsToSubtract = [[NSDateComponents alloc] init]; 22 | 23 | [componentsToSubtract setDay: - ((([components weekday] - [gregorian firstWeekday]) + 7 ) % 7)]; 24 | 25 | NSDate *beginningOfWeek = [gregorian dateByAddingComponents:componentsToSubtract toDate:self options:0]; 26 | 27 | NSDateComponents *componentsStripped = [gregorian components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate: beginningOfWeek]; 28 | 29 | beginningOfWeek = [gregorian dateFromComponents: componentsStripped]; 30 | 31 | return beginningOfWeek; 32 | } 33 | 34 | // ================================ 扩展 =========================== 35 | // 判断是否是昨天或更早 36 | - (BOOL)isYesterdayOrEarlier 37 | { 38 | NSDate *yesterdayDefintionDate = [NSDate dateWithTimeIntervalSinceNow:-60 * 60 * 24]; 39 | NSDate *definitionDate = [self convertDefinitionToDate]; 40 | if ([yesterdayDefintionDate isEqualToDate:definitionDate]) { 41 | return YES; 42 | } 43 | 44 | NSDate *earlierDate = [definitionDate earlierDate:[NSDate date]]; 45 | if (earlierDate == self) { 46 | return YES; 47 | } 48 | return NO; 49 | } 50 | 51 | // 判断是否是明天或更晚 52 | - (BOOL)isTomorrowOrLater 53 | { 54 | NSDate *tomorrowDefintionDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24]; 55 | NSDate *definitionDate = [self convertDefinitionToDate]; 56 | if ([tomorrowDefintionDate isEqualToDate:definitionDate]) { 57 | return YES; 58 | } 59 | 60 | NSDate *laterDate = [definitionDate laterDate:tomorrowDefintionDate]; 61 | if (laterDate == self) { 62 | return YES; 63 | } 64 | return NO; 65 | } 66 | // ================================================================= 67 | 68 | // 判断是否是下一周或者更远 69 | - (BOOL)isNextWeekOrLater 70 | { 71 | if (![self isThisWeek]) { 72 | NSDate *laterDate = [self laterDate:[NSDate date]]; 73 | if (laterDate == self) { 74 | return YES; 75 | } 76 | } 77 | return NO; 78 | } 79 | 80 | // 判断是否是上一周或者更早 81 | - (BOOL)isLastWeekOrEarlier 82 | { 83 | if (![self isThisWeek]) { 84 | NSDate *earlierDate = [self earlierDate:[NSDate date]]; 85 | if (earlierDate == self) { 86 | return YES; 87 | } 88 | } 89 | return NO; 90 | } 91 | 92 | // 判断是否是本周 93 | - (BOOL)isThisWeek 94 | { 95 | NSDate *thisWeekStartDay = [[NSDate date] dateStartOfWeek]; 96 | if ([thisWeekStartDay isEqualToDate:[self dateStartOfWeek]]) { 97 | return YES; 98 | } 99 | return NO; 100 | } 101 | 102 | // 判断是否是本周更早 103 | - (BOOL)isThisWeekEarlier 104 | { 105 | if ([self isThisWeek]) { 106 | NSDate *earlierDate = [self earlierDate:[NSDate date]]; 107 | if (earlierDate == self) { 108 | return YES; 109 | } 110 | } 111 | return NO; 112 | } 113 | 114 | // 判断是否是本周晚些 115 | - (BOOL)isThisWeekLater 116 | { 117 | if ([self isThisWeek]) { 118 | NSDate *laterDate = [self laterDate:[NSDate date]]; 119 | if (laterDate == self) { 120 | return YES; 121 | } 122 | } 123 | return NO; 124 | } 125 | 126 | // 判断是否是前天 127 | - (BOOL)isTheDayBeforeYesterday 128 | { 129 | NSCalendar *cal = [NSCalendar currentCalendar]; 130 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 131 | | NSYearCalendarUnit 132 | | NSMonthCalendarUnit 133 | | NSDayCalendarUnit); 134 | 135 | NSDateComponents *components = [cal components:calendarUnit fromDate:[NSDate dateWithTimeIntervalSinceNow:-60 * 60 * 24 * 2]]; 136 | NSDate *dayAfterTomorrow = [cal dateFromComponents:components]; 137 | 138 | components = [cal components:calendarUnit fromDate:self]; 139 | NSDate *otherDate = [cal dateFromComponents:components]; 140 | 141 | if([dayAfterTomorrow isEqualToDate:otherDate]) { 142 | return YES; 143 | } 144 | return NO; 145 | } 146 | 147 | // 判断是否是昨天 148 | - (BOOL)isYesterDay 149 | { 150 | NSCalendar *cal = [NSCalendar currentCalendar]; 151 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 152 | | NSYearCalendarUnit 153 | | NSMonthCalendarUnit 154 | | NSDayCalendarUnit); 155 | 156 | NSDateComponents *components = [cal components:calendarUnit fromDate:[NSDate dateWithTimeIntervalSinceNow:-60 * 60 * 24]]; 157 | NSDate *today = [cal dateFromComponents:components]; 158 | 159 | components = [cal components:calendarUnit fromDate:self]; 160 | NSDate *otherDate = [cal dateFromComponents:components]; 161 | 162 | if([today isEqualToDate:otherDate]) { 163 | return YES; 164 | } 165 | return NO; 166 | } 167 | 168 | // 判断是否是今天 169 | - (BOOL)isToday 170 | { 171 | NSCalendar *cal = [NSCalendar currentCalendar]; 172 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 173 | | NSYearCalendarUnit 174 | | NSMonthCalendarUnit 175 | | NSDayCalendarUnit); 176 | 177 | NSDateComponents *components = [cal components:calendarUnit fromDate:[NSDate date]]; 178 | NSDate *today = [cal dateFromComponents:components]; 179 | 180 | components = [cal components:calendarUnit fromDate:self]; 181 | NSDate *otherDate = [cal dateFromComponents:components]; 182 | 183 | if([today isEqualToDate:otherDate]) { 184 | return YES; 185 | } 186 | return NO; 187 | } 188 | 189 | // 判断是否是明天 190 | - (BOOL)isTomorrow 191 | { 192 | NSCalendar *cal = [NSCalendar currentCalendar]; 193 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 194 | | NSYearCalendarUnit 195 | | NSMonthCalendarUnit 196 | | NSDayCalendarUnit); 197 | 198 | NSDateComponents *components = [cal components:calendarUnit fromDate:[NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24]]; 199 | NSDate *tomorrow = [cal dateFromComponents:components]; 200 | 201 | components = [cal components:calendarUnit fromDate:self]; 202 | NSDate *otherDate = [cal dateFromComponents:components]; 203 | 204 | if([tomorrow isEqualToDate:otherDate]) { 205 | return YES; 206 | } 207 | return NO; 208 | } 209 | 210 | // 判断是否是后天 211 | - (BOOL)isTheDayAfterTomorrow 212 | { 213 | NSCalendar *cal = [NSCalendar currentCalendar]; 214 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 215 | | NSYearCalendarUnit 216 | | NSMonthCalendarUnit 217 | | NSDayCalendarUnit); 218 | 219 | NSDateComponents *components = [cal components:calendarUnit fromDate:[NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * 2]]; 220 | NSDate *dayAfterTomorrow = [cal dateFromComponents:components]; 221 | 222 | components = [cal components:calendarUnit fromDate:self]; 223 | NSDate *otherDate = [cal dateFromComponents:components]; 224 | 225 | if([dayAfterTomorrow isEqualToDate:otherDate]) { 226 | return YES; 227 | } 228 | return NO; 229 | } 230 | 231 | // 转换成年月日(其他补0) 232 | - (NSDate *)convertDefinitionToDate 233 | { 234 | NSCalendar *cal = [NSCalendar currentCalendar]; 235 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 236 | | NSYearCalendarUnit 237 | | NSMonthCalendarUnit 238 | | NSDayCalendarUnit); 239 | 240 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 241 | NSDate *dateConverted = [cal dateFromComponents:components]; 242 | return dateConverted; 243 | } 244 | 245 | // 转换标准时间 246 | - (NSString *)convertToStandardDateFormat 247 | { 248 | // eg: 2014-01-03 19:36 星期五 249 | NSCalendar *cal = [NSCalendar currentCalendar]; 250 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 251 | | NSYearCalendarUnit 252 | | NSMonthCalendarUnit 253 | | NSDayCalendarUnit 254 | | NSCalendarUnitWeekday 255 | | NSCalendarUnitHour 256 | | NSCalendarUnitMinute 257 | | NSCalendarUnitSecond); 258 | 259 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 260 | NSInteger year = [components year]; 261 | NSInteger month = [components month]; 262 | NSInteger day = [components day]; 263 | NSInteger hour = [components hour]; 264 | NSInteger minute = [components minute]; 265 | NSInteger weekday = [components weekday]; 266 | 267 | NSString *weekdayStr = nil; 268 | switch (weekday) { 269 | case 1: 270 | weekdayStr = @"星期日"; 271 | break; 272 | case 2: 273 | weekdayStr = @"星期一"; 274 | break; 275 | case 3: 276 | weekdayStr = @"星期二"; 277 | break; 278 | case 4: 279 | weekdayStr = @"星期三"; 280 | break; 281 | case 5: 282 | weekdayStr = @"星期四"; 283 | break; 284 | case 6: 285 | weekdayStr = @"星期五"; 286 | break; 287 | case 7: 288 | weekdayStr = @"星期六"; 289 | break; 290 | default: 291 | break; 292 | } 293 | NSString *standardDateFormatStr = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d %@", (int)year, (int)month, (int)day, (int)hour, (int)minute, weekdayStr]; 294 | return standardDateFormatStr; 295 | } 296 | 297 | // 转换本星期标准时间 298 | - (NSString *)convertToStandardThisWeekDateFormat 299 | { 300 | NSCalendar *cal = [NSCalendar currentCalendar]; 301 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 302 | | NSYearCalendarUnit 303 | | NSMonthCalendarUnit 304 | | NSDayCalendarUnit 305 | | NSCalendarUnitWeekday 306 | | NSCalendarUnitHour 307 | | NSCalendarUnitMinute 308 | | NSCalendarUnitSecond); 309 | 310 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 311 | NSInteger hour = [components hour]; 312 | NSInteger minute = [components minute]; 313 | NSInteger weekday = [components weekday]; 314 | 315 | NSString *weekdayStr = nil; 316 | switch (weekday) { 317 | case 1: 318 | weekdayStr = @"星期日"; 319 | break; 320 | case 2: 321 | weekdayStr = @"星期一"; 322 | break; 323 | case 3: 324 | weekdayStr = @"星期二"; 325 | break; 326 | case 4: 327 | weekdayStr = @"星期三"; 328 | break; 329 | case 5: 330 | weekdayStr = @"星期四"; 331 | break; 332 | case 6: 333 | weekdayStr = @"星期五"; 334 | break; 335 | case 7: 336 | weekdayStr = @"星期六"; 337 | break; 338 | default: 339 | return nil; 340 | break; 341 | } 342 | 343 | NSString *standardThisWeekDateFormatStr = [NSString stringWithFormat:@"%@ %02d:%02d", weekdayStr, (int)hour, (int)minute]; 344 | return standardThisWeekDateFormatStr; 345 | } 346 | 347 | - (NSString *)convertToStandardTimeDateFormat 348 | { 349 | NSCalendar *cal = [NSCalendar currentCalendar]; 350 | NSCalendarUnit calendarUnit = ( NSCalendarUnitHour 351 | | NSCalendarUnitMinute); 352 | 353 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 354 | NSInteger hour = [components hour]; 355 | NSInteger minute = [components minute]; 356 | 357 | NSString *timeDateFormatStr = [NSString stringWithFormat:@"%02d:%02d", (int)hour, (int)minute]; 358 | return timeDateFormatStr; 359 | } 360 | 361 | - (NSString *)convertToStandardNormalDateFormat 362 | { 363 | NSCalendar *cal = [NSCalendar currentCalendar]; 364 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 365 | | NSYearCalendarUnit 366 | | NSMonthCalendarUnit 367 | | NSDayCalendarUnit 368 | | NSCalendarUnitWeekday 369 | | NSCalendarUnitHour 370 | | NSCalendarUnitMinute 371 | | NSCalendarUnitSecond); 372 | 373 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 374 | NSInteger year = [components year]; 375 | NSInteger month = [components month]; 376 | NSInteger day = [components day]; 377 | NSInteger hour = [components hour]; 378 | NSInteger minute = [components minute]; 379 | 380 | NSString *dateFormatStr = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d", (int)year, (int)month, (int)day, (int)hour, (int)minute]; 381 | return dateFormatStr; 382 | } 383 | 384 | // 转换成YYYY-MM-DD HH:MM:SS格式时间 385 | - (NSString *)convertToStandardYYYYMMDDHHMMSSDateFormat 386 | { 387 | NSCalendar *cal = [NSCalendar currentCalendar]; 388 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 389 | | NSYearCalendarUnit 390 | | NSMonthCalendarUnit 391 | | NSDayCalendarUnit 392 | | NSCalendarUnitWeekday 393 | | NSCalendarUnitHour 394 | | NSCalendarUnitMinute 395 | | NSCalendarUnitSecond); 396 | 397 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 398 | NSInteger year = [components year]; 399 | NSInteger month = [components month]; 400 | NSInteger day = [components day]; 401 | NSInteger hour = [components hour]; 402 | NSInteger minute = [components minute]; 403 | NSInteger second = [components second]; 404 | 405 | NSString *standardDateFormatStr = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d", (int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second]; 406 | return standardDateFormatStr; 407 | } 408 | 409 | - (NSString *)convertToYYYYMMDDHHMMSSDateFormat { 410 | NSCalendar *cal = [NSCalendar currentCalendar]; 411 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 412 | | NSYearCalendarUnit 413 | | NSMonthCalendarUnit 414 | | NSDayCalendarUnit 415 | | NSCalendarUnitWeekday 416 | | NSCalendarUnitHour 417 | | NSCalendarUnitMinute 418 | | NSCalendarUnitSecond); 419 | 420 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 421 | NSInteger year = [components year]; 422 | NSInteger month = [components month]; 423 | NSInteger day = [components day]; 424 | NSInteger hour = [components hour]; 425 | NSInteger minute = [components minute]; 426 | NSInteger second = [components second]; 427 | 428 | NSString *standardDateFormatStr = [NSString stringWithFormat:@"%04d%02d%02d%02d%02d%02d", (int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second]; 429 | return standardDateFormatStr; 430 | } 431 | 432 | // 转换成YYYY-MM-DD 433 | - (NSString *)convertToStandardYYYYMMDDDateFormat 434 | { 435 | NSCalendar *cal = [NSCalendar currentCalendar]; 436 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 437 | | NSYearCalendarUnit 438 | | NSMonthCalendarUnit 439 | | NSDayCalendarUnit 440 | | NSCalendarUnitWeekday 441 | | NSCalendarUnitHour 442 | | NSCalendarUnitMinute 443 | | NSCalendarUnitSecond); 444 | 445 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 446 | NSInteger year = [components year]; 447 | NSInteger month = [components month]; 448 | NSInteger day = [components day]; 449 | 450 | NSString *standardDateFormatStr = [NSString stringWithFormat:@"%04d-%02d-%02d", (int)year, (int)month, (int)day]; 451 | return standardDateFormatStr; 452 | } 453 | 454 | // 转换成标准前天、昨天、今天、明天、后天时间 今天 19:36 455 | - (NSString *)convertToStandardRecentlyDateFormat 456 | { 457 | NSString *dateStr = nil; 458 | if ([self isToday]) { 459 | dateStr = @"今天"; 460 | } else if ([self isTomorrow]) { 461 | dateStr = @"明天"; 462 | } else if ([self isTheDayAfterTomorrow]) { 463 | dateStr = @"后天"; 464 | } else if ([self isYesterDay]) { 465 | dateStr = @"昨天"; 466 | } else if ([self isTheDayBeforeYesterday]) { 467 | dateStr = @"前天"; 468 | } else { 469 | NSLog(@"类型错误:%s", __FUNCTION__); 470 | return nil; 471 | } 472 | 473 | NSCalendar *cal = [NSCalendar currentCalendar]; 474 | NSCalendarUnit calendarUnit = ( NSCalendarUnitHour 475 | | NSCalendarUnitMinute); 476 | 477 | NSDateComponents *components = [cal components:calendarUnit fromDate:self]; 478 | NSInteger hour = [components hour]; 479 | NSInteger minute = [components minute]; 480 | 481 | NSString *todayDateFormatStr = [NSString stringWithFormat:@"%@ %02d:%02d", dateStr, (int)hour, (int)minute]; 482 | return todayDateFormatStr; 483 | } 484 | 485 | + (NSDateComponents *)dateComponentsByDate:(NSDate *)date { 486 | NSCalendar *calendar = [NSCalendar currentCalendar]; 487 | NSCalendarUnit calendarUnit = NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit | NSWeekOfYearCalendarUnit; 488 | return [calendar components:calendarUnit fromDate:date]; 489 | } 490 | 491 | + (NSInteger)weekdayByDate:(NSDate *)date { 492 | return [[self dateComponentsByDate:date] weekday]; 493 | } 494 | 495 | + (NSString *)weekdayInChineseByDate:(NSDate *)date { 496 | NSString *name = nil; 497 | NSInteger weekday = [NSDate weekdayByDate:date]; 498 | switch (weekday) { 499 | case 1: 500 | name = @"周日"; 501 | break; 502 | case 2: 503 | name = @"周一"; 504 | break; 505 | case 3: 506 | name = @"周二"; 507 | break; 508 | case 4: 509 | name = @"周三"; 510 | break; 511 | case 5: 512 | name = @"周四"; 513 | break; 514 | case 6: 515 | name = @"周五"; 516 | break; 517 | case 7: 518 | name = @"周六"; 519 | break; 520 | default: 521 | break; 522 | } 523 | return name; 524 | } 525 | 526 | + (NSDate *)dateWithDays:(NSUInteger)days beforDate:(NSDate *)date { 527 | NSTimeInterval interval = [date timeIntervalSinceReferenceDate] - 86400 * days; 528 | return [NSDate dateWithTimeIntervalSinceReferenceDate:interval]; 529 | } 530 | 531 | + (NSDate *)dateWithDays:(NSUInteger)days afterDate:(NSDate *)date { 532 | NSTimeInterval interval = [date timeIntervalSinceReferenceDate] + 86400 * days; 533 | return [NSDate dateWithTimeIntervalSinceReferenceDate:interval]; 534 | } 535 | 536 | + (NSArray *)dayNamesAtDays:(NSInteger)days beforDate:(NSDate *)date { 537 | NSMutableArray *names = [NSMutableArray array]; 538 | NSInteger currentMonthDay = [NSDate dayByDate:date]; 539 | 540 | for (int i = (int)days - 1; i >= currentMonthDay ; i--) { 541 | NSDate *date = [NSDate dateWithDays:i beforDate:[NSDate date]]; 542 | NSInteger day = [NSDate dayByDate:date]; 543 | [names addObject:[NSString stringWithFormat:@"%d", (int)day]]; 544 | } 545 | 546 | for (int i = (int)currentMonthDay - 1; i >= 0; i--) { 547 | NSDate *date = [NSDate dateWithDays:i beforDate:[NSDate date]]; 548 | NSInteger day = [NSDate dayByDate:date]; 549 | [names addObject:[NSString stringWithFormat:@"%d", (int)day]]; 550 | } 551 | return names; 552 | } 553 | 554 | + (NSInteger)yearByDate:(NSDate *)date { 555 | return [[self dateComponentsByDate:date] year]; 556 | } 557 | 558 | + (NSInteger)monthByDate:(NSDate *)date { 559 | return [[self dateComponentsByDate:date] month]; 560 | } 561 | 562 | + (NSInteger)dayByDate:(NSDate *)date { 563 | return [[self dateComponentsByDate:date] day]; 564 | } 565 | 566 | + (NSInteger)weekOfYearByDate:(NSDate *)date { 567 | return [[self dateComponentsByDate:date] weekOfYear]; 568 | } 569 | 570 | +(NSString *)getCurrentDateHHMM 571 | { 572 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 573 | [formatter setDateFormat:@"HH:mm"]; 574 | return [formatter stringFromDate:[NSDate date]]; 575 | } 576 | 577 | + (NSUInteger)daysInMonthByDate:(NSDate *)date { 578 | NSRange dayRange = [[NSCalendar currentCalendar] rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:date]; 579 | return dayRange.length; 580 | } 581 | 582 | + (NSString *)convertToyyyMMddHHmmssString:(NSDate *)date { 583 | NSCalendar *cal = [NSCalendar currentCalendar]; 584 | NSCalendarUnit calendarUnit = ( NSEraCalendarUnit 585 | | NSYearCalendarUnit 586 | | NSMonthCalendarUnit 587 | | NSDayCalendarUnit 588 | | NSCalendarUnitWeekday 589 | | NSCalendarUnitHour 590 | | NSCalendarUnitMinute 591 | | NSCalendarUnitSecond); 592 | 593 | NSDateComponents *components = [cal components:calendarUnit fromDate:date]; 594 | NSInteger year = [components year]; 595 | NSInteger month = [components month]; 596 | NSInteger day = [components day]; 597 | NSInteger hour = [components hour]; 598 | NSInteger minute = [components minute]; 599 | NSInteger second = [components second]; 600 | 601 | NSString *dateFormatStr = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d", (int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second]; 602 | return dateFormatStr; 603 | } 604 | 605 | 606 | 607 | 608 | 609 | 610 | @end 611 | -------------------------------------------------------------------------------- /catagory/NSObject+HUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+HUD.h 3 | // iChrono365 4 | // 5 | // Created by 刘平伟 on 14-1-14. 6 | // Copyright (c) 2014年 刘平伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MBProgressHUD.h" 11 | 12 | @interface NSObject (HUD) 13 | 14 | -(void)showHUDInWindowWithText:(NSString *)text; 15 | -(void)disMissHUDWithText:(NSString *)text afterDelay:(NSTimeInterval)inteval; 16 | 17 | -(void)showHUDInWindowJustWithText:(NSString *)text; 18 | -(void)showHUDInWindowJustWithText:(NSString *)text disMissAfterDelay:(NSTimeInterval)interval; 19 | 20 | -(void)showHUDInView:(UIView *)view WithText:(NSString *)text; 21 | -(void)showHUDInView:(UIView *)view WithText:(NSString *)text dismissAfterDelay:(NSTimeInterval)interval; 22 | -(void)showHUDInView:(UIView *)view justWithText:(NSString *)text; 23 | -(void)showHUDInView:(UIView *)view justWithText:(NSString *)text disMissAfterDelay:(NSTimeInterval)interval; 24 | 25 | -(void)showHUDWithCustomView:(UIView *)customView inView:(UIView *)view; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /catagory/NSObject+HUD.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+HUD.m 3 | // iChrono365 4 | // 5 | // Created by 刘平伟 on 14-1-14. 6 | // Copyright (c) 2014年 刘平伟. All rights reserved. 7 | // 8 | 9 | #import "NSObject+HUD.h" 10 | 11 | MBProgressHUD *__HUD = nil; 12 | 13 | #define KeyWindow [[UIApplication sharedApplication] keyWindow] 14 | 15 | @implementation NSObject (HUD) 16 | 17 | -(void)showHUDInWindowWithText:(NSString *)text 18 | { 19 | MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithWindow:KeyWindow]; 20 | HUD.removeFromSuperViewOnHide = YES; 21 | [KeyWindow addSubview:HUD]; 22 | __HUD = HUD; 23 | if (text) { 24 | __HUD.labelText = text; 25 | } 26 | [__HUD show:YES]; 27 | } 28 | 29 | -(void)disMissHUDWithText:(NSString *)text afterDelay:(NSTimeInterval)inteval 30 | { 31 | if (text) { 32 | __HUD.labelText = text; 33 | } 34 | [__HUD hide:YES afterDelay:inteval]; 35 | } 36 | 37 | -(void)showHUDInWindowJustWithText:(NSString *)text 38 | { 39 | MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithWindow:KeyWindow]; 40 | HUD.removeFromSuperViewOnHide = YES; 41 | HUD.customView = [[UILabel alloc] init]; 42 | HUD.removeFromSuperViewOnHide = YES; 43 | HUD.mode = MBProgressHUDModeCustomView; 44 | [KeyWindow addSubview:HUD]; 45 | __HUD = HUD; 46 | if (text) { 47 | __HUD.labelText = text; 48 | } 49 | [__HUD show:YES]; 50 | } 51 | 52 | -(void)showHUDInWindowJustWithText:(NSString *)text disMissAfterDelay:(NSTimeInterval)interval 53 | { 54 | [self showHUDInWindowJustWithText:text]; 55 | [self disMissHUDWithText:nil afterDelay:interval]; 56 | } 57 | 58 | -(void)showHUDInView:(UIView *)view WithText:(NSString *)text 59 | { 60 | MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view]; 61 | HUD.removeFromSuperViewOnHide = YES; 62 | [view addSubview:HUD]; 63 | __HUD = HUD; 64 | if (text) { 65 | __HUD.labelText = text; 66 | } 67 | [__HUD show:YES]; 68 | } 69 | 70 | -(void)showHUDInView:(UIView *)view WithText:(NSString *)text dismissAfterDelay:(NSTimeInterval)interval 71 | { 72 | [self showHUDInView:view WithText:text]; 73 | [self disMissHUDWithText:nil afterDelay:interval]; 74 | } 75 | 76 | -(void)showHUDInView:(UIView *)view justWithText:(NSString *)text 77 | { 78 | MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view]; 79 | HUD.removeFromSuperViewOnHide = YES; 80 | HUD.customView = [[UILabel alloc] init]; 81 | HUD.mode = MBProgressHUDModeCustomView; 82 | HUD.removeFromSuperViewOnHide = YES; 83 | [view addSubview:HUD]; 84 | __HUD = HUD; 85 | if (text) { 86 | __HUD.labelText = text; 87 | } 88 | [__HUD show:YES]; 89 | } 90 | 91 | -(void)showHUDInView:(UIView *)view justWithText:(NSString *)text disMissAfterDelay:(NSTimeInterval)interval 92 | { 93 | [self showHUDInView:view justWithText:text]; 94 | [self disMissHUDWithText:nil afterDelay:interval]; 95 | } 96 | 97 | -(void)showHUDWithCustomView:(UIView *)customView inView:(UIView *)view 98 | { 99 | // CGRect frame = [[UIScreen mainScreen] applicationFrame]; 100 | CGRect frame = view.bounds; 101 | // customView.alpha = .3; 102 | customView.center = CGPointMake(CGRectGetWidth(frame)/2, CGRectGetHeight(frame)/2); 103 | [view addSubview:customView]; 104 | view.userInteractionEnabled = NO; 105 | [UIView animateKeyframesWithDuration:.3 106 | delay:2 107 | options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{ 108 | customView.alpha = 0.0; 109 | } completion:^(BOOL finished) { 110 | view.userInteractionEnabled = YES; 111 | [customView removeFromSuperview]; 112 | }]; 113 | 114 | } 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /catagory/NSObject+filterPropertys.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+filterPropertys.h 3 | // dianlv_ios2 4 | // 5 | // Created by 刘 平伟 on 13-8-2. 6 | // Copyright (c) 2013年 VeryCD. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSObject (filterPropertys) 13 | 14 | //get property name list 15 | - (NSArray *)filterPropertys; 16 | 17 | //get property name and class key-value dictionary 18 | 19 | -(NSDictionary *)filterPropertyNameAndClassList; 20 | 21 | 22 | -(id)initWithDictionary:(NSDictionary *)dictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /catagory/NSObject+filterPropertys.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+filterPropertys.m 3 | // dianlv_ios2 4 | // 5 | // Created by 刘 平伟 on 13-8-2. 6 | // Copyright (c) 2013年 VeryCD. All rights reserved. 7 | // 8 | 9 | #import "NSObject+filterPropertys.h" 10 | 11 | @implementation NSObject (filterPropertys) 12 | 13 | - (NSArray *)filterPropertys 14 | { 15 | NSMutableArray *props = [NSMutableArray array]; 16 | unsigned int outCount, i; 17 | objc_property_t *properties = class_copyPropertyList([self class], &outCount); 18 | for (i = 0; i 10 | 11 | @interface NSString (SLExt) 12 | 13 | - (NSString *)md5String; 14 | 15 | // 加密方法 16 | + (NSString*)encrypt:(NSString*)plainText; 17 | 18 | // 解密方法 19 | + (NSString*)decrypt:(NSString*)encryptText; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /catagory/NSString+SLExt.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+SLExt.m 3 | // BodyScaleProduction 4 | // 5 | // Created by Go Salo on 14-3-20. 6 | // Copyright (c) 2014年 Go Salo. All rights reserved. 7 | // 8 | 9 | #import "NSString+SLExt.h" 10 | #import 11 | #import 12 | #import "DES3Util.h" 13 | 14 | #define gkey @"894D94361A243577F0A497C4EAB6462A178900022D1D95B2EAE04" 15 | #define gIv @"01234567" 16 | 17 | @implementation NSString (SLExt) 18 | 19 | // 加密方法 20 | + (NSString*)encrypt:(NSString*)plainText { 21 | return [DES3Util encrypt:plainText]; 22 | } 23 | 24 | // 解密方法 25 | + (NSString*)decrypt:(NSString*)encryptText { 26 | return [DES3Util decrypt:encryptText]; 27 | } 28 | 29 | - (NSString *)md5String 30 | { 31 | const char *cStr = [self UTF8String]; 32 | unsigned char result[16]; 33 | CC_MD5(cStr, (int)strlen(cStr), result); // This is the md5 call 34 | return [NSString stringWithFormat: 35 | @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 36 | result[0], result[1], result[2], result[3], 37 | result[4], result[5], result[6], result[7], 38 | result[8], result[9], result[10], result[11], 39 | result[12], result[13], result[14], result[15] 40 | ]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /catagory/UIViewExt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Erica Sadun, http://ericasadun.com 3 | iPhone Developer's Cookbook, 3.0 Edition 4 | BSD License, Use at your own risk 5 | */ 6 | 7 | #import 8 | 9 | CGPoint CGRectGetCenter(CGRect rect); 10 | CGRect CGRectMoveToCenter(CGRect rect, CGPoint center); 11 | 12 | @interface UIView (ViewFrameGeometry) 13 | @property CGPoint origin; 14 | @property CGSize size; 15 | 16 | @property (readonly) CGPoint bottomLeft; 17 | @property (readonly) CGPoint bottomRight; 18 | @property (readonly) CGPoint topRight; 19 | 20 | @property CGFloat height; 21 | @property CGFloat width; 22 | 23 | @property CGFloat top; 24 | @property CGFloat left; 25 | 26 | @property CGFloat bottom; 27 | @property CGFloat right; 28 | 29 | - (void) moveBy: (CGPoint) delta; 30 | - (void) scaleBy: (CGFloat) scaleFactor; 31 | - (void) fitInSize: (CGSize) aSize; 32 | @end -------------------------------------------------------------------------------- /catagory/UIViewExt.m: -------------------------------------------------------------------------------- 1 | /* 2 | Erica Sadun, http://ericasadun.com 3 | iPhone Developer's Cookbook, 3.0 Edition 4 | BSD License, Use at your own risk 5 | */ 6 | 7 | #import "UIViewExt.h" 8 | 9 | CGPoint CGRectGetCenter(CGRect rect) 10 | { 11 | CGPoint pt; 12 | pt.x = CGRectGetMidX(rect); 13 | pt.y = CGRectGetMidY(rect); 14 | return pt; 15 | } 16 | 17 | CGRect CGRectMoveToCenter(CGRect rect, CGPoint center) 18 | { 19 | CGRect newrect = CGRectZero; 20 | newrect.origin.x = center.x-CGRectGetMidX(rect); 21 | newrect.origin.y = center.y-CGRectGetMidY(rect); 22 | newrect.size = rect.size; 23 | return newrect; 24 | } 25 | 26 | @implementation UIView (ViewGeometry) 27 | 28 | // Retrieve and set the origin 29 | - (CGPoint) origin 30 | { 31 | return self.frame.origin; 32 | } 33 | 34 | - (void) setOrigin: (CGPoint) aPoint 35 | { 36 | CGRect newframe = self.frame; 37 | newframe.origin = aPoint; 38 | self.frame = newframe; 39 | } 40 | 41 | 42 | // Retrieve and set the size 43 | - (CGSize) size 44 | { 45 | return self.frame.size; 46 | } 47 | 48 | - (void) setSize: (CGSize) aSize 49 | { 50 | CGRect newframe = self.frame; 51 | newframe.size = aSize; 52 | self.frame = newframe; 53 | } 54 | 55 | // Query other frame locations 56 | - (CGPoint) bottomRight 57 | { 58 | CGFloat x = self.frame.origin.x + self.frame.size.width; 59 | CGFloat y = self.frame.origin.y + self.frame.size.height; 60 | return CGPointMake(x, y); 61 | } 62 | 63 | - (CGPoint) bottomLeft 64 | { 65 | CGFloat x = self.frame.origin.x; 66 | CGFloat y = self.frame.origin.y + self.frame.size.height; 67 | return CGPointMake(x, y); 68 | } 69 | 70 | - (CGPoint) topRight 71 | { 72 | CGFloat x = self.frame.origin.x + self.frame.size.width; 73 | CGFloat y = self.frame.origin.y; 74 | return CGPointMake(x, y); 75 | } 76 | 77 | 78 | // Retrieve and set height, width, top, bottom, left, right 79 | - (CGFloat) height 80 | { 81 | return self.frame.size.height; 82 | } 83 | 84 | - (void) setHeight: (CGFloat) newheight 85 | { 86 | CGRect newframe = self.frame; 87 | newframe.size.height = newheight; 88 | self.frame = newframe; 89 | } 90 | 91 | - (CGFloat) width 92 | { 93 | return self.frame.size.width; 94 | } 95 | 96 | - (void) setWidth: (CGFloat) newwidth 97 | { 98 | CGRect newframe = self.frame; 99 | newframe.size.width = newwidth; 100 | self.frame = newframe; 101 | } 102 | 103 | - (CGFloat) top 104 | { 105 | return self.frame.origin.y; 106 | } 107 | 108 | - (void) setTop: (CGFloat) newtop 109 | { 110 | CGRect newframe = self.frame; 111 | newframe.origin.y = newtop; 112 | self.frame = newframe; 113 | } 114 | 115 | - (CGFloat) left 116 | { 117 | return self.frame.origin.x; 118 | } 119 | 120 | - (void) setLeft: (CGFloat) newleft 121 | { 122 | CGRect newframe = self.frame; 123 | newframe.origin.x = newleft; 124 | self.frame = newframe; 125 | } 126 | 127 | - (CGFloat) bottom 128 | { 129 | return self.frame.origin.y + self.frame.size.height; 130 | } 131 | 132 | - (void) setBottom: (CGFloat) newbottom 133 | { 134 | CGRect newframe = self.frame; 135 | newframe.origin.y = newbottom - self.frame.size.height; 136 | self.frame = newframe; 137 | } 138 | 139 | - (CGFloat) right 140 | { 141 | return self.frame.origin.x + self.frame.size.width; 142 | } 143 | 144 | - (void) setRight: (CGFloat) newright 145 | { 146 | CGFloat delta = newright - (self.frame.origin.x + self.frame.size.width); 147 | CGRect newframe = self.frame; 148 | newframe.origin.x += delta ; 149 | self.frame = newframe; 150 | } 151 | 152 | // Move via offset 153 | - (void) moveBy: (CGPoint) delta 154 | { 155 | CGPoint newcenter = self.center; 156 | newcenter.x += delta.x; 157 | newcenter.y += delta.y; 158 | self.center = newcenter; 159 | } 160 | 161 | // Scaling 162 | - (void) scaleBy: (CGFloat) scaleFactor 163 | { 164 | CGRect newframe = self.frame; 165 | newframe.size.width *= scaleFactor; 166 | newframe.size.height *= scaleFactor; 167 | self.frame = newframe; 168 | } 169 | 170 | // Ensure that both dimensions fit within the given size by scaling down 171 | - (void) fitInSize: (CGSize) aSize 172 | { 173 | CGFloat scale; 174 | CGRect newframe = self.frame; 175 | 176 | if (newframe.size.height && (newframe.size.height > aSize.height)) 177 | { 178 | scale = aSize.height / newframe.size.height; 179 | newframe.size.width *= scale; 180 | newframe.size.height *= scale; 181 | } 182 | 183 | if (newframe.size.width && (newframe.size.width >= aSize.width)) 184 | { 185 | scale = aSize.width / newframe.size.width; 186 | newframe.size.width *= scale; 187 | newframe.size.height *= scale; 188 | } 189 | 190 | self.frame = newframe; 191 | } 192 | @end -------------------------------------------------------------------------------- /catagory/Utility.h: -------------------------------------------------------------------------------- 1 | // 2 | // Utility.h 3 | // BodyScale 4 | // 5 | // Created by Jerry Yu on 13-12-24. 6 | // Copyright (c) 2013年 于菲. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Utility : NSObject 12 | 13 | +(NSString*)getAppname; 14 | +(NSString*)getAppVersion; 15 | +(NSString*)getMacAddress; 16 | +(NSString*)getModelOwnerName; 17 | +(NSString*)getSystemName; 18 | +(NSString*)getSystemVersion; 19 | +(NSString*)getModelType; 20 | +(NSString*)getLocalizedModel; 21 | +(NSString*)getLanguage; 22 | //+(NSString *)MD516:(NSString *)str; 23 | //+(NSString *)MD532:(NSString *)str; 24 | +(NSMutableArray*)splitString:(NSString*)str splitchar:(NSString*)splitchar; 25 | +(UILabel*)createUILabelWithRect:(CGRect)rect text:(NSString*)text fontsize:(float)fontsize textAlignment:(NSTextAlignment)textAlignment textcolor:(UIColor*)textcolor; 26 | +(int)getRandomInt:(int)maxInt; 27 | +(NSString*)substring:(NSString*)str nstart:(int)nstart len:(int)len; 28 | +(int)indexOfString:(NSString*)str substr:(NSString*)substr; 29 | +(int)hexToDec:(NSString *)s; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /catagory/Utility.m: -------------------------------------------------------------------------------- 1 | // 2 | // Utility.m 3 | // BodyScale 4 | // 5 | // Created by Jerry Yu on 13-12-24. 6 | // Copyright (c) 2013年 于菲. All rights reserved. 7 | // 8 | 9 | #import "Utility.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | @implementation Utility 16 | 17 | /** 18 | @brief 取APP名称 19 | */ 20 | +(NSString*)getAppname 21 | { 22 | NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey]; 23 | return appName; 24 | } 25 | /** 26 | @brief 取APP版本号 27 | */ 28 | +(NSString*)getAppVersion 29 | { 30 | // 31 | NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey]; 32 | version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; 33 | return version; 34 | } 35 | /** 36 | @brief 取Mac地址 37 | */ 38 | +(NSString*)getMacAddress 39 | { 40 | int mib[6]; 41 | size_t len; 42 | char *buf; 43 | unsigned char *ptr; 44 | struct if_msghdr *ifm; 45 | struct sockaddr_dl *sdl; 46 | 47 | mib[0] = CTL_NET; 48 | mib[1] = AF_ROUTE; 49 | mib[2] = 0; 50 | mib[3] = AF_LINK; 51 | mib[4] = NET_RT_IFLIST; 52 | 53 | if ((mib[5] = if_nametoindex("en0")) == 0) { 54 | printf("Error: if_nametoindex error/n"); 55 | return NULL; 56 | } 57 | 58 | if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { 59 | printf("Error: sysctl, take 1/n"); 60 | return NULL; 61 | } 62 | 63 | if ((buf = malloc(len)) == NULL) { 64 | printf("Could not allocate memory. error!/n"); 65 | return NULL; 66 | } 67 | 68 | if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { 69 | printf("Error: sysctl, take 2"); 70 | return NULL; 71 | } 72 | 73 | ifm = (struct if_msghdr *)buf; 74 | sdl = (struct sockaddr_dl *)(ifm + 1); 75 | ptr = (unsigned char *)LLADDR(sdl); 76 | // NSString *outstring = [NSString stringWithFormat:@"%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; 77 | NSString *outstring = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; 78 | free(buf); 79 | return [outstring uppercaseString]; 80 | } 81 | /** 82 | @brief iphone的名称 83 | */ 84 | +(NSString*)getModelOwnerName 85 | { 86 | return [[UIDevice currentDevice] name];//iphone的名称,如Jerry's的iphone 87 | } 88 | /** 89 | @brief 操作系统名称 90 | */ 91 | +(NSString*)getSystemName 92 | { 93 | return [[UIDevice currentDevice] systemName];//操作系统名称 94 | } 95 | /** 96 | @brief 操作系统版本号 97 | */ 98 | +(NSString*)getSystemVersion 99 | { 100 | return [[UIDevice currentDevice] systemVersion];//操作系统版本号 101 | } 102 | /** 103 | @brief 硬件设备类型 104 | */ 105 | +(NSString*)getModelType 106 | { 107 | return [[UIDevice currentDevice] model];//硬件设备类型 108 | } 109 | /** 110 | @brief 硬件设备类型 111 | */ 112 | +(NSString*)getLocalizedModel 113 | { 114 | return [[UIDevice currentDevice] localizedModel];//硬件设备类型 115 | } 116 | /** 117 | @brief 当前语言 118 | */ 119 | +(NSString*)getLanguage 120 | { 121 | /** 122 | zh-Hans, 123 | en, 124 | fr, 125 | de, 126 | ja, 127 | nl, 128 | it, 129 | es, 130 | pt, 131 | pt-PT, 132 | da, 133 | fi, 134 | nb, 135 | sv, 136 | ko, 137 | zh-Hant, 138 | ru, 139 | pl, 140 | tr, 141 | uk, 142 | ar, 143 | hr, 144 | cs, 145 | el, 146 | he, 147 | ro, 148 | sk, 149 | th, 150 | id, 151 | ms, 152 | en-GB, 153 | ca, 154 | hu, 155 | vi 156 | */ 157 | NSString* strLanguage = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0]; 158 | return strLanguage; 159 | } 160 | /** 161 | @brief MD5 16位 162 | @param str 要加密的字符串 163 | 164 | +(NSString *)MD516:(NSString *)str 165 | { 166 | const char *src=[str UTF8String]; 167 | unsigned char result[16]; 168 | 169 | CC_MD5(src, strlen(src), result); 170 | 171 | NSString *ret =[NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]]; 172 | 173 | return ret; 174 | } 175 | 176 | 177 | @brief MD5 32位 178 | @param str 要加密的字符串 179 | 180 | +(NSString *)MD532:(NSString *)str 181 | { 182 | const char *src = [str UTF8String]; 183 | 184 | unsigned char result[32]; 185 | 186 | CC_MD5( src, strlen(src), result ); 187 | 188 | NSString *ret= [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",result[0],result[1],result[2],result[3], 189 | result[4],result[5],result[6],result[7], 190 | result[8],result[9],result[10],result[11], 191 | result[12],result[13],result[14],result[15], 192 | result[16], result[17],result[18], result[19], 193 | result[20], result[21],result[22], result[23], 194 | result[24], result[25],result[26], result[27], 195 | result[28], result[29],result[30], result[31]]; 196 | return ret; 197 | } 198 | */ 199 | /** 200 | @brief 拆分字符串到数组 201 | @param str 要拆分的字符串 202 | @param splitchar 分隔符 203 | @return 返回字符串数组 204 | */ 205 | +(NSMutableArray*)splitString:(NSString*)str splitchar:(NSString*)splitchar 206 | { 207 | NSMutableArray *result=[[NSMutableArray alloc]init]; 208 | 209 | if ([str isEqualToString:@""]||[splitchar isEqualToString:@""]){ 210 | return result; 211 | } 212 | 213 | NSInteger n=splitchar.length; 214 | NSString *instr=str; 215 | NSRange r=[str rangeOfString:splitchar options:NSCaseInsensitiveSearch]; 216 | if (r.location==NSNotFound){ 217 | [result addObject:str]; 218 | return result; 219 | } 220 | else{ 221 | while (true) { 222 | NSString *sub=[instr substringToIndex:r.location]; 223 | [result addObject:sub]; 224 | 225 | instr=[instr substringFromIndex:r.location+n ]; 226 | r=[instr rangeOfString:splitchar options:NSCaseInsensitiveSearch]; 227 | if (r.location==NSNotFound){ 228 | [result addObject:instr]; 229 | break; 230 | } 231 | } 232 | } 233 | 234 | return result; 235 | } 236 | /** 237 | @brief 创建一个UILabel 238 | @param rect 位置和大小 239 | @param text 标题 240 | @param fontsize 字体大小 241 | @param textAlignment 文本对齐方式 242 | @param textcolor 文本颜色 243 | */ 244 | +(UILabel*)createUILabelWithRect:(CGRect)rect text:(NSString*)text fontsize:(float)fontsize textAlignment:(NSTextAlignment)textAlignment textcolor:(UIColor*)textcolor 245 | { 246 | UILabel *lbl=[[UILabel alloc]initWithFrame:rect]; 247 | [lbl setBackgroundColor:[UIColor clearColor]]; 248 | lbl.opaque=NO; 249 | [lbl setTextAlignment:textAlignment]; 250 | [lbl setFont:[UIFont systemFontOfSize:fontsize]]; 251 | [lbl setTextColor:textcolor]; 252 | [lbl setText:text]; 253 | 254 | return lbl; 255 | } 256 | 257 | /** 258 | @brief 生成一个随机数 259 | @param maxInt 最大值 260 | */ 261 | +(int)getRandomInt:(int)maxInt 262 | { 263 | int x = arc4random() % maxInt; 264 | return x; 265 | } 266 | 267 | /** 268 | @brief 截取一段字符 269 | @param str 字串 270 | @param nstart 开始索引 271 | @param len 截取长度 272 | */ 273 | +(NSString*)substring:(NSString*)str nstart:(int)nstart len:(int)len 274 | { 275 | NSString *result=@""; 276 | if (str==nil || [str isEqualToString:@""]){ 277 | result=@""; 278 | } 279 | if (len>=str.length){ 280 | result=[str substringFromIndex:nstart]; 281 | } 282 | else{ 283 | result=[str substringFromIndex:nstart]; 284 | result=[result substringToIndex:len]; 285 | } 286 | return result; 287 | } 288 | 289 | /** 290 | @brief 返回substr在str中的起始索引 291 | @param str 字串 292 | @param substr 子串 293 | */ 294 | +(int)indexOfString:(NSString*)str substr:(NSString*)substr 295 | { 296 | int result=0; 297 | 298 | NSRange r=[str rangeOfString:substr]; 299 | if (r.location==NSNotFound){ 300 | result=-1; 301 | } 302 | else{ 303 | result=(int)r.location; 304 | } 305 | 306 | return result; 307 | } 308 | 309 | /** 310 | @brief 一个16进制转10进制 311 | @param s 字符形式的16进制 312 | */ 313 | +(int)hexToDec:(NSString *)s 314 | { 315 | int int_ch = 0; 316 | for (int index = 0; index < s.length; index ++) { 317 | unichar hex_char = [s characterAtIndex:index]; // 取一位 318 | 319 | int int_chn = 0; 320 | int powNum = pow(16, s.length - index - 1); 321 | if (hex_char >= '0' && hex_char <= '9') { 322 | int_chn = (hex_char - 48) * powNum ; // 0 的Ascll - 48 323 | } else if (hex_char >= 'A' && hex_char <= 'F') { 324 | int_chn = (hex_char - 55) * powNum; // A 的Ascll - 65 325 | } else { 326 | int_chn = (hex_char - 87) * powNum; // a 的Ascll - 97 327 | } 328 | int_ch += int_chn; 329 | } 330 | 331 | /* 332 | int int_ch; 333 | 334 | unichar hex_char1 = [s characterAtIndex:0]; ////两位16进制数中的第一位(高位*16) 335 | 336 | int int_ch1; 337 | 338 | if(hex_char1 >= '0'&& hex_char1 <='9'){ 339 | int_ch1 = (hex_char1-48)*16; //// 0 的Ascll - 48 340 | } 341 | else if(hex_char1 >= 'A'&& hex_char1 <='F'){ 342 | int_ch1 = (hex_char1-55)*16; //// A 的Ascll - 65 343 | } 344 | else{ 345 | int_ch1 = (hex_char1-87)*16; //// a 的Ascll - 97 346 | } 347 | 348 | unichar hex_char2 = [s characterAtIndex:1]; ///两位16进制数中的第二位(低位) 349 | 350 | int int_ch2; 351 | 352 | if(hex_char2 >= '0'&& hex_char2 <='9'){ 353 | int_ch2 = (hex_char2-48); //// 0 的Ascll - 48 354 | } 355 | else if(hex_char2 >= 'A'&& hex_char2 <='F'){ 356 | int_ch2 = hex_char2-55; //// A 的Ascll - 65 357 | } 358 | else{ 359 | int_ch2 = hex_char2-87; //// a 的Ascll - 97 360 | } 361 | 362 | 363 | int_ch = int_ch1+int_ch2; 364 | */ 365 | 366 | return int_ch; 367 | } 368 | 369 | @end 370 | -------------------------------------------------------------------------------- /catagory/Utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.h 3 | // BodyScaleProduction 4 | // 5 | // Created by Go Salo on 14-3-20. 6 | // Copyright (c) 2014年 Go Salo. All rights reserved. 7 | // 8 | 9 | #ifndef BodyScaleProduction_Utils_h 10 | #define BodyScaleProduction_Utils_h 11 | 12 | #import "UIViewExt.h" 13 | #import "NSString+SLExt.h" 14 | #import "NSDate+SLExtend.h" 15 | #import "ViewUtilFactory.h" 16 | #import "Utility.h" 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /catagory/ViewUtilFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewUtilFactory.h 3 | // BodyScaleProduction 4 | // 5 | // Created by Go Salo on 14-3-21. 6 | // Copyright (c) 2014年 Go Salo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewUtilFactory : NSObject 12 | 13 | + (void)presentAlertViewWithTitle:(NSString *)title 14 | message:(NSString *)message 15 | delegate:(id)delegate 16 | cancelButtonTitle:(NSString *)cancelButtonTitle 17 | otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; 18 | 19 | + (void)presentTakePhotoAlertViewWithTarget:(id)target takeAction:(SEL)takeAction localAction:(SEL)localAction; 20 | + (void)presentAlertViewWithTitle:(NSString *)title sureButtonTitle:(NSString *)sureButtonTitle cancelButtonTitle:(NSString *)cancelButtonTitle target:(id)target sureAction:(SEL)sureAction; 21 | 22 | + (void)presentCustomAlertViewWithTitle:(NSString *)title 23 | message:(NSString *)message 24 | delegate:(id)delegate 25 | cancelButtonTitle:(NSString *)cancelButtonTitle 26 | otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; 27 | @end 28 | -------------------------------------------------------------------------------- /catagory/ViewUtilFactory.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewUtilFactory.m 3 | // BodyScaleProduction 4 | // 5 | // Created by Go Salo on 14-3-21. 6 | // Copyright (c) 2014年 Go Salo. All rights reserved. 7 | // 8 | 9 | #import "ViewUtilFactory.h" 10 | 11 | @interface WhiteBackgroundView : UIView 12 | 13 | @end 14 | 15 | @implementation WhiteBackgroundView 16 | 17 | //- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 18 | //{ 19 | // NSLog(@"%s", __FUNCTION__); 20 | // return self; 21 | //} 22 | 23 | - (void)cancelTap:(UITapGestureRecognizer *)tap { 24 | [self removeFromSuperview]; 25 | 26 | } 27 | 28 | @end 29 | 30 | @implementation ViewUtilFactory { 31 | UIView *_alertView; // 确定取消alertview 32 | } 33 | 34 | + (instancetype)sharedInstance { 35 | static ViewUtilFactory *_sharedClient = nil; 36 | static dispatch_once_t onceToken; 37 | dispatch_once(&onceToken, ^{ 38 | _sharedClient = [[ViewUtilFactory alloc] init]; 39 | }); 40 | 41 | return _sharedClient; 42 | } 43 | 44 | + (void)presentAlertViewWithTitle:(NSString *)title 45 | message:(NSString *)message 46 | delegate:(id)delegate 47 | cancelButtonTitle:(NSString *)cancelButtonTitle 48 | otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION { 49 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title 50 | message:message 51 | delegate:delegate 52 | cancelButtonTitle:cancelButtonTitle 53 | otherButtonTitles:otherButtonTitles, nil]; 54 | [alert show]; 55 | } 56 | 57 | + (void)presentCustomAlertViewWithTitle:(NSString *)title 58 | message:(NSString *)message 59 | delegate:(id)delegate 60 | cancelButtonTitle:(NSString *)cancelButtonTitle 61 | otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION { 62 | [[ViewUtilFactory sharedInstance] createCustomAlertViewWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil]; 63 | } 64 | 65 | + (void)presentTakePhotoAlertViewWithTarget:(id)target takeAction:(SEL)takeAction localAction:(SEL)localAction { 66 | [[ViewUtilFactory sharedInstance] createTakePhotoAlertViewWithTarget:target takeAction:takeAction localAction:localAction]; 67 | 68 | } 69 | 70 | + (void)presentAlertViewWithTitle:(NSString *)title sureButtonTitle:(NSString *)sureButtonTitle cancelButtonTitle:(NSString *)cancelButtonTitle target:(id)target sureAction:(SEL)sureAction { 71 | [[ViewUtilFactory sharedInstance] createAlertViewWithTitle:title sureButtonTitle:sureButtonTitle cancelButtonTitle:cancelButtonTitle target:target sureAction:sureAction]; 72 | } 73 | 74 | #pragma mark - Private Method 75 | - (void)createAlertViewWithTitle:(NSString *)title sureButtonTitle:(NSString *)sureButtonTitle cancelButtonTitle:(NSString *)cancelButtonTitle target:(id)target sureAction:(SEL)sureAction { 76 | WhiteBackgroundView *backgroundView = [[WhiteBackgroundView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_HEIGHT)]; 77 | UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(34, (SCREEN_HEIGHT - 158) / 2, 255, 113)]; 78 | whiteView.layer.cornerRadius = 8; 79 | whiteView.backgroundColor = [UIColor whiteColor]; 80 | backgroundView.backgroundColor = [UIColor clearColor]; 81 | [backgroundView addSubview:whiteView]; 82 | [[[UIApplication sharedApplication] keyWindow] addSubview:backgroundView]; 83 | _alertView = backgroundView; 84 | 85 | UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, whiteView.width, 30)]; 86 | titleLabel.text = title; 87 | titleLabel.textAlignment = NSTextAlignmentCenter; 88 | titleLabel.font = [UIFont systemFontOfSize:14.0f]; 89 | titleLabel.textColor = [UIColor colorWithWhite:188 / 255.0f alpha:1]; 90 | [whiteView addSubview:titleLabel]; 91 | 92 | UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeCustom]; 93 | [sureButton setBackgroundImage:[UIImage imageNamed:@"registerbutton_backgroundimage.png"] forState:UIControlStateNormal]; 94 | [sureButton setFrame:CGRectMake(15, titleLabel.bottom + 15, 109, 31)]; 95 | [sureButton setTitleColor:[UIColor colorWithRed:5 / 255.0f green:138 / 255.0f blue:233 / 255.0f alpha:1] forState:UIControlStateNormal]; 96 | [sureButton setTitle:@"注册" forState:UIControlStateNormal]; 97 | [sureButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 98 | [sureButton addTarget:target action:sureAction forControlEvents:UIControlEventTouchUpInside]; 99 | [whiteView addSubview:sureButton]; 100 | 101 | UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; 102 | [cancelButton setBackgroundImage:[UIImage imageNamed:@"cancelbutton_backgroundimage.png"] forState:UIControlStateNormal]; 103 | [cancelButton setFrame:CGRectMake(whiteView.width - 15 - 109, titleLabel.bottom + 15, 109, 31)]; 104 | [cancelButton setTitleColor:[UIColor colorWithWhite:188 / 255.0f alpha:1] forState:UIControlStateNormal]; 105 | [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; 106 | [whiteView addSubview:cancelButton]; 107 | [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 108 | 109 | } 110 | 111 | - (void)createTakePhotoAlertViewWithTarget:(id)target takeAction:(SEL)takeAction localAction:(SEL)localAction { 112 | WhiteBackgroundView *alertView = [[WhiteBackgroundView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; 113 | 114 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:alertView action:@selector(cancelTap:)]; 115 | [tap setNumberOfTouchesRequired:1]; 116 | [alertView addGestureRecognizer:tap]; 117 | 118 | UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(15, (SCREEN_HEIGHT - 158) / 2, 290, 158)]; 119 | whiteView.layer.cornerRadius = 8; 120 | whiteView.backgroundColor = [UIColor whiteColor]; 121 | alertView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4]; 122 | [alertView addSubview:whiteView]; 123 | 124 | [[[UIApplication sharedApplication] keyWindow] addSubview:alertView]; 125 | 126 | UIImage *imageTake = [UIImage imageNamed:@"xiangji_normal.png"]; 127 | UIImage *imageTakeHightlight = [UIImage imageNamed:@"xiangji_hightlight.png"]; 128 | UIImage *imageLocal = [UIImage imageNamed:@"wenjian_normal.png"]; 129 | UIImage *imageLocalHightlight = [UIImage imageNamed:@"wenjian_hightlight.png"]; 130 | 131 | UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; 132 | [leftButton setImage:imageTake forState:UIControlStateNormal]; 133 | [leftButton setImage:imageTakeHightlight forState:UIControlStateHighlighted]; 134 | [leftButton setFrame:CGRectMake(40, 40, imageTake.size.width, imageTake.size.height)]; 135 | [leftButton addTarget:target action:takeAction forControlEvents:UIControlEventTouchUpInside]; 136 | [leftButton addTarget:self action:@selector(dismisViewAction:) forControlEvents:UIControlEventTouchUpInside]; 137 | [whiteView addSubview:leftButton]; 138 | 139 | UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; 140 | [rightButton setImage:imageLocal forState:UIControlStateNormal]; 141 | [rightButton setImage:imageLocalHightlight forState:UIControlStateHighlighted]; 142 | [rightButton setFrame:CGRectMake(whiteView.frame.size.width - 40 - imageLocal.size.width, 40, imageLocal.size.width, imageLocal.size.height)]; 143 | [rightButton addTarget:self action:@selector(dismisViewAction:) forControlEvents:UIControlEventTouchUpInside]; 144 | [rightButton addTarget:target action:localAction forControlEvents:UIControlEventTouchUpInside]; 145 | [whiteView addSubview:rightButton]; 146 | } 147 | 148 | - (void)createCustomAlertViewWithTitle:(NSString *)title 149 | message:(NSString *)message 150 | delegate:(id)delegate 151 | cancelButtonTitle:(NSString *)cancelButtonTitle 152 | otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION { 153 | UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; 154 | [backgroundView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.4]]; 155 | [[[UIApplication sharedApplication] keyWindow] addSubview:backgroundView]; 156 | _alertView = backgroundView; 157 | 158 | UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(15, 142, 290, 190)]; 159 | whiteView.backgroundColor = [UIColor whiteColor]; 160 | whiteView.layer.cornerRadius = 6; 161 | [backgroundView addSubview:whiteView]; 162 | 163 | UIImage *image = [UIImage imageNamed:@"default_photo_females.png"]; 164 | UIImageView *photoImageView = [[UIImageView alloc] initWithImage:image]; 165 | [photoImageView setFrame:CGRectMake(15, 15, 59, 59)]; 166 | [whiteView addSubview:photoImageView]; 167 | 168 | UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 28, 182, 35)]; 169 | titleLabel.numberOfLines = 2; 170 | [titleLabel setTextColor:[UIColor colorWithWhite:188 / 255.0f alpha:1]]; 171 | [titleLabel setFont:[UIFont systemFontOfSize:14.0f]]; 172 | titleLabel.text = title; 173 | [whiteView addSubview:titleLabel]; 174 | 175 | UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(28, 85, 264, 200)]; 176 | messageLabel.numberOfLines = 2; 177 | [messageLabel setTextColor:[UIColor colorWithWhite:188 / 255.0f alpha:1]]; 178 | [messageLabel setFont:[UIFont systemFontOfSize:14.0f]]; 179 | messageLabel.text = message; 180 | [whiteView addSubview:messageLabel]; 181 | [messageLabel sizeToFit]; 182 | 183 | UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; 184 | [cancelButton setBackgroundImage:[UIImage imageNamed:@"cancelbutton_backgroundimage.png"] forState:UIControlStateNormal]; 185 | [cancelButton setFrame:CGRectMake((whiteView.width - 109) / 2, messageLabel.bottom + 25, 109, 31)]; 186 | [cancelButton setTitleColor:[UIColor colorWithWhite:188 / 255.0f alpha:1] forState:UIControlStateNormal]; 187 | [cancelButton setTitle:cancelButtonTitle forState:UIControlStateNormal]; 188 | [whiteView addSubview:cancelButton]; 189 | [cancelButton addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 190 | } 191 | 192 | #pragma mark - Actions 193 | - (void)cancelButtonAction:(id)sender { 194 | [_alertView removeFromSuperview]; 195 | _alertView = nil; 196 | } 197 | 198 | - (void)dismisViewAction:(UIButton *)button { 199 | [button.superview.superview removeFromSuperview]; 200 | } 201 | 202 | @end 203 | -------------------------------------------------------------------------------- /my_Control/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AugustRush/Collection_devClass/92b49c9877da73da24db3ce5b5b7324175c54ebb/my_Control/.DS_Store -------------------------------------------------------------------------------- /my_Control/ICSwitchControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // ICSwitchControl.h 3 | // Test XCTest 4 | // 5 | // Created by 刘平伟 on 14-5-9. 6 | // Copyright (c) 2014年 刘平伟. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ICSwitchControlCompleteSelectedBlock)(id sender); 12 | 13 | typedef NS_ENUM(NSInteger, ICSwitchControlState) { 14 | ICSwitchControlStateOn = 0, 15 | ICSwitchControlStateOff, 16 | ICSwitchControlStateHightlight, 17 | }; 18 | 19 | typedef NS_ENUM(NSUInteger, ICSwitchControlStyle) { 20 | ICSwitchControlStyleDefault, 21 | ICSwitchControlStyleRoundCorner, 22 | }; 23 | 24 | @interface ICSwitchControl : UIControl 25 | 26 | @property (nonatomic, assign) BOOL isOn; 27 | @property (nonatomic, copy ,readonly) NSString *leftTitle; 28 | @property (nonatomic, copy, readonly) NSString *rightTitle; 29 | @property (nonatomic, assign, readonly) ICSwitchControlState currentState; 30 | @property (nonatomic, assign) ICSwitchControlStyle style; 31 | @property (nonatomic, retain) UIColor *pannelColor; 32 | @property (nonatomic, retain) UIColor *titleColor; 33 | 34 | 35 | -(void)setCompleteSelectedBlock:(ICSwitchControlCompleteSelectedBlock)completeSelectedBlock; 36 | -(void)setLeftTitle:(NSString *)left RightTitle:(NSString *)right; 37 | -(void)setBackgroundColor:(UIColor *)backgroundColor forState:(ICSwitchControlState)state; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /my_Control/ICSwitchControl.m: -------------------------------------------------------------------------------- 1 | // 2 | // ICSwitchControl.m 3 | // Test XCTest 4 | // 5 | // Created by 刘平伟 on 14-5-9. 6 | // Copyright (c) 2014年 刘平伟. All rights reserved. 7 | // 8 | 9 | #import "ICSwitchControl.h" 10 | 11 | @interface ICSwitchControl () 12 | 13 | @property (nonatomic, copy) ICSwitchControlCompleteSelectedBlock completeSelectedBlock; 14 | @property (nonatomic, strong) NSMutableDictionary *StateColorDict; 15 | 16 | @end 17 | 18 | @implementation ICSwitchControl 19 | { 20 | UILabel *_leftTL; 21 | UILabel *_rightTL; 22 | UIView *_DOT; 23 | } 24 | 25 | -(id)init 26 | { 27 | return [self initWithFrame:CGRectZero]; 28 | } 29 | 30 | - (id)initWithFrame:(CGRect)frame 31 | { 32 | self = [super initWithFrame:frame]; 33 | if (self) { 34 | [self initConfig]; 35 | } 36 | return self; 37 | } 38 | 39 | -(id)initWithCoder:(NSCoder *)aDecoder 40 | { 41 | self = [super initWithCoder:aDecoder]; 42 | if (self) { 43 | [self initConfig]; 44 | } 45 | return self; 46 | } 47 | 48 | -(void)initConfig 49 | { 50 | // self.backgroundColor = [UIColor blackColor]; 51 | 52 | UILabel *leftL = [[UILabel alloc] init]; 53 | leftL.backgroundColor = [UIColor clearColor]; 54 | leftL.textColor = [UIColor whiteColor]; 55 | leftL.textAlignment = 1; 56 | leftL.adjustsFontSizeToFitWidth = YES; 57 | [self addSubview:leftL]; 58 | _leftTL = leftL; 59 | 60 | UILabel *rightL = [[UILabel alloc] init]; 61 | rightL.backgroundColor = [UIColor clearColor]; 62 | rightL.textColor = [UIColor whiteColor]; 63 | rightL.textAlignment = 1; 64 | rightL.adjustsFontSizeToFitWidth = YES; 65 | [self addSubview:rightL]; 66 | _rightTL = rightL; 67 | 68 | _DOT = [[UIView alloc] init]; 69 | [self addSubview:_DOT]; 70 | 71 | _isOn = NO; 72 | self.currentState = ICSwitchControlStateOff; 73 | self.style = ICSwitchControlStyleDefault; 74 | self.StateColorDict = [NSMutableDictionary dictionary]; 75 | } 76 | 77 | -(void)layoutSubviews 78 | { 79 | [super layoutSubviews]; 80 | self.layer.cornerRadius = CGRectGetHeight(self.frame)/2; 81 | _leftTL.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)); 82 | _rightTL.frame = CGRectMake(CGRectGetWidth(self.frame)/2, 0, CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)); 83 | _leftTL.font = [UIFont systemFontOfSize:CGRectGetHeight(self.frame)/3]; 84 | _rightTL.font = [UIFont systemFontOfSize:CGRectGetHeight(self.frame)/3]; 85 | _DOT.frame = CGRectMake(1, 1, CGRectGetWidth(self.frame)/2-2, CGRectGetHeight(self.frame)-2); 86 | _DOT.center = self.isOn ? CGPointMake(CGRectGetWidth(self.frame)/4*3, CGRectGetHeight(self.frame)/2):CGPointMake(CGRectGetWidth(self.frame)/4, CGRectGetHeight(self.frame)/2); 87 | _DOT.layer.cornerRadius = CGRectGetHeight(self.frame)/2; 88 | 89 | } 90 | 91 | -(void)setStyle:(ICSwitchControlStyle)style 92 | { 93 | _style = style; 94 | 95 | switch (_style) { 96 | case ICSwitchControlStyleDefault: 97 | _DOT.layer.cornerRadius = 0; 98 | self.layer.cornerRadius = 0; 99 | break; 100 | case ICSwitchControlStyleRoundCorner: 101 | _DOT.layer.cornerRadius = CGRectGetHeight(self.frame)/2; 102 | self.layer.cornerRadius = CGRectGetHeight(self.frame)/2; 103 | 104 | break; 105 | 106 | default: 107 | break; 108 | } 109 | } 110 | 111 | -(void)setBackgroundColor:(UIColor *)backgroundColor 112 | { 113 | 114 | self.StateColorDict[@(ICSwitchControlStateOff)] ? NULL:[self setBackgroundColor:backgroundColor forState:ICSwitchControlStateOff]; 115 | 116 | self.StateColorDict[@(ICSwitchControlStateOn)] ? NULL:[self setBackgroundColor:backgroundColor forState:ICSwitchControlStateOn]; 117 | 118 | 119 | self.StateColorDict[@(ICSwitchControlStateHightlight)] ? NULL:[self setBackgroundColor:backgroundColor forState:ICSwitchControlStateHightlight]; 120 | 121 | } 122 | 123 | -(void)setBackgroundColor:(UIColor *)backgroundColor forState:(ICSwitchControlState)state 124 | { 125 | [self.StateColorDict setObject:backgroundColor forKey:@(state)]; 126 | [self setCurrentState:_currentState]; 127 | } 128 | 129 | -(void)setCurrentState:(ICSwitchControlState)currentState 130 | { 131 | _currentState = currentState; 132 | 133 | [UIView animateWithDuration:.3 animations:^{ 134 | self.layer.backgroundColor = self.StateColorDict[@(currentState)] ? [self.StateColorDict[@(currentState)] CGColor] : NULL; 135 | }]; 136 | } 137 | 138 | -(void)setIsOn:(BOOL)isOn 139 | { 140 | _isOn = isOn; 141 | self.currentState = isOn ? ICSwitchControlStateOn:ICSwitchControlStateOff; 142 | [UIView animateWithDuration:0.1 143 | animations:^{ 144 | _DOT.center = self.isOn ? CGPointMake(CGRectGetWidth(self.frame)/4*3, CGRectGetHeight(self.frame)/2):CGPointMake(CGRectGetWidth(self.frame)/4, CGRectGetHeight(self.frame)/2); 145 | } completion:^(BOOL finished) { 146 | self.completeSelectedBlock ? self.completeSelectedBlock(self):NULL; 147 | }]; 148 | 149 | } 150 | 151 | -(void)setPannelColor:(UIColor *)pannelColor 152 | { 153 | _pannelColor = pannelColor; 154 | _DOT.backgroundColor = _pannelColor; 155 | } 156 | 157 | -(void)setTitleColor:(UIColor *)titleColor 158 | { 159 | _titleColor = titleColor; 160 | _leftTL.textColor = titleColor; 161 | _rightTL.textColor = titleColor; 162 | } 163 | 164 | -(void)setCompleteSelectedBlock:(ICSwitchControlCompleteSelectedBlock)completeSelectedBlock 165 | { 166 | _completeSelectedBlock = completeSelectedBlock; 167 | } 168 | 169 | -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 170 | { 171 | CGPoint p = [[touches anyObject] locationInView:self]; 172 | if (p.x - CGRectGetWidth(_DOT.frame)/2 >= 0 && (p.x + CGRectGetWidth(_DOT.frame)/2 <= CGRectGetWidth(self.frame))) { 173 | _DOT.center = CGPointMake(p.x, CGRectGetHeight(self.frame)/2); 174 | } 175 | self.currentState = ICSwitchControlStateHightlight; 176 | } 177 | 178 | -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 179 | { 180 | CGPoint p = [[touches anyObject] locationInView:self]; 181 | self.isOn = p.x > CGRectGetWidth(self.frame)/2 ? YES:NO; 182 | } 183 | 184 | -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 185 | { 186 | [self touchesEnded:touches withEvent:event]; 187 | } 188 | 189 | -(void)setLeftTitle:(NSString *)left RightTitle:(NSString *)right 190 | { 191 | _leftTitle = left; 192 | _rightTitle = right; 193 | _leftTL.text = left; 194 | _rightTL.text = right; 195 | } 196 | 197 | @end 198 | --------------------------------------------------------------------------------