#import "UIView+ISViewController.h"- (UIViewController *)viewController{ // 下一个响应者 id next = [self nextResponder]; while (next) { next = [next nextResponder]; // 当下一个响应者派生自ViewController if ([next isKindOfClass:[UIViewController class]]) { return next; } } return nil;}
#import "UIColor+ISColor.h"+ (UIColor *)colorWithFFRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue { return [UIColor colorWithFFRed:red green:green blue:blue alpha:1];}+ (UIColor *)colorWithFFRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { return [UIColor colorWithRed:(red)/255.0 green:(green)/255.0 blue:(blue)/255.0 alpha:alpha];}+ (UIColor *)randomColor { return [UIColor colorWithFFRed:arc4random_uniform(256) green:arc4random_uniform(256) blue:arc4random_uniform(256) alpha:arc4random_uniform(101)/100.0f];}CGFloat colorComponentFrom(NSString *string, NSUInteger start, NSUInteger length) { NSString *substring = [string substringWithRange:NSMakeRange(start, length)]; NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring]; unsigned hexComponent; [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent]; return hexComponent / 255.0;}+ (UIColor *)colorWithHex:(UInt32)hex{ return [UIColor colorWithHex:hex andAlpha:1];}+ (UIColor *)colorWithHex:(UInt32)hex andAlpha:(CGFloat)alpha{ return [UIColor colorWithRed:((hex >> 16) & 0xFF)/255.0 green:((hex >> 8) & 0xFF)/255.0 blue:(hex & 0xFF)/255.0 alpha:alpha];}+ (UIColor *)colorWithHexString:(NSString *)hexString { CGFloat alpha, red, blue, green; NSString *colorString = [[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""] uppercaseString]; switch ([colorString length]) { case 3: // #RGB alpha = 1.0f; red = colorComponentFrom(colorString, 0, 1); green = colorComponentFrom(colorString, 1, 1); blue = colorComponentFrom(colorString, 2, 1); break; case 4: // #ARGB alpha = colorComponentFrom(colorString, 0, 1); red = colorComponentFrom(colorString, 1, 1); green = colorComponentFrom(colorString, 2, 1); blue = colorComponentFrom(colorString, 3, 1); break; case 6: // #RRGGBB alpha = 1.0f; red = colorComponentFrom(colorString, 0, 2); green = colorComponentFrom(colorString, 2, 2); blue = colorComponentFrom(colorString, 4, 2); break; case 8: // #AARRGGBB alpha = colorComponentFrom(colorString, 0, 2); red = colorComponentFrom(colorString, 2, 2); green = colorComponentFrom(colorString, 4, 2); blue = colorComponentFrom(colorString, 6, 2); break; default: return nil; } return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];}- (NSString *)HEXString{ UIColor* color = self; if (CGColorGetNumberOfComponents(color.CGColor) < 4) { const CGFloat *components = CGColorGetComponents(color.CGColor); color = [UIColor colorWithRed:components[0] green:components[0] blue:components[0] alpha:components[1]]; } if (CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) != kCGColorSpaceModelRGB) { return [NSString stringWithFormat:@"#FFFFFF"]; } return [NSString stringWithFormat:@"#%02X%02X%02X", (int)((CGColorGetComponents(color.CGColor))[0]*255.0), (int)((CGColorGetComponents(color.CGColor))[1]*255.0), (int)((CGColorGetComponents(color.CGColor))[2]*255.0)];}