├── .DS_Store ├── .gitignore ├── Controller ├── HHViewController.h ├── HHViewController.m ├── UINavigationController+HHKit.h ├── UINavigationController+HHKit.m ├── UIViewController+StoreKit.h └── UIViewController+StoreKit.m ├── Core ├── HHBlocks.h ├── HHThreadHelper.h └── HHThreadHelper.m ├── HHKit.h ├── HHKit.podspec ├── LICENSE ├── Other ├── NSString+HHKit.h ├── NSString+HHKit.m ├── UIImage+HHKit.h └── UIImage+HHKit.m ├── README.md └── View ├── HHActionSheet.h ├── HHActionSheet.m ├── HHAlertView.h ├── HHAlertView.m ├── HHLabel.h ├── HHLabel.m ├── HHTextView.h ├── HHTextView.m ├── UIView+HHKit.h └── UIView+HHKit.m /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Huohua/HHKit/f6e5cf9b50a7fab5fc0ea7bac1ebcf5f34b4c871/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | build/* 3 | *.pbxuser 4 | !default.pbxuser 5 | *.mode1v3 6 | !default.mode1v3 7 | *.mode2v3 8 | !default.mode2v3 9 | *.perspectivev3 10 | !default.perspectivev3 11 | *.xcworkspace 12 | !default.xcworkspace 13 | xcuserdata 14 | profile 15 | *.moved-aside 16 | -------------------------------------------------------------------------------- /Controller/HHViewController.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | #import "HHBlocks.h" 4 | 5 | @protocol UIViewControllerHooksDelegate 6 | @optional - (NSArray *)hooksAfterLoadView; 7 | @optional - (NSArray *)hooksBeforeViewDidUnload; 8 | @optional - (NSArray *)hooksAfterViewWillAppear; 9 | @optional - (NSArray *)hooksAfterViewDidAppear; 10 | @optional - (NSArray *)hooksAfterViewWillDisappear; 11 | @optional - (NSArray *)hooksAfterViewDidDisappear; 12 | @end 13 | 14 | @interface HHViewController : UIViewController 15 | @end 16 | 17 | @interface UIViewController (ModallyPresent) 18 | - (void)presentModalViewControllerWithBlock:(HHViewControllerBlock)viewController animated:(BOOL)animated; 19 | @end -------------------------------------------------------------------------------- /Controller/HHViewController.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "HHViewController.h" 3 | 4 | @implementation HHViewController 5 | - (void)didReceiveMemoryWarning 6 | { 7 | [super didReceiveMemoryWarning]; 8 | 9 | if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) { 10 | // We check the window property to make sure that the view is not visible 11 | if (self.isViewLoaded && self.view.window == nil) { 12 | [self.view removeFromSuperview]; // Detach it from its parent (in cases of view controller containment) 13 | self.view = nil; 14 | [self performSelectorOnMainThread:@selector(viewDidUnload) withObject:nil waitUntilDone:YES]; 15 | } 16 | } 17 | } 18 | 19 | #pragma clang diagnostic push 20 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 21 | - (void)loadView 22 | { 23 | if ([self respondsToSelector:@selector(hooksAfterLoadView)]) { 24 | for (NSString *selString in [self hooksAfterLoadView]) { 25 | [self performSelector:NSSelectorFromString(selString)]; 26 | } 27 | } 28 | } 29 | 30 | - (void)viewDidUnload 31 | { 32 | if ([self respondsToSelector:@selector(hooksBeforeViewDidUnload)]) { 33 | for (NSString *selString in [self hooksBeforeViewDidUnload]) { 34 | [self performSelector:NSSelectorFromString(selString)]; 35 | } 36 | } 37 | 38 | [super viewDidUnload]; 39 | } 40 | 41 | - (void)viewWillAppear:(BOOL)animated 42 | { 43 | [super viewWillAppear:animated]; 44 | 45 | if ([self respondsToSelector:@selector(hooksAfterViewWillAppear)]) { 46 | for (NSString *selString in [self hooksAfterViewWillAppear]) { 47 | [self performSelector:NSSelectorFromString(selString)]; 48 | } 49 | } 50 | } 51 | 52 | - (void)viewDidAppear:(BOOL)animated 53 | { 54 | [super viewDidAppear:animated]; 55 | 56 | if ([self respondsToSelector:@selector(hooksAfterViewDidAppear)]) { 57 | for (NSString *selString in [self hooksAfterViewDidAppear]) { 58 | [self performSelector:NSSelectorFromString(selString)]; 59 | } 60 | } 61 | } 62 | 63 | - (void)viewWillDisappear:(BOOL)animated 64 | { 65 | [super viewWillDisappear:animated]; 66 | 67 | if ([self respondsToSelector:@selector(hooksAfterViewWillDisappear)]) { 68 | for (NSString *selString in [self hooksAfterViewWillDisappear]) { 69 | [self performSelector:NSSelectorFromString(selString)]; 70 | } 71 | } 72 | } 73 | 74 | - (void)viewDidDisappear:(BOOL)animated 75 | { 76 | [super viewDidDisappear:animated]; 77 | 78 | if ([self respondsToSelector:@selector(hooksAfterViewDidDisappear)]) { 79 | for (NSString *selString in [self hooksAfterViewDidDisappear]) { 80 | [self performSelector:NSSelectorFromString(selString)]; 81 | } 82 | } 83 | } 84 | #pragma clang diagnostic pop 85 | 86 | @end 87 | 88 | 89 | @implementation UIViewController (ModallyPresent) 90 | - (void)presentModalViewControllerWithBlock:(HHViewControllerBlock)viewController animated:(BOOL)animated 91 | { 92 | UIViewController *vc = viewController(); 93 | [self presentViewController:vc animated:animated completion:nil]; 94 | } 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /Controller/UINavigationController+HHKit.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | #import "HHBlocks.h" 4 | 5 | @interface UINavigationController (HHKit) 6 | - (void)customBackgroundWithImage:(UIImage *)image; 7 | 8 | - (void)backBtnWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage; 9 | - (void)leftBtnWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage target:(id)target selector:(SEL)selector; 10 | - (void)rightBtnWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage target:(id)target selector:(SEL)selector; 11 | 12 | - (void)replaceVisibleViewController:(UIViewController *)viewController animated:(BOOL)animated; 13 | @end -------------------------------------------------------------------------------- /Controller/UINavigationController+HHKit.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "UINavigationController+HHKit.h" 3 | 4 | @interface NavigationBarButton : UIButton 5 | @property (assign, nonatomic) BOOL isLeftButton; 6 | - (id)initWithFrame:(CGRect)frame isLeftButton:(BOOL)isLeftButton; 7 | @end 8 | 9 | @implementation NavigationBarButton 10 | - (id)initWithFrame:(CGRect)frame isLeftButton:(BOOL)isLeftButton 11 | { 12 | self = [super initWithFrame:frame]; 13 | if (self) { 14 | self.isLeftButton = isLeftButton; 15 | } 16 | return self; 17 | } 18 | 19 | - (UIEdgeInsets)alignmentRectInsets { 20 | UIEdgeInsets insets; 21 | if (self.isLeftButton) { 22 | insets = UIEdgeInsetsMake(0, 12.0f, 0, 0); 23 | } else { 24 | insets = UIEdgeInsetsMake(0, 0, 0, 12.0f); 25 | } 26 | return insets; 27 | } 28 | 29 | @end 30 | 31 | @implementation UINavigationController (HHKit) 32 | 33 | - (void)customBackgroundWithImage:(UIImage *)image 34 | { 35 | self.navigationBar.frame = CGRectMake(0, self.navigationBar.frame.origin.y, self.navigationBar.frame.size.width, 44); 36 | 37 | if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { // ios5 38 | [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 39 | } 40 | } 41 | 42 | - (void)backBtnWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage 43 | { 44 | [self leftBtnWithImage:image highlightImage:highlightImage target:self selector:@selector(popWithAnimated)]; 45 | } 46 | 47 | - (void)leftBtnWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage target:(id)target selector:(SEL)selector 48 | { 49 | UIButton *leftBtn; 50 | if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { 51 | leftBtn = [[NavigationBarButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height) isLeftButton:YES]; 52 | } else { 53 | leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)]; 54 | } 55 | [leftBtn setImage:image forState:UIControlStateNormal]; 56 | if (highlightImage) { 57 | [leftBtn setImage:highlightImage forState:UIControlStateHighlighted]; 58 | } 59 | 60 | [leftBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; 61 | self.visibleViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn]; 62 | } 63 | 64 | - (void)rightBtnWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage target:(id)target selector:(SEL)selector 65 | { 66 | UIButton *rightBtn; 67 | if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { 68 | rightBtn = [[NavigationBarButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height) isLeftButton:NO]; 69 | } else { 70 | rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)]; 71 | } 72 | [rightBtn setImage:image forState:UIControlStateNormal]; 73 | if (highlightImage) { 74 | [rightBtn setImage:highlightImage forState:UIControlStateHighlighted]; 75 | } 76 | 77 | [rightBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; 78 | self.visibleViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn]; 79 | } 80 | 81 | - (void)popWithAnimated 82 | { 83 | if (![self popViewControllerAnimated:YES]) { 84 | [self.visibleViewController dismissViewControllerAnimated:YES completion:nil]; 85 | } 86 | } 87 | 88 | - (void)replaceVisibleViewController:(UIViewController *)viewController animated:(BOOL)animated 89 | { 90 | [self pushViewController:viewController animated:animated]; 91 | 92 | NSMutableArray *VCs = [self.viewControllers mutableCopy]; 93 | [VCs removeObjectAtIndex:VCs.count - 2]; 94 | [self setViewControllers:VCs animated:animated]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /Controller/UIViewController+StoreKit.h: -------------------------------------------------------------------------------- 1 | // light@huohua.in 2 | #import 3 | #import 4 | 5 | @interface UIViewController (StoreKit) 6 | - (void)presentModalBuyItemVC:(NSString *)itemId animated:(BOOL)animated; 7 | @end -------------------------------------------------------------------------------- /Controller/UIViewController+StoreKit.m: -------------------------------------------------------------------------------- 1 | // light@huohua.in 2 | #import "UIViewController+StoreKit.h" 3 | 4 | @implementation UIViewController (StoreKit) 5 | - (void)presentModalBuyItemVC:(NSString *)itemId animated:(BOOL)animated 6 | { 7 | if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) { 8 | SKStoreProductViewController *skvc = [[SKStoreProductViewController alloc] init]; 9 | skvc.delegate = self; 10 | [skvc loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:itemId} completionBlock:^(BOOL result, NSError *error){ 11 | if (!result || error) { 12 | [skvc dismissViewControllerAnimated:YES completion:nil]; 13 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=8", itemId]]]; 14 | } 15 | }]; 16 | [self presentViewController:skvc animated:YES completion:nil]; 17 | } else { 18 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=8", itemId]]]; 19 | } 20 | } 21 | 22 | - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController 23 | { 24 | [viewController dismissViewControllerAnimated:YES completion:nil]; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Core/HHBlocks.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | 4 | typedef void (^HHBasicBlock)(void); 5 | typedef void (^HHIterationBlock)(int number); 6 | typedef void (^HHObserverBlock)(NSDictionary *change); 7 | typedef void (^HHErrorBlock)(NSError *error); 8 | typedef UIViewController *(^HHViewControllerBlock)(); -------------------------------------------------------------------------------- /Core/HHThreadHelper.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | 3 | #import 4 | #import "HHBlocks.h" 5 | 6 | @interface HHThreadHelper : NSObject 7 | 8 | + (void)performBlockInBackground:(HHBasicBlock)block completion:(HHBasicBlock)completionBlock waitUntilDone:(BOOL)waitUntilDone; 9 | + (void)performBlockInBackground:(HHBasicBlock)block completion:(HHBasicBlock)completionBlock; 10 | + (void)performBlockInBackground:(HHBasicBlock)block; 11 | 12 | + (void)performBlockInMainThread:(HHBasicBlock)block waitUntilDone:(BOOL)waitUntilDone; 13 | + (void)performBlockInMainThread:(HHBasicBlock)block afterDelay:(NSTimeInterval)delay; 14 | + (void)performBlockInMainThread:(HHBasicBlock)block; 15 | 16 | @end -------------------------------------------------------------------------------- /Core/HHThreadHelper.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "HHThreadHelper.h" 3 | 4 | @implementation HHThreadHelper 5 | 6 | + (void)performBlockInBackground:(HHBasicBlock)block completion:(HHBasicBlock)completionBlock waitUntilDone:(BOOL)waitUntilDone 7 | { 8 | dispatch_queue_t concurrentQueue = dispatch_queue_create("hhkit.core.threadhelper", DISPATCH_QUEUE_CONCURRENT); 9 | dispatch_queue_t mainQueue = dispatch_get_main_queue(); 10 | 11 | HHBasicBlock operation = [block copy]; 12 | HHBasicBlock completion = [completionBlock copy]; 13 | 14 | if (completion == nil) completion =^{}; 15 | 16 | if (operation == nil) operation =^{}; 17 | 18 | if (waitUntilDone) { 19 | dispatch_sync(concurrentQueue, operation); 20 | dispatch_sync(mainQueue, ^{ 21 | completion(); 22 | }); 23 | } else { 24 | dispatch_async(concurrentQueue, ^{ 25 | operation(); 26 | dispatch_async(mainQueue, ^{ 27 | completion(); 28 | }); 29 | }); 30 | } 31 | } 32 | 33 | + (void)performBlockInBackground:(HHBasicBlock)block completion:(HHBasicBlock)completionBlock 34 | { 35 | [self performBlockInBackground:block completion:completionBlock waitUntilDone:NO]; 36 | } 37 | 38 | + (void)performBlockInBackground:(HHBasicBlock)block 39 | { 40 | [self performBlockInBackground:block completion:nil]; 41 | } 42 | 43 | + (void)performBlockInMainThread:(HHBasicBlock)block waitUntilDone:(BOOL)waitUntilDone 44 | { 45 | [self performBlockInBackground:nil completion:block waitUntilDone:waitUntilDone]; 46 | } 47 | 48 | + (void)performBlockInMainThread:(HHBasicBlock)block afterDelay:(NSTimeInterval)delay 49 | { 50 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 51 | if (block) { 52 | block(); 53 | } 54 | }); 55 | } 56 | 57 | + (void)performBlockInMainThread:(HHBasicBlock)block 58 | { 59 | dispatch_async(dispatch_get_main_queue(), ^{ 60 | if (block) { 61 | block(); 62 | } 63 | }); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /HHKit.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | 3 | #import "HHBlocks.h" 4 | #import "HHThreadHelper.h" 5 | 6 | #import "NSString+HHKit.h" 7 | 8 | #import "UIImage+HHKit.h" 9 | 10 | #import "UIView+HHKit.h" 11 | #import "HHAlertView.h" 12 | #import "HHActionSheet.h" 13 | #import "HHLabel.h" 14 | #import "HHTextView.h" 15 | 16 | #import "HHViewController.h" 17 | #import "UINavigationController+HHKit.h" 18 | -------------------------------------------------------------------------------- /HHKit.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "HHKit" 3 | s.version = "0.1.8" 4 | s.summary = "HHKit" 5 | s.homepage = "https://github.com/Huohua/HHKit/" 6 | s.license = 'MIT' 7 | s.author = { "George Shen" => "georgeshen@huohua.in" } 8 | s.platform = :ios 9 | s.ios.deployment_target = '7.0' 10 | s.source = { :git => "https://github.com/Huohua/HHKit.git", :tag => s.version } 11 | s.source_files = 'Controller', 'Core', 'Other', 'View', 'HHKit.h' 12 | s.requires_arc = true 13 | end 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Elethom Hunter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Other/NSString+HHKit.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | 4 | @interface NSString (HHKit) 5 | @property (readonly) NSString *trim; 6 | @property (readonly) NSString *md5; 7 | 8 | - (NSString *)stringByUppercaseFirstLetter; 9 | 10 | - (NSString *)stringByEncodeURIComponent; 11 | - (NSString *)stringByDecodeURIComponent; 12 | @end -------------------------------------------------------------------------------- /Other/NSString+HHKit.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "NSString+HHKit.h" 3 | #import 4 | 5 | @implementation NSString (HHKit) 6 | 7 | - (NSString *)trim 8 | { 9 | NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet]; 10 | return [self stringByTrimmingCharactersInSet:set]; 11 | } 12 | 13 | - (NSString *)md5 14 | { 15 | const char *concat_str = [self UTF8String]; 16 | unsigned char result[CC_MD5_DIGEST_LENGTH]; 17 | 18 | CC_MD5(concat_str, (unsigned int)strlen(concat_str), result); 19 | NSMutableString *hash = [NSMutableString string]; 20 | 21 | for (int i = 0; i < 16; i++) { 22 | [hash appendFormat:@"%02X", result[i]]; 23 | } 24 | 25 | return [hash lowercaseString]; 26 | } 27 | 28 | - (NSString *)stringByUppercaseFirstLetter 29 | { 30 | NSString *firstLetter = [self substringToIndex:1]; 31 | return [self stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[firstLetter uppercaseString]]; 32 | } 33 | 34 | - (NSString *)stringByEncodeURIComponent 35 | { 36 | NSString *s = [self copy]; 37 | s = [s stringByReplacingOccurrencesOfString:@"?" withString:@"%3F" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 38 | s = [s stringByReplacingOccurrencesOfString:@"=" withString:@"%3D" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 39 | s = [s stringByReplacingOccurrencesOfString:@":" withString:@"%3A" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 40 | s = [s stringByReplacingOccurrencesOfString:@"/" withString:@"%2F" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 41 | s = [s stringByReplacingOccurrencesOfString:@"&" withString:@"%26" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 42 | s = [s stringByReplacingOccurrencesOfString:@"$" withString:@"%24" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 43 | s = [s stringByReplacingOccurrencesOfString:@";" withString:@"%3B" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 44 | s = [s stringByReplacingOccurrencesOfString:@"," withString:@"%2C" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 45 | s = [s stringByReplacingOccurrencesOfString:@"@" withString:@"%40" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 46 | s = [s stringByReplacingOccurrencesOfString:@"+" withString:@"%2B" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 47 | return s; 48 | } 49 | 50 | - (NSString *)stringByDecodeURIComponent 51 | { 52 | NSString *s = [self copy]; 53 | s = [s stringByReplacingOccurrencesOfString:@"%3F" withString:@"?" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 54 | s = [s stringByReplacingOccurrencesOfString:@"%3D" withString:@"=" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 55 | s = [s stringByReplacingOccurrencesOfString:@"%3A" withString:@":" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 56 | s = [s stringByReplacingOccurrencesOfString:@"%2F" withString:@"/" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 57 | s = [s stringByReplacingOccurrencesOfString:@"%26" withString:@"&" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 58 | s = [s stringByReplacingOccurrencesOfString:@"%24" withString:@"$" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 59 | s = [s stringByReplacingOccurrencesOfString:@"%3B" withString:@";" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 60 | s = [s stringByReplacingOccurrencesOfString:@"%2C" withString:@"," options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 61 | s = [s stringByReplacingOccurrencesOfString:@"%40" withString:@"@" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 62 | s = [s stringByReplacingOccurrencesOfString:@"%2B" withString:@"+" options:NSCaseInsensitiveSearch range:NSMakeRange(0, s.length)]; 63 | return s; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Other/UIImage+HHKit.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | 4 | @interface UIImage (HHKit) 5 | + (UIImage *)imageFromMainBundleFile:(NSString *)filename; 6 | @end -------------------------------------------------------------------------------- /Other/UIImage+HHKit.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "UIImage+HHKit.h" 3 | 4 | @implementation UIImage (HHKit) 5 | + (UIImage *)imageFromMainBundleFile:(NSString *)filename { 6 | NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; 7 | return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", bundlePath, filename]]; 8 | } 9 | 10 | @end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HHKit 2 | ===== 3 | :) -------------------------------------------------------------------------------- /View/HHActionSheet.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | #import "HHBlocks.h" 4 | 5 | @interface HHActionSheet : UIActionSheet 6 | - (id)initWithTitle:(NSString *)title; 7 | - (NSInteger)addButtonWithTitle:(NSString *)title block:(HHBasicBlock)block; 8 | - (NSInteger)addDestructiveButtonWithTitle:(NSString *)title block:(HHBasicBlock)block; 9 | - (void)addCancelButtonWithTitle:(NSString *)title; 10 | - (void)addCancelButtonWithTitle:(NSString *)title block:(HHBasicBlock)block; 11 | @end -------------------------------------------------------------------------------- /View/HHActionSheet.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "HHActionSheet.h" 3 | @interface HHActionSheet () 4 | @property (strong, nonatomic) NSMutableArray *blocks; 5 | @end 6 | 7 | @implementation HHActionSheet 8 | - (NSMutableArray *)blocks 9 | { 10 | if (!_blocks) { 11 | _blocks = [[NSMutableArray alloc] init]; 12 | } 13 | 14 | return _blocks; 15 | } 16 | 17 | - (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle 18 | { 19 | self = [self initWithTitle:title]; 20 | return self; 21 | } 22 | 23 | - (id)initWithTitle:(NSString *)title 24 | { 25 | self = [self initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 26 | return self; 27 | } 28 | 29 | - (NSInteger)addButtonWithTitle:(NSString *)title 30 | { 31 | return [self addButtonWithTitle:title block:^{}]; 32 | } 33 | 34 | - (NSInteger)addButtonWithTitle:(NSString *)title block:(HHBasicBlock)block 35 | { 36 | if (!block) { 37 | block = ^{}; 38 | } 39 | 40 | [self.blocks addObject:[block copy]]; 41 | return [super addButtonWithTitle:title]; 42 | } 43 | 44 | - (NSInteger)addDestructiveButtonWithTitle:(NSString *)title block:(HHBasicBlock)block 45 | { 46 | NSInteger index = [self addButtonWithTitle:title block:block]; 47 | self.destructiveButtonIndex = self.numberOfButtons - 1; 48 | 49 | return index; 50 | } 51 | 52 | - (void)addCancelButtonWithTitle:(NSString *)title 53 | { 54 | [self addCancelButtonWithTitle:title block:^{}]; 55 | } 56 | 57 | - (void)addCancelButtonWithTitle:(NSString *)title block:(HHBasicBlock)block 58 | { 59 | [self addButtonWithTitle:title block:block]; 60 | self.cancelButtonIndex = self.numberOfButtons - 1; 61 | } 62 | 63 | - (void)actionSheet:(HHActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 64 | { 65 | HHBasicBlock block = self.blocks[buttonIndex]; 66 | 67 | block(); 68 | } 69 | 70 | @end -------------------------------------------------------------------------------- /View/HHAlertView.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | #import "HHBlocks.h" 4 | 5 | @interface HHAlertView : UIAlertView 6 | - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle; 7 | - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle cancelBlock:(HHBasicBlock)cancelBlock; 8 | - (void)addButtonWithTitle:(NSString *)title block:(HHBasicBlock)block; 9 | @end -------------------------------------------------------------------------------- /View/HHAlertView.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "HHAlertView.h" 3 | 4 | @interface HHAlertView () 5 | @property (strong, nonatomic) NSMutableArray *blocks; 6 | @end 7 | 8 | @implementation HHAlertView 9 | 10 | - (NSMutableArray *)blocks 11 | { 12 | if (!_blocks) { 13 | _blocks = [[NSMutableArray alloc] init]; 14 | } 15 | 16 | return _blocks; 17 | } 18 | 19 | - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle 20 | { 21 | self = [self initWithTitle:title message:message cancelButtonTitle:cancelButtonTitle cancelBlock:^{}]; 22 | return self; 23 | } 24 | 25 | - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle cancelBlock:(HHBasicBlock)cancelBlock 26 | { 27 | self = [self initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil]; 28 | 29 | if (self) { 30 | if (cancelBlock) { 31 | [self.blocks addObject:[cancelBlock copy]]; 32 | } 33 | } 34 | 35 | return self; 36 | } 37 | 38 | - (void)addButtonWithTitle:(NSString *)title block:(HHBasicBlock)block 39 | { 40 | [self addButtonWithTitle:title]; 41 | 42 | if (block) { 43 | [self.blocks addObject:[block copy]]; 44 | } 45 | } 46 | 47 | - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 48 | { 49 | HHBasicBlock block = [self.blocks objectAtIndex:buttonIndex]; 50 | 51 | block(); 52 | } 53 | 54 | - (void)alertViewCancel:(UIAlertView *)alertView 55 | { 56 | HHBasicBlock block = [self.blocks firstObject]; 57 | 58 | block(); 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /View/HHLabel.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | 4 | @interface UILabel (HHKit) 5 | - (void)autoResize:(CGSize)maxSize; 6 | @end 7 | 8 | @interface HHLabel : UILabel 9 | @end -------------------------------------------------------------------------------- /View/HHLabel.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "HHLabel.h" 3 | #import "UIView+HHKit.h" 4 | 5 | @implementation UILabel (HHKit) 6 | 7 | - (void)autoResize:(CGSize)maxSize 8 | { 9 | CGSize size = [self.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : self.font} context:nil].size; 10 | self.frame = CGRectMake(self.offsetX, self.offsetY, size.width, size.height); 11 | } 12 | 13 | @end 14 | 15 | 16 | @implementation HHLabel 17 | 18 | @end -------------------------------------------------------------------------------- /View/HHTextView.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | 4 | @interface HHTextView : UITextView 5 | @property (strong, nonatomic) NSString *placeholder; 6 | @end -------------------------------------------------------------------------------- /View/HHTextView.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "HHTextView.h" 3 | #import "UIView+HHKit.h" 4 | 5 | @interface HHTextView () 6 | @property (strong, nonatomic) UILabel *placeholderLabel; 7 | @end 8 | 9 | @implementation HHTextView 10 | - (void)setPlaceholder:(NSString *)placeholder 11 | { 12 | self.placeholderLabel.text = placeholder; 13 | CGSize textSize = [self.placeholderLabel.text boundingRectWithSize:CGSizeMake(self.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : self.placeholderLabel.font} context:nil].size; 14 | self.placeholderLabel.frame = CGRectMake(8, 8, textSize.width, textSize.height); 15 | [self addSubview:self.placeholderLabel]; 16 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewDidChange:) name:UITextViewTextDidChangeNotification object:nil]; 17 | } 18 | 19 | - (void)dealloc 20 | { 21 | [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:nil]; 22 | } 23 | 24 | - (void)setFont:(UIFont *)font 25 | { 26 | [super setFont:font]; 27 | 28 | self.placeholderLabel.font = font; 29 | CGSize textSize = [self.placeholderLabel.text boundingRectWithSize:CGSizeMake(self.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : self.placeholderLabel.font} context:nil].size; 30 | self.placeholderLabel.frame = CGRectMake(8, 8, textSize.width, textSize.height); 31 | } 32 | 33 | - (void)setText:(NSString *)text 34 | { 35 | [super setText:text]; 36 | [[NSNotificationCenter defaultCenter] postNotificationName:UITextViewTextDidChangeNotification object:nil]; 37 | } 38 | 39 | - (void)textViewDidChange:(UITextView *)textView 40 | { 41 | NSString *content = [self text]; 42 | 43 | if ([content length] == 0) { 44 | self.placeholderLabel.textColor = [UIColor grayColor]; 45 | } else { 46 | self.placeholderLabel.textColor = [UIColor clearColor]; 47 | } 48 | } 49 | 50 | #pragma mark - Property 51 | - (UILabel *)placeholderLabel 52 | { 53 | if (!_placeholderLabel) { 54 | _placeholderLabel = [[UILabel alloc] init]; 55 | _placeholderLabel.textColor = [UIColor colorWithWhite:0.7f alpha:1]; 56 | _placeholderLabel.backgroundColor = [UIColor clearColor]; 57 | _placeholderLabel.font = self.font; 58 | } 59 | 60 | return _placeholderLabel; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /View/UIView+HHKit.h: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import 3 | 4 | @interface UIView (HHKit) 5 | @property (assign, nonatomic) CGPoint offset; 6 | @property (assign, nonatomic) CGSize size; 7 | 8 | @property (assign, nonatomic) CGFloat offsetX; 9 | @property (assign, nonatomic) CGFloat offsetY; 10 | @property (assign, nonatomic) CGFloat width; 11 | @property (assign, nonatomic) CGFloat height; 12 | 13 | @property (readonly) CGFloat right; 14 | @property (readonly) CGFloat bottom; 15 | 16 | 17 | - (void)show; 18 | - (void)hide; 19 | - (void)fadeInWithDuration:(NSTimeInterval)duration; 20 | - (void)fadeOutWithDuration:(NSTimeInterval)duration; 21 | @end -------------------------------------------------------------------------------- /View/UIView+HHKit.m: -------------------------------------------------------------------------------- 1 | // light@huohua.tv 2 | #import "UIView+HHKit.h" 3 | 4 | @implementation UIView (HHKit) 5 | 6 | - (CGPoint)offset 7 | { 8 | return CGPointMake(self.offsetX, self.offsetY); 9 | } 10 | 11 | - (void)setOffset:(CGPoint)offset 12 | { 13 | self.frame = CGRectMake(offset.x, offset.y, self.width, self.height); 14 | } 15 | 16 | - (CGSize)size 17 | { 18 | return CGSizeMake(self.width, self.height); 19 | } 20 | 21 | - (void)setSize:(CGSize)size 22 | { 23 | self.frame = CGRectMake(self.offsetX, self.offsetY, size.width, size.height); 24 | } 25 | 26 | - (CGFloat)offsetX 27 | { 28 | return self.frame.origin.x; 29 | } 30 | 31 | - (void)setOffsetX:(CGFloat)offsetX 32 | { 33 | self.frame = CGRectMake(offsetX, self.offsetY, self.width, self.height); 34 | } 35 | 36 | - (CGFloat)offsetY 37 | { 38 | return self.frame.origin.y; 39 | } 40 | 41 | - (void)setOffsetY:(CGFloat)offsetY 42 | { 43 | self.frame = CGRectMake(self.offsetX, offsetY, self.width, self.height); 44 | } 45 | 46 | - (CGFloat)width 47 | { 48 | return self.frame.size.width; 49 | } 50 | 51 | - (void)setWidth:(CGFloat)width 52 | { 53 | self.frame = CGRectMake(self.offsetX, self.offsetY, width, self.height); 54 | } 55 | 56 | - (CGFloat)height 57 | { 58 | return self.frame.size.height; 59 | } 60 | 61 | - (void)setHeight:(CGFloat)height 62 | { 63 | self.frame = CGRectMake(self.offsetX, self.offsetY, self.width, height); 64 | } 65 | 66 | - (CGFloat)right 67 | { 68 | return self.offsetX + self.width; 69 | } 70 | 71 | - (CGFloat)bottom 72 | { 73 | return self.offsetY + self.height; 74 | } 75 | 76 | 77 | #pragma mark - Alpha 78 | - (void)show 79 | { 80 | self.alpha = 1; 81 | } 82 | 83 | - (void)hide 84 | { 85 | self.alpha = 0; 86 | } 87 | 88 | #pragma mark - Animation 89 | - (void)fadeInWithDuration:(NSTimeInterval)duration 90 | { 91 | [UIView animateWithDuration:duration animations:^{ 92 | self.alpha = 1; 93 | }]; 94 | } 95 | 96 | - (void)fadeOutWithDuration:(NSTimeInterval)duration 97 | { 98 | [UIView animateWithDuration:duration animations:^{ 99 | self.alpha = 0; 100 | }]; 101 | } 102 | 103 | @end --------------------------------------------------------------------------------