├── .gitignore ├── CHANGELOG.md ├── Demo └── Olla4iOSDemo │ ├── .gitignore │ ├── Olla4iOSDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── Olla4iOSDemo.xccheckout │ │ └── xcuserdata │ │ │ └── null.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── null.xcuserdatad │ │ └── xcschemes │ │ ├── Olla4iOSDemo.xcscheme │ │ └── xcschememanagement.plist │ ├── Olla4iOSDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── FirstViewController.h │ ├── FirstViewController.m │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── first.imageset │ │ │ ├── Contents.json │ │ │ └── first.pdf │ │ └── second.imageset │ │ │ ├── Contents.json │ │ │ └── second.pdf │ ├── Info.plist │ ├── Olla4iOSDemo-Prefix.pch │ ├── SecondViewController.h │ ├── SecondViewController.m │ ├── ThirdViewController.h │ ├── ThirdViewController.m │ └── main.m │ ├── Olla4iOSDemoTests │ ├── Info.plist │ └── Olla4iOSDemoTests.m │ └── Podfile ├── LICENSE ├── Olla4iOS.podspec ├── Olla4iOS ├── Olla4iOS.h ├── __macro__.h ├── application │ ├── application.h │ ├── controller │ │ ├── IOllaUIController.h │ │ ├── OllaCollectionController.h │ │ ├── OllaCollectionController.m │ │ ├── OllaCollectionDataController.h │ │ ├── OllaCollectionDataController.m │ │ ├── OllaCollectionPageController.h │ │ ├── OllaCollectionPageController.m │ │ ├── OllaDataController.h │ │ ├── OllaDataController.m │ │ ├── OllaDescendTableDataController.h │ │ ├── OllaDescendTableDataController.m │ │ ├── OllaMiddleInsertTableDataController.h │ │ ├── OllaMiddleInsertTableDataController.m │ │ ├── OllaScrollTabDataController.h │ │ ├── OllaScrollTabDataController.m │ │ ├── OllaSearchTableController.h │ │ ├── OllaSearchTableController.m │ │ ├── OllaTabDataController.h │ │ ├── OllaTabDataController.m │ │ ├── OllaTableDataController.h │ │ ├── OllaTableDataController.m │ │ ├── OllaTablePageController.h │ │ ├── OllaTablePageController.m │ │ ├── OllaTask.h │ │ └── OllaTask.m │ ├── datasource │ │ ├── IOllaDownlinkPageTask.h │ │ ├── IOllaDownlinkTask.h │ │ ├── OllaDataSource.h │ │ ├── OllaDataSource.m │ │ ├── OllaPageDataSource.h │ │ └── OllaPageDataSource.m │ └── vc │ │ ├── IOllaAction.h │ │ ├── IOllaContext.h │ │ ├── IOllaService.h │ │ ├── IOllaUIContext.h │ │ ├── IOllaUIViewController.h │ │ ├── OllaNavigationController.h │ │ ├── OllaNavigationController.m │ │ ├── OllaShell.h │ │ ├── OllaShell.m │ │ ├── OllaTabBarController.h │ │ ├── OllaTabBarController.m │ │ ├── OllaTabViewController.h │ │ ├── OllaTabViewController.m │ │ ├── OllaTableViewController.h │ │ ├── OllaTableViewController.m │ │ ├── OllaViewController.h │ │ └── OllaViewController.m ├── foundation │ ├── addtions │ │ ├── CLLocation+decode.h │ │ ├── CLLocation+decode.m │ │ ├── NSArray+addtions.h │ │ ├── NSArray+addtions.m │ │ ├── NSAttributedString+Height.h │ │ ├── NSAttributedString+Height.m │ │ ├── NSData+AES.h │ │ ├── NSData+AES.m │ │ ├── NSDate+Utilities.h │ │ ├── NSDate+Utilities.m │ │ ├── NSDate+additions.h │ │ ├── NSDate+additions.m │ │ ├── NSDictionary+additions.h │ │ ├── NSDictionary+additions.m │ │ ├── NSLocale+additions.h │ │ ├── NSLocale+additions.m │ │ ├── NSMutableArray+addtions.h │ │ ├── NSMutableArray+addtions.m │ │ ├── NSNumber+additions.h │ │ ├── NSNumber+additions.m │ │ ├── NSObject+KeyPath.h │ │ ├── NSObject+KeyPath.m │ │ ├── NSObject+check.h │ │ ├── NSObject+check.m │ │ ├── NSString+MD5.h │ │ ├── NSString+MD5.m │ │ ├── NSString+ORM.h │ │ ├── NSString+ORM.m │ │ ├── NSString+size.h │ │ ├── NSString+size.m │ │ ├── NSURL+Query.h │ │ ├── NSURL+Query.m │ │ ├── UIColor+additions.h │ │ ├── UIColor+additions.m │ │ ├── UIDevice+Hardware.h │ │ ├── UIDevice+Hardware.m │ │ ├── UIDevice+Identifier.h │ │ ├── UIDevice+Identifier.m │ │ ├── UIDevice+software.h │ │ ├── UIDevice+software.m │ │ ├── UIFont+additions.h │ │ ├── UIFont+additions.m │ │ ├── UIImage+BoxBlur.h │ │ ├── UIImage+BoxBlur.m │ │ ├── UIImage+Color.h │ │ ├── UIImage+Color.m │ │ ├── UIImage+Filter.h │ │ ├── UIImage+Filter.m │ │ ├── UIImage+Resize.h │ │ └── UIImage+Resize.m │ ├── assetLibrary │ │ ├── ALAsset+additions.h │ │ ├── ALAsset+additions.m │ │ ├── ALAssetsGroup+additions.h │ │ ├── ALAssetsGroup+additions.m │ │ ├── OllaAssetsLoader.h │ │ └── OllaAssetsLoader.m │ ├── audio │ │ ├── OllaAudioSound.h │ │ └── OllaAudioSound.m │ ├── foundation.h │ ├── network │ │ ├── OllaSocket.h │ │ └── OllaSocket.m │ ├── preference │ │ ├── OllaPreference.h │ │ └── OllaPreference.m │ └── util │ │ ├── GCDHelper.h │ │ ├── GCDHelper.m │ │ ├── OllaKeychain.h │ │ ├── OllaKeychain.m │ │ ├── OllaSandBox.h │ │ └── OllaSandBox.m └── system │ ├── bind │ ├── NSStringValueTransformer.h │ ├── NSStringValueTransformer.m │ ├── OllaDataBind.h │ ├── OllaDataBind.m │ ├── OllaDataBindContainer.h │ └── OllaDataBindContainer.m │ ├── image │ ├── OllaImagePickerController.h │ └── OllaImagePickerController.m │ ├── system.h │ └── uikit │ ├── IOllaLoadingProtocol.h │ ├── OllaButton.h │ ├── OllaButton.m │ ├── OllaCollectionViewCell.h │ ├── OllaCollectionViewCell.m │ ├── OllaFadeButton.h │ ├── OllaFadeButton.m │ ├── OllaImageBrowserView.h │ ├── OllaImageBrowserView.m │ ├── OllaLoadingMoreView.h │ ├── OllaLoadingMoreView.m │ ├── OllaMenuLabel.h │ ├── OllaMenuLabel.m │ ├── OllaRefreshView.h │ ├── OllaRefreshView.m │ ├── OllaResignView.h │ ├── OllaResignView.m │ ├── OllaTableSection.h │ ├── OllaTableSection.m │ ├── OllaTableSource.h │ ├── OllaTableSource.m │ ├── OllaTableView.h │ ├── OllaTableView.m │ ├── OllaTableViewCell.h │ ├── OllaTableViewCell.m │ ├── additions │ ├── UIActionSheet+Blocks.h │ ├── UIActionSheet+Blocks.m │ ├── UIActionSheet+iOS8.h │ ├── UIActionSheet+iOS8.m │ ├── UIApplication+additions.h │ ├── UIApplication+additions.m │ ├── UIButton+CacheURL.h │ ├── UIButton+CacheURL.m │ ├── UIImageView+CacheURL.h │ ├── UIImageView+CacheURL.m │ ├── UIImageView+ProgressHUD.h │ ├── UIImageView+ProgressHUD.m │ ├── UINavigationItem+MultipleButtonsAddition.h │ ├── UINavigationItem+MultipleButtonsAddition.m │ ├── UITabBarController+hidable.h │ ├── UITabBarController+hidable.m │ ├── UITableView+AutoHeight.h │ ├── UITableView+AutoHeight.m │ ├── UITableView+FDTemplateLayoutCell.h │ ├── UITableView+FDTemplateLayoutCell.m │ ├── UITableViewCell+additions.h │ ├── UITableViewCell+additions.m │ ├── UIView+Gesture.h │ ├── UIView+Gesture.m │ ├── UIView+additions.h │ ├── UIView+additions.m │ ├── UIView+style.h │ ├── UIView+style.m │ ├── UIViewController+HUD.h │ ├── UIViewController+HUD.m │ ├── UIWebView+addtions.h │ └── UIWebView+addtions.m │ └── common │ └── ScrollBanner │ ├── OllaBannerCell.h │ ├── OllaBannerCell.m │ ├── OllaBannerModelDelegate.h │ ├── OllaBannerView.h │ └── OllaBannerView.m ├── README.md ├── README.md.copy └── asset └── arch.png /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX noise 2 | .DS_Store 3 | *.zip 4 | ./git/* 5 | 6 | #xcode 7 | build/ 8 | xcuserdata/ 9 | *.pbxuser 10 | *.mode1 11 | *.mode1v2 12 | *.mode1v3 13 | 14 | *.xcworkspace 15 | DerivedData 16 | *.ipa 17 | 18 | #pod 19 | Pods 20 | Podfile.lock 21 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonstriater/Olla4iOS/4dac12e64caa133afdab9bc8e06bbe29a4a3c3ee/CHANGELOG.md -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX noise 2 | .DS_Store 3 | *.zip 4 | ./git/* 5 | 6 | #xcode 7 | build/ 8 | xcuserdata/ 9 | *.pbxuser 10 | *.mode1 11 | *.mode1v2 12 | *.mode1v3 13 | 14 | Reveal.framework 15 | *.xcworkspace 16 | DerivedData 17 | *.ipa 18 | 19 | #third party static library 20 | #libs/ 21 | 22 | #pod 23 | Pods 24 | Podfile.lock 25 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo.xcodeproj/project.xcworkspace/xcshareddata/Olla4iOSDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 6AD7D7DE-3DC1-4BF8-AC6F-28A96E2460DB 9 | IDESourceControlProjectName 10 | Olla4iOSDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | FB3ED81FDFC67267678C61CC8A28DB7B29DC8C4A 14 | https://github.com/nonstriater/Olla4iOS.git 15 | 16 | IDESourceControlProjectPath 17 | Demo/Olla4iOSDemo/Olla4iOSDemo.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | FB3ED81FDFC67267678C61CC8A28DB7B29DC8C4A 21 | ../../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/nonstriater/Olla4iOS.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | FB3ED81FDFC67267678C61CC8A28DB7B29DC8C4A 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | FB3ED81FDFC67267678C61CC8A28DB7B29DC8C4A 36 | IDESourceControlWCCName 37 | Olla4iOS 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo.xcodeproj/project.xcworkspace/xcuserdata/null.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonstriater/Olla4iOS/4dac12e64caa133afdab9bc8e06bbe29a4a3c3ee/Demo/Olla4iOSDemo/Olla4iOSDemo.xcodeproj/project.xcworkspace/xcuserdata/null.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo.xcodeproj/xcuserdata/null.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Notification - Olla4iOSDemo WatchKit App.xcscheme 8 | 9 | orderHint 10 | 8 11 | 12 | Olla4iOSDemo WatchKit App.xcscheme 13 | 14 | orderHint 15 | 7 16 | 17 | Olla4iOSDemo.xcscheme 18 | 19 | orderHint 20 | 0 21 | 22 | 23 | SuppressBuildableAutocreation 24 | 25 | 2609A3861B5015490096B51A 26 | 27 | primary 28 | 29 | 30 | 2609A3AD1B501C190096B51A 31 | 32 | primary 33 | 34 | 35 | 2609A3D31B501C6F0096B51A 36 | 37 | primary 38 | 39 | 40 | 26672A4A1B47F891005A219C 41 | 42 | primary 43 | 44 | 45 | 26672A661B47F891005A219C 46 | 47 | primary 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/FirstViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FirstViewController : OllaTableViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/FirstViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "FirstViewController.h" 10 | 11 | @interface FirstViewController () 12 | 13 | @end 14 | 15 | @implementation FirstViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "first.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/first.imageset/first.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonstriater/Olla4iOS/4dac12e64caa133afdab9bc8e06bbe29a4a3c3ee/Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/first.imageset/first.pdf -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "second.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/second.imageset/second.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonstriater/Olla4iOS/4dac12e64caa133afdab9bc8e06bbe29a4a3c3ee/Demo/Olla4iOSDemo/Olla4iOSDemo/Images.xcassets/second.imageset/second.pdf -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.nonstriater.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarTintParameters 34 | 35 | UINavigationBar 36 | 37 | Style 38 | UIBarStyleDefault 39 | Translucent 40 | 41 | 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | UISupportedInterfaceOrientations~ipad 50 | 51 | UIInterfaceOrientationPortrait 52 | UIInterfaceOrientationPortraitUpsideDown 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/Olla4iOSDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_7_0 10 | #warning "This project uses features only available in iOS SDK 6.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #endif 16 | 17 | #import "Olla4iOS.h" 18 | 19 | 20 | //#define App_Text_Color [UIColor colorWithRed:11/255.0f green:106/255.0f blue:255/255.0f alpha:1.0f] 21 | //#define App_Text_Font(x) [UIFont systemFontOfSize:x] 22 | 23 | 24 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : OllaTableViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | 11 | @interface SecondViewController () 12 | 13 | @end 14 | 15 | @implementation SecondViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/ThirdViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ThirdViewController.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "OllaTableViewController.h" 10 | 11 | @interface ThirdViewController : OllaTableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/ThirdViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ThirdViewController.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "ThirdViewController.h" 10 | 11 | @implementation ThirdViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.nonstriater.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Olla4iOSDemoTests/Olla4iOSDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Olla4iOSDemoTests.m 3 | // Olla4iOSDemoTests 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface Olla4iOSDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation Olla4iOSDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Demo/Olla4iOSDemo/Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | 3 | platform :ios , '7.0' 4 | 5 | target 'Olla4iOSDemo' do 6 | pod 'Olla4iOS', :git => 'https://github.com/nonstriater/Olla4iOS', :branch => 'master' 7 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | If you are using Olla4iOS in your project, I'd love to hear about it. Let Gus know 2 | by sending an email to 510495266#qq.com. 3 | 4 | Copyright (c) 2011–2015 nonstriater @移动开发小冉 (http://weibo.com/ranwj) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /Olla4iOS.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | 4 | s.name = "Olla4iOS" 5 | s.version = "0.1.2" 6 | s.author = {'nonstriater' => '510495266@qq.com'} 7 | s.summary = "iOS framework" 8 | s.platform = :ios, '6.0' 9 | s.license = "MIT" 10 | s.homepage = "http://weibo.com/ranwj" 11 | 12 | s.requires_arc = true 13 | s.frameworks = 'AVFoundation','QuartzCore','CoreText','AssetsLibrary' 14 | s.library = 'sqlite3' 15 | 16 | s.source = {:git => 'https://github.com/nonstriater/Olla4iOS.git', :tag => 'v0.1.2'} 17 | s.source_files = 'Olla4iOS/*.h' 18 | 19 | s.dependency 'SDWebImage', '~> 3.7.2' 20 | s.dependency 'FMDB', '~> 2.5' 21 | s.dependency 'MBProgressHUD', '~> 0.9.1' 22 | s.dependency 'CocoaLumberjack', '~> 2.0.1' 23 | 24 | 25 | s.subspec 'foundation' do |ss| 26 | ss.source_files = 'Olla4iOS/foundation/**/*.{h,m}' 27 | end 28 | 29 | s.subspec 'system' do |ss| 30 | ss.source_files = 'Olla4iOS/system/**/*.{h,m}' 31 | 32 | end 33 | 34 | s.subspec 'application' do |ss| 35 | ss.source_files = 'Olla4iOS/application/**/*.{h,m}' 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /Olla4iOS/Olla4iOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaFramework.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "foundation.h" 10 | #import "system.h" 11 | #import "application.h" 12 | 13 | #import 14 | #import "__macro__.h" 15 | 16 | 17 | #import 18 | #import 19 | #import 20 | #import "AVFoundation/AVFoundation.h" 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Olla4iOS/__macro__.h: -------------------------------------------------------------------------------- 1 | // 2 | // __macro__.h 3 | // 4 | // Created by null on 14-10-15. 5 | // Copyright (c) 2014年 xiaoran. All rights reserved. 6 | // 7 | 8 | #ifndef Olla___macro___h 9 | #define Olla___macro___h 10 | 11 | 12 | /////////////// dependency //////////////////// 13 | 14 | #import "FMDB.h" 15 | #import "CocoaLumberjack.h" 16 | #import "MBProgressHUD.h" 17 | 18 | #import "SDImageCache.h" 19 | #import "UIImageView+WebCache.h" 20 | #import "UIButton+WebCache.h" 21 | 22 | 23 | 24 | ///////////////// version ///////////////////////////// 25 | 26 | #undef OLLA_VERSION 27 | #define OLLA_VERSION @"0.1.2" 28 | 29 | 30 | 31 | ////////////////////// log ///////////////////////////// 32 | #undef __ON__ 33 | #define __ON__ (1) 34 | 35 | #define __OLLA_LOG__ (__ON__) 36 | 37 | #if defined(__OLLA_LOG__) && __OLLA_LOG__ 38 | 39 | #define NTLog(fmt,...) NSLog((@"%s [line %d]" fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__); 40 | #define UTLog(fmt,...) {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show];} 41 | 42 | static const int ddLogLevel = DDLogLevelInfo;//(LOG_LEVEL_VERBOSE v2.0 deprecated) 43 | //#define DDLogError(fmt,...) NLog(fmt,##__VA_ARGS__); 44 | //#define DDLogWarn(fmt,...) NLog(fmt,##__VA_ARGS__); 45 | //#define DDLogInfo(fmt,...) NLog(fmt,##__VA_ARGS__); 46 | 47 | #else 48 | 49 | #define NTLog(fmt,...) 50 | #define UTLog(fmt,...) 51 | 52 | static const int ddLogLevel = DDLogLevelOff;//(LOG_LEVEL_OFF v2.0 deprecated) 53 | //#define DDLogError(fmt,...) 54 | //#define DDLogWarn(fmt,...) 55 | //#define DDLogInfo(fmt,...) 56 | 57 | #endif 58 | 59 | 60 | 61 | ///////////////// common ///////////////////////////// 62 | 63 | 64 | #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) 65 | #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) 66 | #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 67 | #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 68 | #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) 69 | 70 | #define IS_IOS7 SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") 71 | #define IS_IOS8 SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") 72 | #define IS_3_5 ([[UIScreen mainScreen] bounds].size.height==480) 73 | 74 | #define IS_IPHONE ([[ [ UIDevice currentDevice ] model ] rangeOfString:@"iPhone"].location != NSNotFound) 75 | #define IS_IPAD ([[ [ UIDevice currentDevice ] model ] rangeOfString:@"iPad"].location != NSNotFound) 76 | #define IS_IPHONE_5 ( IS_IPHONE && IS_WIDESCREEN ) 77 | 78 | 79 | 80 | #define Screen_Height [[UIScreen mainScreen] bounds].size.height 81 | #define Screen_Width [[UIScreen mainScreen] bounds].size.width 82 | #define View_Height IS_IOS7?(Screen_Height):(Screen_Height-20) 83 | 84 | 85 | #endif 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Olla4iOS/application/application.h: -------------------------------------------------------------------------------- 1 | // 2 | // application.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #ifndef OllaFramework_application_h 10 | #define OllaFramework_application_h 11 | 12 | //vc 13 | #import "IOllaAction.h" 14 | 15 | #import "OllaShell.h" 16 | #import "OllaViewController.h" 17 | #import "OllaTableViewController.h" 18 | #import "OllaNavigationController.h" 19 | #import "OllaTabBarController.h" 20 | #import "OllaTabViewController.h" 21 | 22 | 23 | //controller 24 | #import "OllaDataController.h" 25 | #import "OllaCollectionController.h" 26 | #import "OllaTableDataController.h" 27 | #import "OllaTablePageController.h" 28 | #import "OllaSearchTableController.h" 29 | 30 | #import "OllaDescendTableDataController.h" 31 | #import "OllaMiddleInsertTableDataController.h" 32 | 33 | #import "OllaCollectionDataController.h" 34 | #import "OllaCollectionPageController.h" 35 | 36 | #import "OllaTabDataController.h" 37 | #import "OllaScrollTabDataController.h" 38 | 39 | 40 | //datasource 41 | #import "OllaDataSource.h" 42 | #import "OllaPageDataSource.h" 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/IOllaUIController.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol IOllaUIController 12 | 13 | @optional 14 | - (void)viewDidLoad; 15 | - (void)viewWillAppear; 16 | - (void)viewDidLayoutSubviews; 17 | - (void)viewWillDisappear; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaCollectionController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionController.h 3 | // Olla 4 | // 5 | // Created by null on 14-10-30. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | // base controller for collectionView & tableView 10 | #import 11 | #import "OllaDataController.h" 12 | 13 | @interface OllaCollectionController : OllaDataController 14 | 15 | @property(nonatomic, strong) IBOutlet UIView *dataEmptyView; 16 | @property(nonatomic,strong) IBOutlet UIView *dataNotFoundView; 17 | @property(nonatomic,assign) BOOL dataLoadingError; 18 | 19 | @property(nonatomic,copy) NSString *itemViewNib;//same as cell id 20 | 21 | - (void)startLoading; 22 | - (void)stopLoading; 23 | 24 | - (id)dataAtIndexPath:(NSIndexPath *)indexPath; 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaCollectionController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionController.m 3 | // Olla 4 | // 5 | // Created by null on 14-10-30. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaCollectionController.h" 10 | 11 | @implementation OllaCollectionController 12 | 13 | -(void)cancel{ 14 | self.dataLoadingError = NO; 15 | [super cancel]; 16 | [self stopLoading]; 17 | } 18 | 19 | - (void)startLoading{ 20 | self.dataLoadingError = NO; 21 | [_dataEmptyView removeFromSuperview]; 22 | [_dataNotFoundView removeFromSuperview]; 23 | } 24 | 25 | //to be overwrite 26 | - (void)stopLoading{ 27 | } 28 | 29 | // 主要是方便子类重写 30 | // 这里的设计有缺陷,如何支持二维数组数据结构????? 31 | - (id)dataAtIndexPath:(NSIndexPath *)indexPath{ 32 | return [self.dataSource dataObjectAtIndexPath:indexPath]; 33 | } 34 | 35 | 36 | #pragma datasource delegate 37 | 38 | - (void)dataSourceWillLoading:(OllaDataSource *)dataSource{ 39 | [super dataSourceWillLoading:dataSource]; 40 | [self startLoading]; 41 | } 42 | 43 | - (void)dataSourceDidLoaded:(OllaDataSource *)dataSource{ 44 | [super dataSourceDidLoaded:dataSource]; 45 | 46 | self.dataLoadingError = NO; 47 | [self stopLoading]; 48 | } 49 | 50 | - (void)dataSource:(OllaDataSource *)dataSource didFitalError:(NSError *)error{ 51 | self.dataLoadingError = YES; 52 | [self stopLoading]; 53 | [super dataSource:dataSource didFitalError:error]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaCollectionDataController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionDataController.h 3 | // Olla 4 | // 5 | // Created by null on 14-10-30. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaCollectionController.h" 10 | #import "OllaCollectionViewCell.h" 11 | #import "IOllaAction.h" 12 | 13 | //完成collectionview controller的基本设置,包括 datasource/delegate 14 | @interface OllaCollectionDataController : OllaCollectionController 15 | 16 | @property(nonatomic,weak) IBOutlet UICollectionView *collectionView; 17 | @property(nonatomic,strong) IBOutlet UICollectionViewLayout *collectionViewLayout; 18 | 19 | 20 | @property(nonatomic,strong) NSString *headerViewNib; 21 | @property(nonatomic,copy) NSString *headerReuseIdentifier;//storyboard 22 | 23 | @property(nonatomic,strong) NSString *footerViewNib; 24 | @property(nonatomic,copy) NSString *footerReuseIdentifier;//storyboard 25 | 26 | 27 | @end 28 | 29 | 30 | 31 | @protocol OllaCollectionDataController 32 | @optional 33 | 34 | // cell上button事件处理 35 | - (void)collectionController:(OllaDataController *)controller cell:(OllaCollectionViewCell *)cell doAction:(id)action event:(UIEvent *)event; 36 | // cell 选中事件处理 37 | - (void)collectionController:(OllaDataController *)controller didSelectAtIndexPath:(NSIndexPath *)indexPath; 38 | 39 | 40 | @end 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaCollectionPageController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionPageController.h 3 | // Olla 4 | // 5 | // Created by null on 14-10-31. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaCollectionDataController.h" 10 | 11 | //带刷新,加载跟多的collectionview controller 12 | @interface OllaCollectionPageController : OllaCollectionDataController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaCollectionPageController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionPageController.m 3 | // Olla 4 | // 5 | // Created by null on 14-10-31. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaCollectionPageController.h" 10 | 11 | @implementation OllaCollectionPageController 12 | 13 | - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ 14 | 15 | return nil; 16 | } 17 | 18 | - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{//iOS8 19 | 20 | 21 | } 22 | 23 | - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{ 24 | 25 | } 26 | 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaDataController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OllaTask.h" 11 | #import "IOllaUIController.h" 12 | #import "OllaDataSource.h" 13 | 14 | @interface OllaDataController : OllaTask 15 | 16 | @property(nonatomic,strong) IBOutlet OllaDataSource *dataSource; 17 | 18 | -(void) refreshData; 19 | 20 | -(void) reloadData; 21 | 22 | -(void) cancel; 23 | 24 | 25 | @end 26 | 27 | 28 | @protocol OllaDataControllerDelegate 29 | 30 | @optional 31 | -(void) dataControllerWillLoading:(OllaDataController *) controller; 32 | 33 | -(void) dataControllerDidLoadedFromCache:(OllaDataController *) controller timestamp:(NSDate *) timestamp; 34 | 35 | -(void) dataControllerDidLoaded:(OllaDataController *) controller; 36 | 37 | -(void) dataController:(OllaDataController *) controller didFitalError:(NSError *) error; 38 | 39 | -(void) dataControllerDidContentChanged:(OllaDataController *) controller; 40 | 41 | 42 | @end 43 | 44 | 45 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaDataController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataController.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaDataController.h" 10 | 11 | @implementation OllaDataController 12 | 13 | 14 | - (void)viewDidLoad{} 15 | - (void)viewWillAppear{} 16 | - (void)viewDidLayoutSubviews{} 17 | - (void)viewWillDisappear{} 18 | 19 | - (void)dealloc{ 20 | NSLog(@"%@ dealloc!",self); 21 | } 22 | 23 | -(void)setContext:(id)context{ 24 | [super setContext:context]; 25 | _dataSource.context = context; 26 | } 27 | 28 | -(void) refreshData{ 29 | [_dataSource refreshData]; 30 | } 31 | 32 | -(void) reloadData{ 33 | [_dataSource loadData]; 34 | } 35 | 36 | -(void) cancel{ 37 | [_dataSource cancel]; 38 | } 39 | 40 | 41 | #pragma mark datasource delegate 42 | 43 | -(void) dataSourceWillLoading:(OllaDataSource *) dataSource{ 44 | 45 | if (_dataSource == dataSource && [self.delegate respondsToSelector:@selector(dataControllerWillLoading:)]) { 46 | 47 | [self.delegate dataControllerWillLoading:self]; 48 | } 49 | } 50 | 51 | -(void) dataSourceDidLoadedFromCache:(OllaDataSource *) dataSource timestamp:(NSDate *) timestamp{ 52 | 53 | if (_dataSource == dataSource && [self.delegate respondsToSelector:@selector(dataControllerDidLoadedFromCache:timestamp:)]) { 54 | 55 | [self.delegate dataControllerDidLoadedFromCache:self timestamp:timestamp]; 56 | } 57 | } 58 | 59 | -(void) dataSourceDidLoaded:(OllaDataSource *) dataSource{ 60 | 61 | if (_dataSource == dataSource && [self.delegate respondsToSelector:@selector(dataControllerDidLoaded:)]) { 62 | 63 | [self.delegate dataControllerDidLoaded:self]; 64 | } 65 | } 66 | 67 | -(void) dataSource:(OllaDataSource *) dataSource didFitalError:(NSError *) error{ 68 | if (_dataSource == dataSource && [self.delegate respondsToSelector:@selector(dataController:didFitalError:)]) { 69 | 70 | [self.delegate dataController:self didFitalError:error]; 71 | } 72 | } 73 | 74 | -(void) dataSourceDidContentChanged:(OllaDataSource *) dataSource{ 75 | if (_dataSource == dataSource && [self.delegate respondsToSelector:@selector(dataControllerDidContentChanged:)]) { 76 | 77 | [self.delegate dataControllerDidContentChanged:self]; 78 | } 79 | } 80 | 81 | 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaDescendTableDataController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDescendTableDataController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14/8/27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTablePageController.h" 10 | 11 | // 管理一个倒序的tableView,适合IM页面这种业务需求的展现 12 | // 不支持有headcells 13 | @interface OllaDescendTableDataController : OllaTablePageController 14 | 15 | 16 | - (void)tableViewScrollToBottomAnimated:(BOOL)animated; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaDescendTableDataController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDescendTableDataController.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14/8/27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaDescendTableDataController.h" 10 | #import "OllaPageDataSource.h" 11 | 12 | @implementation OllaDescendTableDataController 13 | 14 | 15 | - (void)tableViewScrollToBottomAnimated:(BOOL)animated{ 16 | if ([self.dataSource count]) { 17 | NSInteger pageSize = [(OllaPageDataSource *)self.dataSource pageSize]; 18 | NSInteger pageIndex = [(OllaPageDataSource *)self.dataSource pageIndex]; 19 | [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.dataSource count]-(pageIndex-1)*pageSize inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:animated]; 20 | } 21 | 22 | } 23 | 24 | - (void)dataSourceDidLoaded:(OllaDataSource *)dataSource{ 25 | [super dataSourceDidLoaded:dataSource]; 26 | 27 | [self tableViewScrollToBottomAnimated:NO]; 28 | } 29 | 30 | 31 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 32 | 33 | if (indexPath.row == 0 ) {// loadingMore 34 | return self.bottomLoadingView.frame.size.height; 35 | } 36 | return tableView.rowHeight; 37 | } 38 | 39 | 40 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 41 | 42 | NSLog(@"indexPath row = %ld",(long)indexPath.row); 43 | 44 | if (indexPath.row == 0) {//bottom more 45 | return self.bottomLoadingView; 46 | } 47 | 48 | //itemViewNib空会崩溃 49 | NSAssert([self.itemViewNib length], @"itemViewNib空会崩溃"); 50 | id data = [self dataAtIndexPath:indexPath]; 51 | NSString *reuseIdentifier=nil; 52 | NSString *nibName = self.itemViewNib; 53 | 54 | if (!reuseIdentifier) { 55 | reuseIdentifier = self.itemViewNib; 56 | } 57 | 58 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; 59 | if (!cell) { 60 | cell = [[OllaTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier nibName:nibName]; 61 | } 62 | 63 | if ([cell isKindOfClass:[OllaTableViewCell class]]) { 64 | [(OllaTableViewCell *)cell setDelegate:self];// 代理cell上的button event 65 | [(OllaTableViewCell *)cell setDataItem:data]; 66 | } 67 | 68 | return cell; 69 | } 70 | 71 | 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaMiddleInsertTableDataController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaMiddleInsertTableDataController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-18. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTableDataController.h" 10 | 11 | // 旨在给出在tableview的中间插入cell的通用方案,如加广告等 12 | // 这段逻辑会影响tableview的效率,因为cellforrow里多了一些判断,而需要在cell中间插cell的情况应该是少数,所以独立出来 13 | // 业务层选择性的使用,这样就比较好 14 | 15 | @interface OllaMiddleInsertTableDataController : OllaTableDataController{ 16 | NSUInteger middleCellOffset; 17 | } 18 | 19 | @property(nonatomic,strong) IBOutletCollection(UITableViewCell) NSArray *middleCells;// 应对插在中间的cell的需求,如广告,需要知道插入的indexPath.row; 20 | @property(nonatomic,strong) NSArray *middleIndexRows;// 这个必须制定,且个数与[middeleCells count] 相等,否则,tableview布局会异常;eg. @[@2,@4],还要考虑数据源不足的情况 21 | 22 | - (id)dataObjectAtSelectIndexRow:(NSUInteger)row; 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaMiddleInsertTableDataController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaMiddleInsertTableDataController.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-18. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaMiddleInsertTableDataController.h" 10 | 11 | @implementation OllaMiddleInsertTableDataController 12 | 13 | 14 | - (void)setMiddleCells:(NSArray *)middleCells{ 15 | if (_middleCells != middleCells) { 16 | _middleCells = middleCells; 17 | middleCellOffset = 0; 18 | } 19 | } 20 | 21 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 22 | // 如果[datasource count]为空,就不算middleCells 23 | NSUInteger dataSourceCount = [self.dataSource count]; 24 | if (!dataSourceCount) { 25 | return [self.headerCells count]; 26 | } 27 | return [self.headerCells count]+ dataSourceCount+[_middleCells count]; 28 | 29 | } 30 | 31 | 32 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 33 | 34 | if ([_middleIndexRows containsObject:[NSNumber numberWithInteger:indexPath.row]]) { 35 | return [[_middleCells objectAtIndex:[_middleIndexRows indexOfObject:[NSNumber numberWithInteger:indexPath.row]]] frame].size.height; 36 | } 37 | 38 | return [super tableView:tableView heightForRowAtIndexPath:indexPath]; 39 | } 40 | 41 | //调整好dataItems index,避免数据错位 42 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 43 | 44 | 45 | if (indexPath.row<[[_middleIndexRows firstObject] intValue]) { 46 | middleCellOffset = 0; 47 | 48 | }else if(indexPath.row>[[_middleIndexRows lastObject] intValue]){ 49 | middleCellOffset = [_middleIndexRows count]; 50 | }else{// 升序数组中查找一个数,前面共有几个数 51 | int count=0; 52 | for (int i=0; i<[_middleIndexRows count]; i++) { 53 | if ([_middleIndexRows[i] intValue][[_middleIndexRows lastObject] intValue]){ 81 | offset = [_middleIndexRows count]; 82 | 83 | }else{// 升序数组中查找一个数,前面共有几个数 84 | int count=0; 85 | for (int i=0; i<[_middleIndexRows count]; i++) { 86 | if ([_middleIndexRows[i] intValue] 15 | 16 | @property(nonatomic,strong) IBOutlet UIScrollView *scrollView; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaScrollTabDataController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaScrollTabDataController.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-1. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaScrollTabDataController.h" 10 | 11 | @implementation OllaScrollTabDataController 12 | 13 | -(void)setSelectedIndex:(NSUInteger)selectedIndex{ 14 | [self setSelectedIndex:selectedIndex animated:NO]; 15 | 16 | } 17 | 18 | - (void)setSelectedIndex:(NSUInteger)selectedIndex animated:(BOOL)animated{ 19 | [self setSelectedIndex:selectedIndex animated:animated needScroll:YES]; 20 | } 21 | 22 | - (void)setSelectedIndex:(NSUInteger)selectedIndex animated:(BOOL)animated needScroll:(BOOL)needScroll{ 23 | 24 | if ([[self delegate] respondsToSelector:@selector(tabDataController:selectedWillChange:)]) { 25 | [[self delegate] tabDataController:self selectedWillChange:self.selectedIndex]; 26 | } 27 | 28 | _selectedIndex = selectedIndex; 29 | 30 | for (int index=0; index<[self.tabButtons count]; index++) { 31 | UIButton *button = [self.tabButtons objectAtIndex:index]; 32 | button.enabled = (index==_selectedIndex); 33 | } 34 | 35 | //只显示当前的content viewxxxxx 用scrollview了 36 | if (needScroll) { 37 | [_scrollView setContentOffset:CGPointMake(_selectedIndex*CGRectGetWidth(_scrollView.bounds),0) animated:animated]; 38 | } 39 | 40 | if ([[self delegate] respondsToSelector:@selector(tabDataController:selectedDidChange:)]) { 41 | [[self delegate] tabDataController:self selectedDidChange:_selectedIndex]; 42 | } 43 | 44 | } 45 | 46 | 47 | 48 | // ////////////////////////////////////////////////////////////////////////////////// 49 | 50 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView{} 51 | 52 | 53 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ 54 | if (!decelerate) { 55 | [self setSelectedIndex:scrollView.contentOffset.x/CGRectGetWidth(scrollView.bounds) animated:NO needScroll:NO]; 56 | } 57 | 58 | } 59 | 60 | -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ 61 | [self setSelectedIndex:scrollView.contentOffset.x/CGRectGetWidth(scrollView.bounds) animated:NO needScroll:NO]; 62 | } 63 | 64 | 65 | 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaSearchTableController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaSearchTableController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTablePageController.h" 10 | #import 11 | 12 | @interface OllaSearchTableController : OllaTablePageController 13 | 14 | @property(nonatomic,strong) IBOutlet UISearchBar *searchBar; 15 | 16 | #pragma clang diagnostic push 17 | #pragma clang diagnostic ignored "-Wdeprecated" 18 | @property(nonatomic,strong) IBOutlet UISearchDisplayController *searchDisplayController;//replace by UISearchController iOS8 19 | #pragma clang diagnostic pop 20 | 21 | @property(nonatomic,strong) NSString *searchCellNib; 22 | @property(nonatomic,strong) NSString *resultCellReuseIdentifier; 23 | @property(nonatomic,strong) NSMutableArray *searchResultObjects; 24 | @property(nonatomic,assign) BOOL searchBarHidden; 25 | 26 | @property(nonatomic,strong) NSMutableArray *groupData;//分组数据 @[@{@"A":@[]},@{@"F":@[]}] 27 | 28 | @property(nonatomic,strong) NSArray *sectionHeaderTitles; 29 | @property(nonatomic,strong) NSArray *sectionIndexTitles; 30 | @property(nonatomic,assign) BOOL sectionIndexHidden;//是否使用边索引的开关 31 | 32 | - (void)hiddenSearchBarAnimated:(BOOL)animated; 33 | //如dataItem.user.nickname 34 | 35 | - (void)sortAndGroupDataWithKeyPath:(NSString *)keyPath; 36 | - (void)sortWithDataKeyPath:(NSString *)keyPath; 37 | - (void)setupSectionTitlesWithDataKeyPath:(NSString *)keyPath; 38 | 39 | @end 40 | 41 | 42 | @protocol OllaSearchTableControllerDelegate 43 | 44 | - (void)tableDataController:(OllaDataController *)controller tableView:(UITableView *)tableView didSelectAtIndexPath:(NSIndexPath *)indexPath; 45 | 46 | 47 | @end 48 | 49 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaTabDataController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTabDataController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-1. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaDataController.h" 10 | 11 | @interface OllaTabDataController : OllaDataController{ 12 | @protected 13 | NSUInteger _selectedIndex; 14 | } 15 | 16 | @property(nonatomic,strong) IBOutletCollection(OllaDataController) NSArray *controllers; 17 | @property(nonatomic,strong) IBOutletCollection(UIButton) NSArray *tabButtons; 18 | @property(nonatomic,strong) IBOutlet UISegmentedControl *segmentedControl; 19 | @property(nonatomic,strong) IBOutletCollection(UIView) NSArray *contentViews; 20 | 21 | @property(nonatomic,strong,readonly) id selectedController; 22 | @property(nonatomic,strong,readonly) id selectedTabButton; 23 | @property(nonatomic,strong,readonly) id selectedContentView; 24 | 25 | @property(nonatomic,assign) NSUInteger selectedIndex; 26 | 27 | 28 | - (IBAction)doTabAction:(id)sender; 29 | 30 | @end 31 | 32 | 33 | 34 | @protocol OllaTabDataControllerDelegate 35 | 36 | @optional 37 | - (BOOL)tabDataController:(OllaTabDataController *)controller selectedWillChange:(NSUInteger)selectedIndex; 38 | - (BOOL)tabDataController:(OllaTabDataController *)controller selectedDidChange:(NSUInteger)selectedIndex; 39 | 40 | 41 | @end 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaTableDataController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableDataController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaCollectionController.h" 10 | #import "IOllaAction.h" 11 | #import "OllaTableViewCell.h" 12 | #import "OllaRefreshView.h" 13 | #import "OllaLoadingMoreView.h" 14 | 15 | // 用于一个table多个自定义cell的情况 16 | @interface OllaTableCellItem : NSObject 17 | @property(nonatomic,strong) NSString *nib; 18 | @property(nonatomic,strong) NSString *reusableIdentifier; 19 | @property(nonatomic,assign) id type; // 1 文字 2 图片 3 声音 4 新闻 20 | 21 | @end 22 | 23 | @interface OllaTableDataController : OllaCollectionController 24 | 25 | @property(nonatomic,weak) IBOutlet UIView *footerView; 26 | @property(nonatomic,weak) IBOutlet UIView *headerView; 27 | @property(nonatomic,weak) IBOutlet UITableView *tableView; 28 | @property(nonatomic,strong) IBOutletCollection(UITableViewCell) NSMutableArray *headerCells;//方便应对“cell可消除”这样的需求 29 | @property(nonatomic,strong) IBOutletCollection(UITableViewCell) NSArray *footerCells; 30 | 31 | @property(nonatomic,strong) IBOutlet UIControl *topRefreshView; 32 | @property(nonatomic,assign) IBInspectable BOOL refreshViewEnable; 33 | @property(nonatomic,assign) IBInspectable BOOL autoHeight; 34 | 35 | /** 36 | * cell 是否允许删除 37 | */ 38 | @property(nonatomic,assign) BOOL canCellDelete; 39 | 40 | // 刷新触发,子类重写,做自己的业务逻辑 41 | - (void)tableViewRefreshTrigger:(UIControl *)refreshView; 42 | 43 | //针对一个列表多种动态cell类型 44 | - (NSString *)nibNameAtIndexPath:(NSIndexPath *)indexPath; 45 | - (CGFloat)heightForRowAtIndexPath:(NSIndexPath *)indexPath; 46 | 47 | 48 | //必须要调用super,除非你知道意味着什么!! 49 | - (void)configCell:(OllaTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; 50 | 51 | 52 | @end 53 | 54 | 55 | @class OllaTableViewCell; 56 | @protocol IOllaAction; 57 | 58 | @protocol OllaTableDataControllerDelegate 59 | @optional 60 | 61 | // cell上button事件处理 62 | - (void)tableDataController:(OllaTableDataController *)controller cell:(OllaTableViewCell *)cell doAction:(id)action event:(UIEvent *)event; 63 | // cell 选中事件处理 64 | - (void)tableDataController:(OllaTableDataController *)controller didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 65 | 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaTablePageController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTablePageController.h 3 | // OllaFramework 4 | // 5 | // Created by null on 14-9-8. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTableDataController.h" 10 | 11 | //刷新和分页加载 12 | @interface OllaTablePageController : OllaTableDataController 13 | 14 | 15 | @property(nonatomic,strong) IBOutlet UITableViewCell *bottomLoadingView; 16 | @property(nonatomic,assign) BOOL pageEnabled; // 数据显示分页,default YES 17 | 18 | - (void)tableViewHaveScrollToBottom; 19 | 20 | // 为子类实现其他的tableController 重写(如gridPlaza) 21 | - (BOOL)addBottomLoadingViewAtIndexPath:(NSIndexPath *)indexPath; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaTask.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIContext.h" 11 | 12 | @interface OllaTask : NSObject 13 | 14 | @property(nonatomic,weak) id context; 15 | @property(nonatomic,weak) IBOutlet id delegate; 16 | @property(nonatomic,assign) NSUInteger tag; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/application/controller/OllaTask.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaController.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTask.h" 10 | 11 | @implementation OllaTask 12 | 13 | @synthesize context = _context; 14 | @synthesize delegate = _delegate; 15 | 16 | - (void)dealloc{ 17 | 18 | [OllaTask cancelPreviousPerformRequestsWithTarget:self]; 19 | self.delegate = nil; 20 | NSLog(@"Dealloc:%@",self); 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Olla4iOS/application/datasource/IOllaDownlinkPageTask.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaDownlinkPageTask.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaDownlinkTask.h" 11 | 12 | @protocol IOllaDownlinkPageTask 13 | 14 | - (NSUInteger)downlinkPageTaskPageSize; 15 | - (NSUInteger)downlinkPageTaskPageIndex; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Olla4iOS/application/datasource/IOllaDownlinkTask.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaDownlinkTask.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol IOllaDownlinkTask 12 | 13 | @property(nonatomic,assign,getter = isSkipCached) BOOL skipCached; 14 | @property(nonatomic,assign,getter = isDataChanged) BOOL dataChanged; 15 | 16 | @optional 17 | - (void)downlinkTaskDidLoadedFromCache:(id)cache timestamp:(NSDate *)timestamp; 18 | 19 | - (void)downlinkTaskDidLoaded:(id)data; 20 | - (void)downlinkTaskDidFitalError:(NSError *)error; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Olla4iOS/application/datasource/OllaDataSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataSource.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaDownlinkTask.h" 11 | #import "OllaTask.h" 12 | 13 | @interface OllaDataSource : OllaTask 14 | 15 | @property(nonatomic,strong) NSMutableArray *dataObjects; 16 | 17 | /** 18 | * json数据中的key链 eg. result.data 19 | */ 20 | @property(nonatomic,strong) NSString *dataKey; 21 | 22 | @property(nonatomic,assign,getter = isLoading) BOOL loading; 23 | @property(nonatomic,assign,getter = isLoaded) BOOL loaded; 24 | @property(nonatomic,readonly,getter = isEmpty) BOOL empty; 25 | 26 | @property(nonatomic,assign) BOOL twod;//二维结构 27 | 28 | - (void)refreshData; 29 | - (void)loadData; 30 | - (void)cancel; 31 | 32 | - (void)loadResultsData:(id)resultsData; 33 | 34 | - (NSInteger)count; 35 | 36 | - (NSMutableArray *)dataObjects; 37 | 38 | 39 | - (id)dataObjectAtIndex:(NSUInteger)index; 40 | - (BOOL)removeObjectAtIndex:(NSUInteger)index; 41 | 42 | 43 | - (NSUInteger)numberOfSection; 44 | - (NSUInteger)numberOfCellsAtSection:(NSUInteger)section; 45 | - (id)dataObjectAtIndexPath:(NSIndexPath *)indexPath; 46 | 47 | @end 48 | 49 | 50 | 51 | @protocol OllaDataSourceDelegate 52 | @optional 53 | 54 | -(void) dataSourceWillLoading:(OllaDataSource *) dataSource; 55 | -(void) dataSourceDidLoadedFromCache:(OllaDataSource *) dataSource timestamp:(NSDate *) timestamp; 56 | -(void) dataSourceDidLoaded:(OllaDataSource *) dataSource; 57 | -(void) dataSource:(OllaDataSource *) dataSource didFitalError:(NSError *) error; 58 | -(void) dataSourceDidContentChanged:(OllaDataSource *) dataSource; 59 | 60 | @end 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Olla4iOS/application/datasource/OllaPageDataSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaPageDataSource.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaDataSource.h" 10 | #import "IOllaDownlinkPageTask.h" 11 | 12 | @interface OllaPageDataSource : OllaDataSource 13 | 14 | @property(nonatomic,assign) NSUInteger pageIndex; 15 | @property(nonatomic,assign) NSUInteger pageSize; 16 | @property(nonatomic,assign) BOOL hasMoreData; 17 | 18 | - (void)loadMoreData; 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Olla4iOS/application/datasource/OllaPageDataSource.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaPageDataSource.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaPageDataSource.h" 10 | #import "foundation.h" 11 | 12 | @implementation OllaPageDataSource 13 | 14 | - (id)init{ 15 | if (self = [super init]) { 16 | 17 | self.pageIndex = 1; 18 | self.pageSize = 20; 19 | 20 | self.hasMoreData = NO; // 初始为NO,第一页数据加载不需要判断这个才行 21 | 22 | } 23 | return self; 24 | } 25 | 26 | - (void)loadMoreData{ 27 | 28 | _pageIndex++; 29 | self.loading = YES; 30 | 31 | if ([self.delegate respondsToSelector:@selector(dataSourceWillLoading:)]) { 32 | [self.delegate dataSourceWillLoading:self]; 33 | } 34 | 35 | [self loadData]; 36 | } 37 | 38 | // 重写 , 刷新 39 | - (void)refreshData{ 40 | 41 | if (_pageIndex !=1 ) { 42 | _pageIndex = 1; 43 | } 44 | 45 | _hasMoreData = YES; 46 | [super refreshData]; 47 | 48 | } 49 | 50 | - (void)loadResultsData:(id)resultsData{ 51 | if (self.pageIndex==1 && [self.dataObjects count]>0) { 52 | [self.dataObjects removeAllObjects]; 53 | } 54 | 55 | //[super loadResultsData:resultsData]; 56 | id items = self.dataKey ? [resultsData dataForKeyPath:self.dataKey]:resultsData; 57 | if ([items isKindOfClass:[NSArray class]]) { 58 | [[self dataObjects] addObjectsFromArray:items]; 59 | 60 | }else if([items isKindOfClass:[NSDictionary class]]){ 61 | [[self dataObjects] addObject:[NSMutableDictionary dictionaryWithDictionary:items]]; 62 | } 63 | 64 | } 65 | 66 | 67 | - (NSUInteger)downlinkPageTaskPageSize{ 68 | return _pageSize; 69 | } 70 | 71 | - (NSUInteger)downlinkPageTaskPageIndex{ 72 | return _pageIndex; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/IOllaAction.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaAction.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol IOllaAction 12 | 13 | @property(nonatomic,strong) NSString *actionName; 14 | @property(nonatomic,strong) id userInfo; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/IOllaContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // IVTContext.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol IOllaContext 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/IOllaService.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaServiceContext.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "IOllaContext.h" 10 | 11 | @protocol IOllaService 12 | 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/IOllaUIContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaUIContext.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "IOllaContext.h" 12 | 13 | @protocol IOllaUIContext 14 | 15 | /** 16 | * 方便跟踪当前到了哪一个viewcontroller 17 | */ 18 | @property(nonatomic,weak) UIViewController *currentViewController; 19 | 20 | /** 21 | *默认urlkey=@"url" 22 | */ 23 | - (id)rootViewController; 24 | 25 | /** 26 | * 在rootViewController不固定时使用,如可能是guide页,可能是登录也,也可能是首页 27 | * 28 | * @param key config.plist中的url key 29 | * 30 | * @return rootViewController 31 | */ 32 | - (id)rootViewControllerWithURLKey:(NSString *)key; 33 | 34 | 35 | - (id)getViewController:(NSURL *)url basePath:(NSString *)basePath; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/IOllaUIViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaUIViewController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIContext.h" 11 | #import "OllaDataBindContainer.h" 12 | 13 | @protocol IOllaUIViewController 14 | 15 | @property(nonatomic, weak) id context; 16 | @property(nonatomic, strong) id config; 17 | @property(nonatomic, strong) NSURL *url; 18 | @property(nonatomic,strong) NSString *alias; 19 | @property(nonatomic,strong) NSString *scheme; 20 | @property(nonatomic,weak) id parentController;//used for container ViewController 21 | 22 | //写这里,xib中iboulet变量老出不来 23 | //@property(nonatomic,strong) IBOutlet OllaDataBindContainer *dataBindContainer; 24 | 25 | - (BOOL)canOpenURL:(NSURL *)url; 26 | - (BOOL)openURL:(NSURL *)url animated:(BOOL)animation; 27 | 28 | /** 29 | * 给openURL扩展一个方法 30 | - openURL:params:animated //params是一个id类型,可以传递model类型的参数!!这样可以避免页面之间需要传递字典,数组这一类的数据时的拼装和解析!! 31 | */ 32 | @property(nonatomic,strong) id params; 33 | - (BOOL)openURL:(NSURL *)url params:(id)params animated:(BOOL)animation; 34 | 35 | 36 | // OllaViewController,OllaNavagationController,OllaTabBarController 有不同的 37 | - (NSString *)loadURL:(NSURL *)url basePath:(NSString *)basePath animated:(BOOL)animation; 38 | - (NSString *)loadURL:(NSURL *)url basePath:(NSString *)basePath params:(id)params animated:(BOOL)animation; 39 | 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaNavigationController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaNavigationController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIViewController.h" 11 | 12 | @interface OllaNavigationController : UINavigationController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaShell.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaShell.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIContext.h" 11 | 12 | @interface OllaShell : UIResponder 13 | 14 | @property(nonatomic, strong, readonly)id config; 15 | 16 | - (id)initWithConfig:(id)config bundle:(NSBundle *)bundle; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaTabBarController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTabBarController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIViewController.h" 11 | 12 | @interface OllaTabBarController : UITabBarController 13 | 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaTabViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTabViewController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-1. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaViewController.h" 10 | 11 | // 自定义tabbar viewController 12 | @interface OllaTabViewController : OllaViewController 13 | 14 | @property(nonatomic,strong) IBOutlet UIView *contentView; 15 | @property(nonatomic,strong) IBOutlet UIView *tabView; 16 | @property(nonatomic,strong) IBOutlet UIImageView *tabBackgroundImageView; 17 | @property(nonatomic,strong) IBOutletCollection(UIButton) NSArray *tabButtons; 18 | 19 | @property(nonatomic,strong,readonly) UIViewController *selectedViewController; 20 | @property(nonatomic,strong,readonly) UIButton *selectedTabButton; 21 | @property(nonatomic,strong) NSArray *viewControllers; 22 | @property(nonatomic,assign) NSUInteger selectedIndex; 23 | 24 | - (IBAction)doTabAction:(id)sender; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableViewController.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIViewController.h" 11 | #import "OllaDataController.h" 12 | 13 | @interface OllaTableViewController : UITableViewController 14 | 15 | /** 16 | * data & ui bind 17 | */ 18 | @property(nonatomic,strong) IBOutlet OllaDataBindContainer *dataBindContainer; 19 | 20 | /** 21 | * 每个VC都可以配置一个Controller来分离部分逻辑 22 | */ 23 | @property(nonatomic,strong) IBOutlet OllaDataController *controller; 24 | 25 | - (void)applyDataBinding; 26 | - (IBAction)doAction:(id)sender; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableViewController.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/4. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "OllaTableViewController.h" 10 | #import "Olla4iOS.h" 11 | 12 | @implementation OllaTableViewController 13 | 14 | @synthesize context = _context; 15 | @synthesize config = _config; 16 | @synthesize url = _url; 17 | @synthesize params = _params; 18 | @synthesize alias = _alias; 19 | @synthesize scheme = _scheme; 20 | @synthesize parentController = _parentController; 21 | @synthesize dataBindContainer = _dataBindContainer; 22 | 23 | 24 | - (void)viewDidLoad{ 25 | [super viewDidLoad]; 26 | [self.controller viewDidLoad]; 27 | [self applyDataBinding]; 28 | } 29 | 30 | 31 | - (void)viewWillAppear:(BOOL)animated{ 32 | [super viewWillAppear:animated]; 33 | [self.controller viewWillAppear]; 34 | [self.context setCurrentViewController:self]; 35 | } 36 | 37 | - (void)viewWillDisappear:(BOOL)animated{ 38 | [super viewWillDisappear:animated]; 39 | [self.controller viewWillDisappear]; 40 | } 41 | 42 | 43 | - (void)setConfig:(id)config{ 44 | if (_config != config) { 45 | _config = config; 46 | 47 | id value = [_config valueForKey:@"title"]; 48 | if (!value) { 49 | return; 50 | } 51 | if ([value isString]) { 52 | self.title = (NSString *)value; 53 | }else{ 54 | DDLogError(@"%@'s title must be NSString type,check the config.plist",self); 55 | } 56 | } 57 | } 58 | 59 | - (void)applyDataBinding{ 60 | 61 | [_dataBindContainer applyDataBinding:self]; 62 | } 63 | 64 | 65 | - (IBAction)doAction:(id)sender{ 66 | 67 | if ([sender conformsToProtocol:@protocol(IOllaAction) ]) { 68 | NSString *actionName = [sender actionName]; 69 | id userInfo = [sender userInfo]; 70 | if ([actionName isEqualToString:@"url"]) { 71 | if (userInfo && [userInfo isKindOfClass:[NSString class]]) { 72 | [self openURL:[NSURL URLWithString:userInfo relativeToURL:self.url] animated:YES]; 73 | } 74 | 75 | }else if([actionName isEqualToString:@"openURL"]){ 76 | if (userInfo && [userInfo isKindOfClass:[NSString class] ]) { 77 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:userInfo]]; 78 | } 79 | } 80 | } 81 | 82 | } 83 | 84 | 85 | // xib url //////////////////////////// 86 | 87 | -(BOOL)canOpenURL:(NSURL *)url{ 88 | return NO; 89 | } 90 | 91 | 92 | - (BOOL)openURL:(NSURL *)url animated:(BOOL)animation{ 93 | return [self openURL:url params:nil animated:animation]; 94 | } 95 | 96 | - (BOOL)openURL:(NSURL *)url params:(id)params animated:(BOOL)animation{ 97 | 98 | return [_parentController openURL:url params:params animated:animation]; 99 | } 100 | 101 | 102 | - (NSString *)loadURL:(NSURL *)url basePath:(NSString *)basePath animated:(BOOL)animation{ 103 | 104 | return [basePath stringByAppendingPathComponent:self.alias]; 105 | } 106 | 107 | - (NSString *)loadURL:(NSURL *)url basePath:(NSString *)basePath params:(id)params animated:(BOOL)animation{ 108 | 109 | return nil; 110 | } 111 | 112 | 113 | 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /Olla4iOS/application/vc/OllaViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaViewController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaUIViewController.h" 11 | #import "OllaDataController.h" 12 | 13 | @interface OllaViewController : UIViewController 14 | 15 | @property(nonatomic,strong) IBOutlet OllaDataBindContainer *dataBindContainer; 16 | 17 | /** 18 | * 每个VC都可以配置一个Controller来分离部分逻辑 19 | */ 20 | @property(nonatomic,strong) IBOutlet OllaDataController *controller; 21 | 22 | 23 | - (IBAction)doAction:(id)sender; 24 | - (void)applyDataBinding; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/CLLocation+decode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CLLocation+decode.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-6. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CLLocation (decode) 12 | 13 | //- (NSString *)formatLocation; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/CLLocation+decode.m: -------------------------------------------------------------------------------- 1 | // 2 | // CLLocation+decode.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-6. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "CLLocation+decode.h" 10 | 11 | @implementation CLLocation (decode) 12 | // 13 | //- (NSString *)formatLocat{ 14 | // 15 | // // 将location信息编码成街道信息 16 | // CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 17 | // [geocoder reverseGeocodeLocation:self completionHandler:^(NSArray *places,NSError *error){ 18 | // if ([places count]>0) { 19 | // CLPlacemark *placeMark = places[0]; 20 | // NSString *text =[NSString stringWithFormat:@"%@ %@ %@ %@",placeMark.country,placeMark.administrativeArea,placeMark.locality,placeMark.thoroughfare]; 21 | // } 22 | // 23 | // /** CLPlacemark 24 | // * // address dictionary properties 25 | // @property (nonatomic, readonly) NSString *name; // eg. Apple Inc. 26 | // @property (nonatomic, readonly) NSString *thoroughfare; // street address, eg. 1 Infinite Loop 27 | // @property (nonatomic, readonly) NSString *subThoroughfare; // eg. 1 28 | // @property (nonatomic, readonly) NSString *locality; // city, eg. Cupertino 29 | // @property (nonatomic, readonly) NSString *subLocality; // neighborhood, common name, eg. Mission District 30 | // @property (nonatomic, readonly) NSString *administrativeArea; // state, eg. CA 31 | // @property (nonatomic, readonly) NSString *subAdministrativeArea; // county, eg. Santa Clara 32 | // @property (nonatomic, readonly) NSString *postalCode; // zip code, eg. 95014 33 | // @property (nonatomic, readonly) NSString *ISOcountryCode; // eg. US 34 | // @property (nonatomic, readonly) NSString *country; // eg. United States 35 | // @property (nonatomic, readonly) NSString *inlandWater; // eg. Lake Tahoe 36 | // @property (nonatomic, readonly) NSString *ocean; // eg. Pacific Ocean 37 | // @property (nonatomic, readonly) NSArray *areasOfInterest; // eg. Golden Gate Park 38 | // */ 39 | // 40 | // }]; 41 | // 42 | // 43 | // 44 | //} 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSArray+addtions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+addtions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (addtions) 12 | 13 | + (instancetype)arrayWithObject:(id)object count:(NSUInteger)cnt; 14 | 15 | - (BOOL)isArray; 16 | - (NSArray*)propertyListArray; // filter nsnull 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSArray+addtions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+addtions.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "foundation.h" 10 | 11 | @implementation NSArray (addtions) 12 | 13 | + (instancetype)arrayWithObject:(id)object count:(NSUInteger)cnt{ 14 | NSMutableArray *ma = [[NSMutableArray alloc] initWithCapacity:cnt]; 15 | for (int i=0; i 10 | #import 11 | 12 | @interface NSAttributedString (Height) 13 | 14 | - (CGFloat)boundingHeightForWidth:(CGFloat)inWidth; 15 | - (CGFloat)boundingHeightWithFrameSetter:(CTFramesetterRef)frameSetter ForWidth:(CGFloat)inWidth; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSAttributedString+Height.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSAttributedString+Height.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-5-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSAttributedString+Height.h" 10 | 11 | const CGFloat AttributedString_Max_Height=1000.f; 12 | 13 | @implementation NSAttributedString (Height) 14 | 15 | - (CGFloat)boundingHeightForWidth:(CGFloat)inWidth{ 16 | 17 | CTFramesetterRef frameSetterRef = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef) self); 18 | CGFloat height = [self boundingHeightWithFrameSetter:frameSetterRef ForWidth:inWidth]; 19 | CFRelease(frameSetterRef); 20 | return height; 21 | } 22 | 23 | - (CGFloat)boundingHeightWithFrameSetter:(CTFramesetterRef)frameSetter ForWidth:(CGFloat)inWidth{ 24 | 25 | CGFloat height = 0.f; 26 | 27 | CGMutablePathRef path = CGPathCreateMutable(); 28 | CGPathAddRect(path, Nil, CGRectMake(0, 0, inWidth, AttributedString_Max_Height)); 29 | 30 | CTFrameRef frameRef = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL); 31 | 32 | CFArrayRef linesArray = CTFrameGetLines(frameRef); 33 | CFIndex linesCount = CFArrayGetCount(linesArray); 34 | CGFloat lineHeight,ascent,descent,leading; 35 | for (int i=0; i 10 | 11 | @interface NSData (AES) 12 | 13 | // iOS7上又base64Encoding api直接调用,这里兼容iOS6处理 14 | - (NSString *)base64Encode; 15 | 16 | - (NSString *)md5Encode; 17 | 18 | - (NSData *)AES256EncodeWithKey:(NSString *)key; 19 | - (NSData *)AES256DecodeWithKey:(NSString *)key; 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSData+AES.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+AES.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSData+AES.h" 10 | #import 11 | 12 | @implementation NSData (AES) 13 | 14 | 15 | - (NSString *)base64Encode{ 16 | //return [self base64Encoding];//iOS7以后就废掉了 17 | return nil; 18 | } 19 | 20 | - (NSString *)md5Encode{ 21 | 22 | unsigned char result[CC_MD5_DIGEST_LENGTH]; 23 | CC_MD5(self.bytes, (unsigned int)[self length], result); 24 | 25 | NSMutableString *hash = [[NSMutableString alloc] init]; 26 | for (int i=0; i<16; i++) { 27 | [hash appendFormat:@"%02X",result[i]]; 28 | } 29 | return [hash lowercaseString]; 30 | 31 | } 32 | 33 | 34 | 35 | // iOS 上 noPadding(0x000) 方式aes 加密,得到的数据时 0 lengh 36 | // http://stackoverflow.com/questions/10900894/ios-encryption-aes128-cbc-nopadding-why-is-not-working 37 | // 服务器是nopadding 方式,随意这里改成nopadding的方式 38 | 39 | 40 | - (NSData *)AES256EncodeWithKey:(NSString *)key{ 41 | 42 | char keyPtr[kCCKeySizeAES128+1]; 43 | bzero(keyPtr, sizeof(keyPtr)); 44 | 45 | [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 46 | 47 | 48 | // support no padding ==================================================== 49 | NSUInteger dataLength = [self length]; 50 | int diff = kCCKeySizeAES128 - (dataLength % kCCKeySizeAES128); 51 | 52 | NSUInteger newSize = dataLength; 53 | if(diff > 0) 54 | { 55 | newSize += diff; 56 | } 57 | 58 | char dataPtr[newSize]; 59 | memcpy(dataPtr, [self bytes], [self length]); 60 | for(int i = 0; i < diff; i++) 61 | { 62 | dataPtr[i + dataLength] = 0x20; 63 | } 64 | // ==================================================== 65 | 66 | 67 | size_t bufferSize = [self length]+kCCBlockSizeAES128; 68 | size_t numberBytesOfEncrypted = 0; 69 | void *buffer = malloc(bufferSize); 70 | CCCryptorStatus status = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, 0x000, keyPtr, kCCKeySizeAES128, NULL, dataPtr, sizeof(dataPtr), buffer, bufferSize, &numberBytesOfEncrypted); 71 | if (status==kCCSuccess) { 72 | return [NSData dataWithBytesNoCopy:buffer length:numberBytesOfEncrypted]; 73 | } 74 | free(buffer); 75 | return nil; 76 | } 77 | 78 | 79 | // key should be 32 bytes;;; -4301 error(buffer too small error!) 80 | - (NSData *)AES256DecodeWithKey:(NSString *)key{ 81 | 82 | char keyPtr[kCCKeySizeAES128+1]; 83 | bzero(keyPtr, sizeof(keyPtr)); 84 | 85 | [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 86 | 87 | size_t bufferSize = [self length] + kCCBlockSizeAES128; 88 | size_t numberOfBytesDecrypted =0; 89 | void *buffer = malloc(bufferSize); 90 | 91 | CCCryptorStatus status = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0x000, keyPtr, kCCKeySizeAES128, NULL, [self bytes], [self length], buffer, bufferSize, &numberOfBytesDecrypted); 92 | 93 | if (status == kCCSuccess) { 94 | // decode 去掉 padding数据 -numberOfBytesDecrypted%16 95 | return [NSData dataWithBytesNoCopy:buffer length:numberOfBytesDecrypted-numberOfBytesDecrypted%16]; 96 | }else{ 97 | NSLog(@"decode status=%d",status); 98 | } 99 | 100 | free(buffer); 101 | return nil; 102 | } 103 | 104 | 105 | @end 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSDate+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+additions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDate (additions) 12 | 13 | /** 14 | * Formats dates within 24 hours like '5 minutes ago', or calls formatDateTime if older. 15 | */ 16 | - (NSString*)formatRelativeTime; 17 | 18 | 19 | //yyyy-mm-dd 20 | - (NSString *)formatToDayTime:(NSDateFormatter *)formatter; 21 | 22 | 23 | //eg. 14:45 或 11月5 ,这里要用到NSDataFommater,从外部引入 24 | - (NSString *)formatMouthRelativeTime:(NSDateFormatter *)formatter; 25 | 26 | // yyyy-mm-dd hh-mm-ss 27 | - (NSString *)timeWithFormatter:(NSDateFormatter *)formatter; 28 | 29 | 30 | // 当天显示@"HH:mm", 否则显示@"yyyy-MM-dd HH:mm" 31 | - (NSString *)formatDetailRelativeTime; 32 | 33 | 34 | //该日期在当天已经经过的s数 35 | + (NSTimeInterval)todayIntervalWithFormatter:(NSDateFormatter *)formatter; 36 | 37 | 38 | //是否是当天时间 39 | - (BOOL)isTodayWithFormatter:(NSDateFormatter *)formatter; 40 | 41 | // 年份 42 | - (NSString *)yearWithFormatter:(NSDateFormatter *)formatter; 43 | 44 | //月份 45 | - (NSString *)monthWithFormatter:(NSDateFormatter *)formatter; 46 | 47 | // 日期 48 | - (NSString *)dayWithFormatter:(NSDateFormatter *)formatter; 49 | 50 | 51 | //所给日期于当前日期是否在同一天 52 | - (BOOL)inSomeDay:(NSDate *)date withFormatter:(NSDateFormatter *)formatter; 53 | 54 | //used for test 55 | + (NSDate *)random; 56 | + (NSDate *)randomBetweenYear:(NSUInteger)one andYear:(NSUInteger)two; 57 | 58 | 59 | 60 | @end 61 | 62 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSDictionary+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+additions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDictionary (additions) 12 | 13 | - (BOOL)check; 14 | 15 | // api中往往不欢迎nil的value,会导致崩溃 16 | - (NSDictionary *)replaceNilValue;//it doesnot work! 17 | 18 | - (NSMutableDictionary *)propertyListDictionary; 19 | - (id)modelFromDictionaryWithClassName:(Class)clazz; 20 | 21 | - (NSDictionary *)conversionWithModelMap:(NSDictionary *)map; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSLocale+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSLocale+additions.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-10. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSLocale (additions) 12 | 13 | + (NSArray *)allCountries;// identifier default @"en_US" 14 | + (NSArray *)languagesWithIdentifier:(NSString *)identifier; 15 | + (NSArray *)countriesWithIdentifier:(NSString *)identifier; 16 | 17 | /** 18 | * 19 | * 20 | * @param identifier 地区码,格式是:语言码_国家码 eg. en_US, zh_CN, fr_FR 21 | * @param flag 是否带国旗信息 22 | * 23 | * @return @{country, code} 24 | */ 25 | + (NSArray *)countriesWithIdentifier:(NSString *)identifier flag:(BOOL)flag;//带国旗,每一项是dictionary , 一个helper api ,方便显示国旗用 26 | 27 | // identifier 默认为@“en_US” 28 | + (NSString *)countryCodeWithName:(NSString *)countryName; 29 | 30 | /** 31 | * 32 | * 33 | * @param countryName 国家名字 34 | * @param identifier 同上 35 | * 36 | * @return 返回country code 37 | */ 38 | + (NSString *)countryCodeWithName:(NSString *)countryName inIdentifier:(NSString *)identifier; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSLocale+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSLocale+additions.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-10. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSLocale+additions.h" 10 | #import "foundation.h" 11 | 12 | @implementation NSLocale (additions) 13 | 14 | + (NSArray *)languagesWithIdentifier:(NSString *)identifier{ 15 | NSMutableArray *unsortLanguages = [NSMutableArray array]; 16 | NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:identifier]; 17 | for (NSString *code in [NSLocale ISOLanguageCodes]) { 18 | NSString *lang = [locale displayNameForKey:NSLocaleLanguageCode value:code]; 19 | if (lang) {// 为nil会崩溃 20 | [unsortLanguages addObject:lang]; 21 | } 22 | 23 | } 24 | 25 | return [unsortLanguages sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; 26 | 27 | } 28 | 29 | 30 | + (NSArray *)countriesWithIdentifier:(NSString *)identifier{ 31 | NSMutableArray *unsortCountries = [NSMutableArray array]; 32 | NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:identifier]; 33 | for (NSString *code in [NSLocale ISOCountryCodes]) { 34 | NSString *country = [locale displayNameForKey:NSLocaleCountryCode value:code]; 35 | [unsortCountries addObject:country]; 36 | } 37 | 38 | return [unsortCountries sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; 39 | } 40 | 41 | + (NSArray *)countriesWithIdentifier:(NSString *)identifier flag:(BOOL)flag{ 42 | 43 | NSMutableArray *unsortCountries = [NSMutableArray array]; 44 | NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:identifier]; 45 | for (NSString *code in [NSLocale ISOCountryCodes]) { 46 | NSString *country = [locale displayNameForKey:NSLocaleCountryCode value:code]; 47 | [unsortCountries addObject:@{@"country":country,@"code":code}]; 48 | } 49 | 50 | NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"country" ascending:YES]; 51 | return [unsortCountries sortedArrayUsingDescriptors:@[descriptor]]; 52 | } 53 | 54 | + (NSArray *)allCountries{ 55 | NSArray *countries = [NSLocale countriesWithIdentifier:@"en_US" flag:YES]; 56 | NSMutableArray *all = [NSMutableArray array]; 57 | for (NSDictionary *item in countries) { 58 | /* 59 | { 60 | code = PS; 61 | country = "Palestinian Territories"; 62 | } 63 | */ 64 | NSString *c = item[@"country"]; 65 | if (c) { 66 | [all addObject:c]; 67 | } 68 | } 69 | return all; 70 | } 71 | 72 | + (NSString *)countryCodeWithName:(NSString *)countryName{ 73 | if (![countryName isString]) { 74 | return nil; 75 | } 76 | return [[self class] countryCodeWithName:countryName inIdentifier:@"en_US"]; 77 | } 78 | 79 | + (NSString *)countryCodeWithName:(NSString *)countryName inIdentifier:(NSString *)identifier{ 80 | 81 | if (![countryName isString]) { 82 | return nil; 83 | } 84 | 85 | if (![identifier isString]) { 86 | return nil; 87 | } 88 | 89 | NSLocale *locale = [NSLocale localeWithLocaleIdentifier:identifier]; 90 | for (NSString *code in [NSLocale ISOCountryCodes]) { 91 | if ([countryName isEqualToString:[locale displayNameForKey:NSLocaleCountryCode value:code]]) {////这里比较耗时 92 | return code; 93 | } 94 | } 95 | return nil; 96 | } 97 | 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSMutableArray+addtions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableArray+addtions.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSMutableArray (addtions) 12 | 13 | - (void)replaceObject:(id)oldObject withObject:(id)newObject; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSMutableArray+addtions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableArray+addtions.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSMutableArray+addtions.h" 10 | 11 | @implementation NSMutableArray (addtions) 12 | 13 | - (void)replaceObject:(id)oldObject withObject:(id)newObject{ 14 | 15 | NSUInteger index = [self indexOfObject:oldObject]; 16 | if (index != NSNotFound) { 17 | [self replaceObjectAtIndex:index withObject:newObject]; 18 | } 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSNumber+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSNumber+additions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-2-8. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSNumber (additions) 12 | 13 | - (NSString *)fileSize; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSNumber+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSNumber+additions.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-2-8. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSNumber+additions.h" 10 | 11 | @implementation NSNumber (additions) 12 | 13 | - (NSString *)fileSize{ 14 | 15 | NSString *ret; 16 | unsigned long long size = [self unsignedLongLongValue]; 17 | if (size<1024) { 18 | ret = [NSString stringWithFormat:@"%llu bytes",size]; 19 | }else if (size<1024*1024) { 20 | ret = [NSString stringWithFormat:@"%.1lf KB",size/1024.f]; 21 | }else if (size<1024*1024*1024) { 22 | ret = [NSString stringWithFormat:@"%.1lf MB",size/(1024.f*1024.f)]; 23 | } 24 | 25 | return ret; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSObject+KeyPath.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+KeyPath.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSObject (KeyPath) 12 | 13 | - (id)dataForKeyPath:(NSString *)keyPath; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSObject+KeyPath.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+KeyPath.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSObject+KeyPath.h" 10 | 11 | @implementation NSObject (KeyPath) 12 | 13 | // resutl.data.imgs 递归实现 14 | - (id)dataForKeyPath:(NSString *)keyPath{ 15 | 16 | NSRange range = [keyPath rangeOfString:@"."]; 17 | if (range.location == NSNotFound) { 18 | id value = nil; 19 | @try { 20 | value = [self valueForKey:keyPath]; 21 | } 22 | @catch (NSException *exception) { 23 | NSLog(@"ERROR:[%@ valueforKey:%@] exception!!",[self class],keyPath); 24 | value = nil; 25 | } 26 | 27 | return value; 28 | } 29 | NSString *key = [keyPath substringToIndex:range.location]; 30 | 31 | //id value = [self valueForKey:key];// 如果没有这个属性,会崩溃 32 | id value = nil; 33 | @try { 34 | value = [self valueForKey:key]; 35 | } 36 | @catch (NSException *exception) { 37 | NSLog(@"ERROR:[%@ valueforKey:%@] exception!!",[self class],key); 38 | value = nil; 39 | } 40 | 41 | return [value dataForKeyPath:[keyPath substringFromIndex:range.location+range.length]]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSObject+check.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+check.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-17. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSObject (check) 12 | 13 | - (BOOL)isArray; 14 | - (BOOL)isDictionary; 15 | - (BOOL)isString; 16 | - (BOOL)isNumber; 17 | - (BOOL)isNull; 18 | - (BOOL)isImage; 19 | - (BOOL)isData; 20 | 21 | 22 | - (BOOL)booleanValueForKey:(NSString *)key default:(BOOL)defaultValue; 23 | -(BOOL) booleanValueForKey:(NSString *) key; 24 | 25 | - (NSDictionary *)dictionaryRepresentation; 26 | - (NSString *)JSONString;// 对象序列化,多用于存储, 字典调用 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSString+MD5.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MD5.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (MD5) 12 | 13 | 14 | - (NSString *)URLEncode; 15 | - (NSString *)encodeURLStringByAddingEscapteString; 16 | - (NSString *)decodeURLStringByAddingEscapteString; 17 | 18 | 19 | - (NSString *)md5Encode; 20 | - (NSString *)SHA1Encode; 21 | 22 | // base64 string ---> data , 兼容iOS6 23 | - (NSData *)base64Decode; 24 | 25 | - (NSString *)AESEncodeUsingKey:(NSString *)key; 26 | - (NSString *)AESDecodeUsingKey:(NSString *)key; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSString+MD5.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MD5.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "NSString+MD5.h" 11 | #import "NSData+AES.h" 12 | #import "Olla4iOS.h" 13 | 14 | @implementation NSString (MD5) 15 | 16 | - (NSString *)URLEncode{ 17 | return [self stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 18 | } 19 | 20 | //影响url query的有 “=” “ ” 21 | - (NSString *)encodeURLStringByAddingEscapteString{ 22 | 23 | CFStringRef strRef = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self,NULL ,(CFStringRef)@"=" , kCFStringEncodingUTF8); 24 | NSString *output = [[NSString alloc] initWithString:(__bridge NSString *)strRef]; 25 | CFRelease(strRef); 26 | return output; 27 | 28 | 29 | } 30 | 31 | - (NSString *)decodeURLStringByAddingEscapteString{ 32 | 33 | return nil; 34 | } 35 | 36 | 37 | - (NSString *)md5Encode{ 38 | 39 | const char *cString = [self UTF8String]; 40 | unsigned char result[CC_MD5_DIGEST_LENGTH]; 41 | CC_MD5(cString, (int)[self length] , result); 42 | NSMutableString *hash = [[NSMutableString alloc] init]; 43 | for (int i=0; i<16; i++) { 44 | [hash appendFormat:@"%02X",result[i]]; 45 | } 46 | return [hash lowercaseString]; 47 | } 48 | 49 | 50 | - (NSString *)SHA1Encode{ 51 | 52 | const char *cString = [self UTF8String]; 53 | unsigned char result[CC_SHA1_DIGEST_LENGTH]; 54 | CC_SHA1(cString, (int)[self length], result); 55 | NSMutableString *hash = [[NSMutableString alloc] init]; 56 | for (int i=0; i<20; i++) { 57 | [hash appendFormat:@"%02X",result[i]]; 58 | } 59 | return [hash lowercaseString]; 60 | 61 | } 62 | 63 | 64 | - (NSData *)base64Decode{ 65 | 66 | if (IS_IOS7) { 67 | return nil; 68 | }else{ 69 | #pragma clang diagnostic push 70 | #pragma clang diagnostic ignored "-Wdeprecated" 71 | return [[NSData alloc] initWithBase64Encoding:self]; 72 | #pragma clang diagnostic pop 73 | } 74 | 75 | return nil; 76 | } 77 | 78 | 79 | - (NSString *)AESEncodeUsingKey:(NSString *)key{ 80 | NSData *encodeData = [[self dataUsingEncoding:NSUTF8StringEncoding] AES256EncodeWithKey:key]; 81 | // 这里如果用UTF8编码data就会得到一个nil的string,换一个编码,如base64来编码 or ascii 82 | //NSString *encodeString = [[NSString alloc] initWithData:encodeData encoding:NSUTF8StringEncoding]; 83 | return [encodeData base64Encode]; 84 | } 85 | 86 | - (NSString *)AESDecodeUsingKey:(NSString *)key{ 87 | NSData *decodeData = [self dataUsingEncoding:NSASCIIStringEncoding]; 88 | NSData *orignalData = [decodeData AES256DecodeWithKey:key]; 89 | NSString *decodeString = [[NSString alloc] initWithData:orignalData encoding:NSUTF8StringEncoding]; 90 | return decodeString; 91 | 92 | } 93 | 94 | 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSString+ORM.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+ORM.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-28. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (ORM) 12 | 13 | - (id)modelFromJSONWithClassName:(Class)clazz; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSString+ORM.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+ORM.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-28. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSString+ORM.h" 10 | #import "NSDictionary+additions.h" 11 | 12 | @implementation NSString (ORM) 13 | 14 | 15 | //JSONKit,不支持arc 16 | - (id)modelFromJSONWithClassName:(Class)clazz{ 17 | 18 | NSError *error = nil; 19 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&error]; 20 | if (error) { 21 | NSLog(@"JSON Read ERROR:%@\n Original String=%@",error,self); 22 | return nil; 23 | } 24 | 25 | return [dict modelFromDictionaryWithClassName:clazz]; 26 | 27 | } 28 | 29 | // 重写 NSObject+check 30 | - (NSDictionary *)dictionaryRepresentation{ 31 | 32 | NSError *error= nil; 33 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&error]; 34 | if (error) { 35 | NSLog(@"JSON parse ERROR:%@\n Original String=%@",error,self); 36 | } 37 | 38 | return dict; 39 | } 40 | 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSString+size.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+size.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-16. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface NSString (size) 13 | 14 | //计算字符串占据的size 15 | - (CGSize)sizeWithFont:(UIFont *)font constrainedSize:(CGSize)size; 16 | 17 | - (CGSize)sizeWithFont:(UIFont *)font constrainedSize:(CGSize)size numberOfLine:(NSUInteger)lines; 18 | 19 | //判断是否含有字串,iOS8以后才添加了一个-containsString的方法 20 | - (BOOL)containsSubString:(NSString *)string; 21 | 22 | // 在64为机器上,string转为NSUInteger会调用该方法抛错 23 | //- (NSUInteger)unsignedLongLongValue; 24 | 25 | // 过滤掉字符串头部和尾部的空格 26 | - (NSString *)escapeSpace; 27 | - (NSString *)firstLetter; 28 | - (NSString *)addEscapeSQLCharacters;//如果消息中又 “ ‘ 这样的字符会影响插入,需要加入转义字符 29 | - (NSString *)removeEscapeSQLCharacters; 30 | - (BOOL)isHTTPURL; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/NSString+size.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+size.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-16. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "NSString+size.h" 10 | #import "Olla4iOS.h" 11 | 12 | @implementation NSString (size) 13 | 14 | //TODO: 这里先用integerValue 15 | //- (NSUInteger)unsignedLongLongValue{ 16 | // return [self integerValue]; 17 | //} 18 | 19 | - (BOOL)containsSubString:(NSString *)string{ 20 | if (IS_IOS8) { 21 | return [self containsString:string]; 22 | } 23 | 24 | return ([self rangeOfString:string].length != 0); 25 | } 26 | 27 | - (CGSize)sizeWithFont:(UIFont *)font constrainedSize:(CGSize)size{ 28 | 29 | CGSize retSize = CGSizeZero; 30 | if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { 31 | 32 | CGRect rect = [self boundingRectWithSize:size options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil]; 33 | retSize.width = ceil(rect.size.width); 34 | retSize.height = ceil(rect.size.height); 35 | 36 | }else{ 37 | #pragma clang diagnostic push 38 | #pragma clang diagnostic ignored "-Wdeprecated" 39 | retSize = [self sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping]; 40 | #pragma clang diagnostic pop 41 | } 42 | 43 | return retSize; 44 | } 45 | 46 | - (CGSize)sizeWithFont:(UIFont *)font constrainedSize:(CGSize)size numberOfLine:(NSUInteger)lines{ 47 | CGFloat height = lines?font.lineHeight*lines:size.height; 48 | CGSize constrainedSize = CGSizeMake(size.width, height); 49 | return[self sizeWithFont:font constrainedSize:constrainedSize]; 50 | } 51 | 52 | - (NSString *)escapeSpace{ 53 | return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 54 | } 55 | 56 | - (NSString *)firstLetter{ 57 | 58 | if ([self length]) { 59 | return [self substringToIndex:1]; 60 | } 61 | 62 | return nil; 63 | } 64 | 65 | 66 | - (NSString *)addEscapeSQLCharacters{ 67 | 68 | NSRange range; 69 | NSMutableString *string = [NSMutableString string]; 70 | for (int i=0; i 10 | 11 | @interface NSURL (Query) 12 | 13 | @property(nonatomic,strong,readonly) NSDictionary *queryValue; 14 | 15 | - (NSString *)urlPath; // host+path 16 | 17 | - (NSDictionary *)queryValues; 18 | 19 | - (NSURL *)URLByAppendingPathComponent:(NSString *)string queryValue:(NSDictionary *)queryValue; 20 | 21 | + (NSURL *)URLWithString:(NSString *)string queryValue:(NSDictionary *)queryValue; 22 | 23 | + (NSURL *)URLWithString:(NSString *)string relativeToURL:(NSURL *)baseURL queryValues:(NSDictionary *)query; 24 | 25 | - (NSString *)firstPathComponent; 26 | 27 | - (NSString *)firstPathComponentRelativeTo:(NSString *)basePath; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIColor+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+additions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define RGBA_HEX(rgb,a) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:a] 12 | #define RGB_HEX(rgb) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0] // 如UIColorFromRGB(0x027A34) 13 | #define RGB_DECIMAL(r,g,b) [UIColor colorWithRed:((float)r)/255.0 green:((float)g)/255.0 blue:((float)b)/255.0 alpha:1.0] 14 | 15 | @interface UIColor (additions) 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIColor+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+additions.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIColor+additions.h" 10 | 11 | @implementation UIColor (additions) 12 | 13 | 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIDevice+Hardware.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+Hardware.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIDevice (Hardware) 12 | 13 | + (NSArray *)screenSizes; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIDevice+Hardware.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+Hardware.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIDevice+Hardware.h" 10 | 11 | @implementation UIDevice (Hardware) 12 | 13 | + (NSArray *)screenSizes{ 14 | 15 | return @[@"320x480", // iphone 3g,3gs,touch 1,2,3 16 | @"640x960", // iphone 4, 4s, touch 4 17 | @"640x1136",// iphone 5,5s,5c, touch 5 18 | @"750x1336",// iphone 6 (375x667 @2x) 19 | @"1242x2208",// iphone 6+ (414x736 @3x) 20 | @"768x1024",// ipad 1,2, mini 21 | @"1536x2048"// new ipad,ipad 4 22 | ]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIDevice+Identifier.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+Identifier.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIDevice (Identifier) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIDevice+Identifier.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+Identifier.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIDevice+Identifier.h" 10 | 11 | @implementation UIDevice (Identifier) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIDevice+software.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+software.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-2-8. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIDevice (software) 12 | 13 | + (BOOL)isJailBreak; 14 | 15 | /** 16 | * app 占用的内存 17 | * 18 | * @return 内存大小 19 | */ 20 | + (double)usedMemery; 21 | 22 | 23 | + (double)CPUUsage; 24 | 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIFont+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIFont+additions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-2-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIFont (additions) 12 | 13 | + (UIFont *)boldFont:(UIFont *)font; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIFont+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIFont+additions.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-2-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIFont+additions.h" 10 | #import 11 | 12 | @implementation UIFont (additions) 13 | 14 | + (UIFont *)boldFont:(UIFont *)font{ 15 | 16 | UIFont *result = nil; 17 | 18 | CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)(font.fontName), 19 | font.pointSize, NULL); 20 | if (ctFont) { 21 | // You can't add bold to a bold font 22 | // (don't really need this, since the ctBoldFont check would handle it) 23 | if ((CTFontGetSymbolicTraits(ctFont) & kCTFontTraitBold) == 0) { 24 | CTFontRef ctBoldFont = CTFontCreateCopyWithSymbolicTraits(ctFont, 25 | font.pointSize, 26 | NULL, 27 | kCTFontBoldTrait, 28 | kCTFontBoldTrait); 29 | if (ctBoldFont) { 30 | NSString *fontName = CFBridgingRelease(CTFontCopyPostScriptName(ctBoldFont)); 31 | result = [UIFont fontWithName:fontName size:font.pointSize]; 32 | CFRelease(ctBoldFont); 33 | } 34 | } 35 | CFRelease(ctFont); 36 | } 37 | return result; 38 | 39 | 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIImage+BoxBlur.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+BoxBlur.h 3 | // LiveBlurView 4 | // 5 | // Created by Alex Usbergo on 7/3/13. 6 | // Copyright (c) 2013 Alex Usbergo. All rights reserved. 7 | // 8 | // algorithm from: http://indieambitions.com/idevblogaday/perform-blur-vimage-accelerate-framework-tutorial/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+IndieAmbitions+%28Indie+Ambitions%29 9 | 10 | 11 | #import 12 | 13 | @interface UIImage (BoxBlur) 14 | 15 | /* blur the current image with a box blur algoritm */ 16 | - (UIImage*)drn_boxblurImageWithBlur:(CGFloat)blur; 17 | 18 | /* blur the current image with a box blur algoritm and tint with a color */ 19 | - (UIImage*)drn_boxblurImageWithBlur:(CGFloat)blur withTintColor:(UIColor*)tintColor; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIImage+Color.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Color.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface UIImage (Color) 13 | 14 | + (UIImage *)imageWithColor:(UIColor *)color; 15 | + (UIImage *)imageWithAsset:(ALAsset *)asset; 16 | 17 | - (UIImage *)imageWithTintColor:(UIColor *)color; 18 | - (UIImage *)imageWithTintColor:(UIColor *)color blendMode:(CGBlendMode)mode; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIImage+Color.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Color.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIImage+Color.h" 10 | 11 | 12 | @implementation UIImage (Color) 13 | 14 | + (UIImage *)imageWithColor:(UIColor *)color{ 15 | 16 | UIImage *image; 17 | CGRect rect = CGRectMake(0, 0, 1.f, 1.f); 18 | UIGraphicsBeginImageContext(rect.size); 19 | CGContextRef context = UIGraphicsGetCurrentContext(); 20 | CGContextSetFillColorWithColor(context, color.CGColor); 21 | CGContextFillRect(context, rect); 22 | image = UIGraphicsGetImageFromCurrentImageContext(); 23 | UIGraphicsEndImageContext(); 24 | return image; 25 | } 26 | 27 | + (UIImage *)imageWithAsset:(ALAsset *)asset{ 28 | CGImageRef imageRef = [[asset defaultRepresentation] fullResolutionImage]; 29 | return [UIImage imageWithCGImage:imageRef]; 30 | } 31 | 32 | 33 | - (UIImage *)imageWithTintColor:(UIColor *)color{ 34 | return [self imageWithTintColor:color blendMode:kCGBlendModeDestinationIn]; 35 | } 36 | 37 | - (UIImage *)imageWithTintColor:(UIColor *)color blendMode:(CGBlendMode)mode{ 38 | UIGraphicsBeginImageContext(self.size); 39 | [color setFill]; 40 | CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height); 41 | UIRectFill(bounds); 42 | [self drawInRect:bounds blendMode:mode alpha:1.f]; 43 | 44 | UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext(); 45 | UIGraphicsEndImageContext(); 46 | 47 | return destImage; 48 | } 49 | 50 | @end 51 | 52 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIImage+Filter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Filter.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (Filter) 12 | 13 | - (UIImage *)LOMOFilterOutput; // LOMO 14 | - (UIImage *)grayFilterOutput; //黑白 15 | - (UIImage *)vintageFilterOutput; //复古 16 | - (UIImage *)geteFilterOutput; // 哥特 17 | - (UIImage *)sharpFilterOutput; // 锐化 18 | - (UIImage *)elegantFilterOutput; //淡雅 19 | - (UIImage *)redWineFilterOutput; // 酒红 20 | - (UIImage *)quietFilterOutput; //清宁 21 | - (UIImage *)romanticFilterOutput; // 浪漫 22 | - (UIImage *)shineFilterOutput; // 光晕 23 | - (UIImage *)blueFilterOutput; // 蓝调 24 | - (UIImage *)dreamFilterOutput; // 梦幻 25 | - (UIImage *)darkFilterOutput; // 夜色 26 | 27 | - (UIImage *)gaussBlurFilterWithLevel:(CGFloat)blurLevel; // 高斯模糊X 28 | - (UIImage *)blurWithLevel:(CGFloat)blurLevel; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIImage+Resize.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Resize.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (Resize) 12 | 13 | // 图片可能会变形 14 | - (UIImage *)resizeImageWithSize:(CGSize)size; 15 | 16 | 17 | // 考虑到图片的比例来压缩,以宽?高?为准 18 | - (UIImage *)resizeAspectImageWithSize:(CGSize)size; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/addtions/UIImage+Resize.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Resize.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIImage+Resize.h" 10 | 11 | @implementation UIImage (Resize) 12 | 13 | // not thread safe 14 | - (UIImage *)resizeImageWithSize:(CGSize)size{ 15 | 16 | UIGraphicsBeginImageContext(size); 17 | [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; 18 | UIImage *scaleImage = UIGraphicsGetImageFromCurrentImageContext(); 19 | UIGraphicsEndImageContext(); 20 | return scaleImage; 21 | 22 | } 23 | 24 | 25 | //eg 640*1136 , 以宽为准,高度等比例缩放 26 | - (UIImage *)resizeAspectImageWithSize:(CGSize)size{ 27 | 28 | 29 | CGFloat widthScale = size.width/self.size.width; // 以宽为准 30 | CGFloat height = widthScale * self.size.height;// 31 | 32 | UIGraphicsBeginImageContext(CGSizeMake(size.width,height)); 33 | [self drawInRect:CGRectMake(0, 0, size.width, height)]; 34 | UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 35 | 36 | UIGraphicsEndImageContext(); 37 | 38 | return scaledImage; 39 | 40 | } 41 | 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/assetLibrary/ALAsset+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // ALAsset+additions.h 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-19. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ALAsset (additions) 12 | 13 | //type 14 | - (BOOL)isPhoto; 15 | - (BOOL)isVideo; 16 | 17 | // 18 | - (BOOL)isEqual:(id)object; 19 | 20 | //原图的md5值 21 | - (NSString *)md5Encode; 22 | 23 | //是否是屏幕截图 24 | - (BOOL)isScreenshot; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/assetLibrary/ALAsset+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // ALAsset+additions.m 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-19. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import "ALAsset+additions.h" 10 | #import "NSData+AES.h" 11 | #import "UIDevice+Hardware.h" 12 | 13 | @implementation ALAsset (additions) 14 | 15 | - (BOOL)isPhoto{ 16 | 17 | return [[self valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]; 18 | } 19 | 20 | - (BOOL)isVideo{ 21 | return [[self valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]; 22 | } 23 | 24 | // 25 | - (BOOL)isEqual:(id)object{ 26 | 27 | if (![object isKindOfClass:[ALAsset class]]) { 28 | return NO; 29 | } 30 | 31 | return [[self valueForProperty:ALAssetPropertyAssetURL] isEqualToString:[object valueForProperty:ALAssetPropertyAssetURL]]; 32 | } 33 | 34 | - (NSString *)md5Encode{ 35 | 36 | CGImageRef imageRef = [[self defaultRepresentation] fullResolutionImage]; 37 | UIImage *image = [UIImage imageWithCGImage:imageRef]; 38 | NSData *data = UIImageJPEGRepresentation(image, 1); 39 | return [data md5Encode]; 40 | 41 | } 42 | 43 | 44 | - (BOOL)isScreenshot{ 45 | 46 | CGSize sz = [self.defaultRepresentation dimensions]; 47 | NSString *size = [NSString stringWithFormat:@"%.0fx%.0f",sz.width,sz.height]; 48 | NSString *UTI = [self.defaultRepresentation UTI]; 49 | if ([UTI isEqualToString:@"public.png"] && [[UIDevice screenSizes] containsObject:size]) { 50 | return YES; 51 | } 52 | 53 | return NO; 54 | } 55 | 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/assetLibrary/ALAssetsGroup+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // ALAssetsGroup+additions.h 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-19. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ALAssetsGroup (additions) 12 | 13 | - (NSString *)name; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/assetLibrary/ALAssetsGroup+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // ALAssetsGroup+additions.m 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-19. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import "ALAssetsGroup+additions.h" 10 | 11 | @implementation ALAssetsGroup (additions) 12 | 13 | - (NSString *)name{ 14 | return [self valueForProperty:ALAssetsGroupPropertyName]; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/assetLibrary/OllaAssetsLoader.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaAssetsLoader.h 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-19. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AssetsLibrary/AssetsLibrary.h" 11 | 12 | @interface OllaAssetsLoader : NSObject 13 | 14 | 15 | - (id)initWithAssetsLibrary:(ALAssetsLibrary *)assetsLibrary; 16 | 17 | - (void)fetchAssets:(void (^)(ALAssetsGroup *group, ALAsset *result, NSUInteger index,BOOL *stop))asset finishBlock:(void (^)(NSArray *assets))finishBlock failureBlock:(void (^)(NSError *error))failure; 18 | 19 | 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/assetLibrary/OllaAssetsLoader.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaAssetsLoader.m 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-19. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import "OllaAssetsLoader.h" 10 | #import "ALAsset+additions.h" 11 | #import "Olla4iOS.h" 12 | 13 | @interface OllaAssetsLoader () 14 | 15 | @property(nonatomic,strong) ALAssetsLibrary *assetsLibrary; 16 | 17 | @end 18 | 19 | @implementation OllaAssetsLoader 20 | 21 | - (instancetype)init{ 22 | 23 | ALAssetsLibrary *__assetsLibrary = [[ALAssetsLibrary alloc] init]; 24 | return [self initWithAssetsLibrary:__assetsLibrary]; 25 | } 26 | 27 | - (id)initWithAssetsLibrary:(ALAssetsLibrary *)assetsLibrary{ 28 | if (self=[super init]) { 29 | _assetsLibrary = assetsLibrary; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)fetchAssets:(void (^)(ALAssetsGroup *group, ALAsset *result, NSUInteger index,BOOL *stop))assetBlock finishBlock:(void (^)(NSArray *assets))finishBlock failureBlock:(void (^)(NSError *error))failure{ 35 | 36 | NSMutableArray *assets = [NSMutableArray array]; 37 | NSMutableArray *assetGroups = [NSMutableArray array]; 38 | 39 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 40 | 41 | //groups process 42 | void (^ assetGroupEnumerator)(ALAssetsGroup *group, BOOL *stop) = ^(ALAssetsGroup *group, BOOL *stop){ 43 | 44 | if (group) { 45 | [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){ 46 | 47 | if (result && [result isPhoto]) { 48 | 49 | [assets addObject:result]; 50 | dispatch_async(dispatch_get_main_queue(), ^{ 51 | assetBlock(group,result,index,stop); 52 | }); 53 | } 54 | 55 | }]; 56 | [assetGroups addObject:group]; 57 | } 58 | }; 59 | 60 | // start ALAssetsGroupSavedPhotos 61 | [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop){ 62 | 63 | assetGroupEnumerator(group,stop); 64 | 65 | dispatch_async(dispatch_get_main_queue(), ^{ 66 | finishBlock(assets); 67 | }); 68 | 69 | 70 | } failureBlock:^(NSError *error) { 71 | if (error) { 72 | DDLogError(@"遍历系统相册失败:%@",error); 73 | dispatch_async(dispatch_get_main_queue(), ^{ 74 | failure(error); 75 | }); 76 | } 77 | }]; 78 | 79 | 80 | }); 81 | } 82 | 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/audio/OllaAudioSound.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaAudioSound.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-6. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OllaAudioSound : NSObject 12 | 13 | + (void)playAudioSound:(NSString *)audioName; 14 | + (void)playAudioSound:(NSString *)audioName bundle:(NSBundle *)bundle; 15 | 16 | + (void)vibrate; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/audio/OllaAudioSound.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaAudioSound.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-6. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaAudioSound.h" 10 | #import 11 | 12 | @implementation OllaAudioSound 13 | 14 | + (void)playAudioSound:(NSString *)audioName{ 15 | 16 | [OllaAudioSound playAudioSound:audioName bundle:[NSBundle mainBundle]]; 17 | } 18 | 19 | 20 | + (void)playAudioSound:(NSString *)audioName bundle:(NSBundle *)bundle{ 21 | 22 | SystemSoundID systemSoundID = 0; 23 | NSString *path = [bundle pathForResource:audioName ofType:@"wav"]; 24 | NSURL *url = [NSURL URLWithString:path]; 25 | AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &systemSoundID); 26 | AudioServicesPlaySystemSound(systemSoundID); 27 | AudioServicesRemoveSystemSoundCompletion(systemSoundID); 28 | //AudioServicesDisposeSystemSoundID(systemSoundID);// 直接dispose将不会播出声音 29 | 30 | } 31 | 32 | 33 | + (void)vibrate{ 34 | AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/foundation.h: -------------------------------------------------------------------------------- 1 | // 2 | // system.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #ifndef OllaFramework_foundation_h 10 | #define OllaFramework_foundation_h 11 | 12 | 13 | 14 | // addtions 15 | #import "NSURL+Query.h" 16 | #import "NSArray+addtions.h" 17 | #import "NSMutableArray+addtions.h" 18 | #import "NSAttributedString+Height.h" 19 | #import "NSDate+additions.h" 20 | #import "NSDate+Utilities.h" //by @erica 21 | #import "NSDictionary+additions.h" 22 | #import "NSNumber+additions.h" 23 | #import "NSString+MD5.h" 24 | #import "NSString+size.h" 25 | #import "NSString+ORM.h" 26 | #import "NSData+AES.h" 27 | #import "UIColor+additions.h" 28 | #import "UIDevice+Hardware.h" 29 | #import "UIDevice+software.h" 30 | #import "UIDevice+Identifier.h" 31 | #import "UIFont+additions.h" 32 | #import "UIImage+Color.h" 33 | #import "UIImage+BoxBlur.h" 34 | #import "UIImage+Filter.h" 35 | #import "UIImage+Resize.h" 36 | #import "NSLocale+additions.h" 37 | #import "NSObject+check.h" 38 | #import "NSObject+KeyPath.h" 39 | 40 | //util 41 | #import "OllaSandBox.h" 42 | #import "GCDHelper.h" 43 | #import "OllaKeychain.h" 44 | 45 | 46 | // network 47 | #import "OllaSocket.h" 48 | 49 | // preferenc 50 | #import "OllaPreference.h" 51 | 52 | // audio 53 | #import "OllaAudioSound.h" 54 | 55 | // asset Library 56 | #import "ALAsset+additions.h" 57 | #import "ALAssetsGroup+additions.h" 58 | #import "OllaAssetsLoader.h" 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/network/OllaSocket.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaSocket.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-9. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger,OllaSocketErrorCode){ 12 | 13 | SocketErrorServerRespondDisconnect = -2, 14 | SocketErrorHeartbeatTimeout = -1, 15 | SocketErrorHandShake = 0, 16 | SocketErrorUnauthorized = 1 17 | 18 | }; 19 | 20 | @interface OllaSocket : NSObject 21 | 22 | /** 23 | * 1. 超时时间,多久没收到数据就表示socket断开了 24 | * 2. 每个ns发一个心跳包,没有respond表示socke断开了 25 | */ 26 | @property(nonatomic,assign) NSTimeInterval heartbeatTimeout; 27 | 28 | - (id)initWithDelegate:(id)delegate; 29 | 30 | - (void)connectOnHost:(NSString *)host port:(UInt16)port; 31 | - (void)connectOnHost:(NSString *)host port:(UInt16)port timeout:(NSTimeInterval)timeout; 32 | - (void)disconnect; 33 | 34 | - (void)sendData:(NSData *)data tag:(long)tag; 35 | - (void)readData:(NSData *)data tag:(long)tag; 36 | 37 | - (BOOL)isValid; 38 | 39 | - (int)portFromSocket;// 获得当前连接的本地port 40 | 41 | @end 42 | 43 | 44 | @protocol OllaSocketDelegate 45 | @optional 46 | - (void)socket:(OllaSocket *)socket didConnectToHost:(NSString *)host port:(UInt16)port; 47 | - (void)socketDidDisConnect:(OllaSocket *)socket withError:(NSError *)error; 48 | 49 | - (void)socket:(OllaSocket *)socket didReadData:(NSData *)data tag:(long)tag; 50 | - (void)socket:(OllaSocket *)socket didWriteData:(NSData *)data tag:(long)tag; 51 | 52 | @end 53 | 54 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/preference/OllaPreference.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaPreference.h 3 | // Olla 4 | // 5 | // Created by null on 14-10-18. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OllaPreference : NSObject 12 | 13 | @property(nonatomic,copy) NSString *uid; 14 | @property(nonatomic,copy) NSString *fullNamespace; 15 | @property(nonatomic,copy) NSString *path;//文件存储路径 16 | 17 | + (OllaPreference *)defaultInstance; 18 | 19 | - (id)valueForKey:(NSString *)defaultName; 20 | - (void)setValue:(id)value forKey:(NSString *)defaultName; 21 | - (void)addUserInfo:(NSDictionary *)userInfo; 22 | - (void)removeValueForKey:(NSString *)defaultName; 23 | 24 | - (BOOL)synchronize; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/preference/OllaPreference.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaPreference.m 3 | // Olla 4 | // 5 | // Created by null on 14-10-18. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaPreference.h" 10 | #import "Olla4iOS.h" 11 | 12 | @interface OllaPreference (){ 13 | 14 | NSString *_currentFilePath;//文件绝对路径 15 | NSString *_fullNamespace;// 文件命名前缀 16 | } 17 | 18 | @property(nonatomic,strong) NSMutableDictionary *userInfo; 19 | 20 | 21 | @end 22 | 23 | @implementation OllaPreference 24 | 25 | + (OllaPreference *)defaultInstance{ 26 | 27 | static OllaPreference *instance = nil; 28 | static dispatch_once_t onceToken; 29 | dispatch_once(&onceToken, ^{ 30 | instance = [[OllaPreference alloc] init]; 31 | }); 32 | 33 | return instance; 34 | } 35 | 36 | - (NSString *)fullNamespace{ 37 | if (!_fullNamespace) { 38 | _fullNamespace = @"com.between.olla"; 39 | } 40 | return _fullNamespace; 41 | } 42 | 43 | - (NSString *)path{ 44 | 45 | if (!_path) { 46 | _path = [OllaSandBox libPrefPath]; 47 | } 48 | return _path; 49 | } 50 | 51 | 52 | - (NSString *)filePath{ 53 | 54 | if (!_currentFilePath) { 55 | NSString *filePath = [self.path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@.plist",self.fullNamespace ,self.uid]]; 56 | if (![OllaSandBox createFileIfNotExist:filePath]) { 57 | DDLogError(@"创建文件失败:path=%@",filePath); 58 | return nil; 59 | } 60 | _currentFilePath = filePath; 61 | } 62 | 63 | return _currentFilePath; 64 | 65 | } 66 | 67 | - (NSMutableDictionary *)userInfo{ 68 | 69 | if (!_userInfo) { 70 | _userInfo = [[NSMutableDictionary alloc] initWithContentsOfFile:[self filePath]]; 71 | if(!_userInfo){ 72 | _userInfo = [NSMutableDictionary dictionary]; 73 | } 74 | 75 | } 76 | return _userInfo; 77 | } 78 | 79 | 80 | - (void)setUid:(NSString *)uid{ 81 | 82 | if (_uid != uid) { 83 | 84 | _uid = uid; 85 | if ([uid length]==0) { 86 | DDLogWarn(@"uid设置为空,设置uid先"); 87 | return; 88 | } 89 | } 90 | } 91 | 92 | - (id)valueForKey:(NSString *)defaultName{ 93 | if ([self.uid length]==0) { 94 | DDLogError(@"uid设置为空,设置uid先"); 95 | return nil; 96 | } 97 | id value = [self.userInfo valueForKey:defaultName]; 98 | return value; 99 | } 100 | 101 | - (void)setValue:(id)value forKey:(NSString *)defaultName{ 102 | if ([self.uid length]==0) { 103 | DDLogError(@"设置uid先"); 104 | return; 105 | } 106 | if (!value) { 107 | return; 108 | } 109 | if ([value isNull]) { 110 | value = @""; 111 | } 112 | [self.userInfo setValue:value forKey:defaultName]; 113 | [self synchronize]; 114 | } 115 | 116 | - (void)addUserInfo:(NSDictionary *)__userInfo{ 117 | [self.userInfo addEntriesFromDictionary:[__userInfo propertyListDictionary]]; 118 | [self synchronize]; 119 | } 120 | 121 | - (void)removeValueForKey:(NSString *)defaultName{ 122 | if ([self.uid length]==0) { 123 | DDLogError(@"设置uid先"); 124 | return; 125 | } 126 | [self.userInfo removeObjectForKey:defaultName]; 127 | [self synchronize]; 128 | } 129 | 130 | - (BOOL)synchronize{ 131 | 132 | BOOL ret = [self.userInfo writeToFile:_currentFilePath atomically:YES]; 133 | if (!ret) { 134 | DDLogError(@"preference 写入plist文件失败,userInfo = %@,filePath=%@",self.userInfo,[self filePath]); 135 | } 136 | 137 | return ret; 138 | } 139 | 140 | @end 141 | 142 | 143 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/util/GCDHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // BlockHelper.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-4-23. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface GCDHelper : NSObject 12 | 13 | + (void)handleImageInBackground:(void (^)())block completion:(void (^)())block; 14 | // 当一连串的事情顺序执行时调用 15 | + (void)handleSerialTask:(void (^)())block completion:(void (^)())complete; 16 | 17 | + (void)dispatchBlock:(void (^)())block completion:(void (^)())block; 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/util/GCDHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // BlockHelper.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-4-23. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "GCDHelper.h" 10 | 11 | @implementation GCDHelper 12 | static dispatch_queue_t seria_queue; 13 | static dispatch_queue_t image_queue; 14 | static dispatch_queue_t image_handle_queue(){ 15 | if (image_queue==NULL) { 16 | image_queue = dispatch_queue_create("com.nonstriater.queue.image.filter",0); 17 | } 18 | return image_queue; 19 | } 20 | 21 | static dispatch_queue_t serial_task_queue(){ 22 | 23 | if (seria_queue==NULL) { 24 | seria_queue = dispatch_queue_create("com.nonstriater.queue.serial", NULL); 25 | } 26 | 27 | return seria_queue; 28 | } 29 | 30 | + (void)handleSerialTask:(void (^)())block completion:(void (^)())complete{ 31 | 32 | dispatch_async(serial_task_queue(), ^{ 33 | @autoreleasepool { 34 | 35 | if (block) { 36 | block(); 37 | } 38 | dispatch_async(dispatch_get_main_queue(), ^{ 39 | 40 | if (complete) { 41 | complete(); 42 | } 43 | }); 44 | } 45 | }); 46 | 47 | 48 | } 49 | 50 | + (void)handleImageInBackground:(void (^)())block completion:(void (^)())finish{ 51 | 52 | dispatch_async(image_handle_queue(),^{ 53 | @autoreleasepool { 54 | block(); 55 | dispatch_async(dispatch_get_main_queue(),^{ 56 | finish(); 57 | }); 58 | } 59 | }); 60 | } 61 | 62 | + (void)dispatchBlock:(void (^)())block completion:(void (^)())finish{ 63 | 64 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 65 | 66 | @autoreleasepool { 67 | if (block) { 68 | block(); 69 | } 70 | 71 | dispatch_async(dispatch_get_main_queue(), ^{ 72 | if (finish) {// finish 为nil 崩溃!! 73 | finish(); 74 | } 75 | 76 | }); 77 | } 78 | }); 79 | 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/util/OllaKeychain.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaKeychain.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OllaKeychain : NSObject 12 | 13 | + (NSString *)passwordForService:(NSString *)service account:(NSString *)account error:(NSError **)error; 14 | 15 | + (BOOL)setPassword:(NSString *)password forService:(NSString *)service account:(NSString *)account error:(NSError **)error; 16 | 17 | + (BOOL)deletePasswordForService:(NSString *)service account:(NSString *)account error:(NSError **)error; 18 | 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/util/OllaSandBox.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaSandBox.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-23. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OllaSandBox : NSObject 12 | 13 | + (NSString *)appPath; 14 | + (NSString *)documentPath; 15 | + (NSString *)libraryPath; 16 | + (NSString *)libPrefPath; 17 | + (NSString *)libCachePath; 18 | + (NSString *)tmpPath; 19 | 20 | + (BOOL)createPathIfNotExist:(NSString *)path; 21 | + (BOOL)createFileIfNotExist:(NSString *)path; 22 | + (BOOL)deleteItem:(NSString *)path; 23 | + (BOOL)copyItem:(NSString *)srcPath toPath:(NSString *)destPath; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Olla4iOS/foundation/util/OllaSandBox.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaSandBox.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-23. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaSandBox.h" 10 | 11 | @implementation OllaSandBox 12 | 13 | + (NSString *)appPath{ 14 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES); 15 | if ([paths count]>0) { 16 | return [paths objectAtIndex:0]; 17 | } 18 | return nil; 19 | 20 | } 21 | //NSHomeDirectory() 22 | 23 | + (NSString *)documentPath{ 24 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 25 | if ([paths count]>0) { 26 | return [paths objectAtIndex:0]; 27 | } 28 | return nil; 29 | } 30 | + (NSString *)libraryPath{ 31 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 32 | if ([paths count]>0) { 33 | return [paths objectAtIndex:0]; 34 | } 35 | return nil; 36 | 37 | } 38 | + (NSString *)libPrefPath{ 39 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 40 | if ([paths count]>0) { 41 | return [paths[0] stringByAppendingPathComponent:@"Preferences"]; 42 | } 43 | return nil; 44 | } 45 | + (NSString *)libCachePath{ 46 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 47 | if ([paths count]>0) { 48 | return [paths[0] stringByAppendingPathComponent:@"Caches"]; 49 | } 50 | return nil; 51 | 52 | } 53 | 54 | + (NSString *)tmpPath{ 55 | return [NSHomeDirectory() stringByAppendingFormat:@"/tmp"]; 56 | } 57 | 58 | 59 | + (BOOL)createPathIfNotExist:(NSString *)path;{ 60 | 61 | if (NO==[[NSFileManager defaultManager] fileExistsAtPath:path]) { 62 | NSError *error = nil; 63 | BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]; 64 | if (!success || error) { 65 | return NO; 66 | } 67 | 68 | } 69 | return YES; 70 | } 71 | 72 | + (BOOL)createFileIfNotExist:(NSString *)path{ 73 | if (NO==[[NSFileManager defaultManager] fileExistsAtPath:path]) { 74 | // 如果path中又目录需要创建,先创建目录 75 | // 创建文件默认属性是只读的 76 | return [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil]; 77 | } 78 | return YES; 79 | } 80 | 81 | 82 | + (BOOL)deleteItem:(NSString *)path{ 83 | return [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; 84 | } 85 | 86 | + (BOOL)copyItem:(NSString *)srcPath toPath:(NSString *)destPath{ 87 | [self deleteItem:destPath]; 88 | return [[NSFileManager defaultManager] copyItemAtPath:srcPath toPath:destPath error:nil]; 89 | } 90 | 91 | 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /Olla4iOS/system/bind/NSStringValueTransformer.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSStringValueTransformer.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/10. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSStringValueTransformer : NSValueTransformer 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Olla4iOS/system/bind/NSStringValueTransformer.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSStringValueTransformer.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/10. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "NSStringValueTransformer.h" 10 | #import "foundation.h" 11 | 12 | @implementation NSStringValueTransformer 13 | 14 | //指定转换的类型 15 | +(Class)transformedValueClass{ 16 | return [NSString class]; 17 | } 18 | 19 | //如果是number转为string类型 20 | - (id)transformedValue:(id)value{ 21 | if ([value isNumber]) { 22 | return [(NSNumber *)value stringValue]; 23 | } 24 | return nil; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Olla4iOS/system/bind/OllaDataBind.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataBind.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | typedef NS_ENUM(NSInteger, OllaDataBindMode){ 13 | OllaDataBindModeNoWay=0, 14 | OllaDataBindModeOneWay, 15 | OllaDataBindModeTwoWay 16 | }; 17 | 18 | @interface OllaDataBind : NSObject 19 | 20 | @property(nonatomic,copy) NSString *propertyKeyPath; 21 | @property(nonatomic,copy) NSString *dataKeyPath; 22 | @property(nonatomic,copy) NSString *secondDataKeyPath;//当第一个为空时,选第二个 23 | @property(nonatomic,copy) NSString *value; // 也有直接给值的,如cornerRadius 24 | @property(nonatomic,strong) IBOutletCollection(UIView) NSArray *views; 25 | 26 | @property(nonatomic,copy) NSString *enabledKeyPath; 27 | @property(nonatomic,copy) NSString *disabledKeyPath; 28 | 29 | @property(nonatomic,strong) id targetNilValue;//值为空时的值 30 | @property(nonatomic,copy) NSString *stringFormat;//@“%@元” 31 | @property(nonatomic,strong) NSValueTransformer *convertor; 32 | @property(nonatomic,assign) OllaDataBindMode mode;//KVO 33 | 34 | - (void)applyDataBinding:(id)data; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Olla4iOS/system/bind/OllaDataBind.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataBind.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaDataBind.h" 10 | #import "NSObject+KeyPath.h" 11 | #import "foundation.h" 12 | 13 | @implementation OllaDataBind 14 | 15 | // 这是2个机关,_eanbledKeyPath 是0 断开bind ,——disabledKeyPath是1断开bind 16 | - (void)applyDataBinding:(id)data{ 17 | 18 | if (_enabledKeyPath) { 19 | if (![self booleanValue:[data dataForKeyPath:_enabledKeyPath]]) { 20 | return; 21 | } 22 | } 23 | 24 | if (_disabledKeyPath) { 25 | if ([self booleanValue:[data dataForKeyPath:_disabledKeyPath]]) { 26 | return; 27 | } 28 | } 29 | 30 | id value=_value; 31 | if ([_dataKeyPath length]>0) { 32 | value = [data dataForKeyPath:_dataKeyPath]; 33 | } 34 | if (!value || [value isKindOfClass:[NSNull class]]) { 35 | value = self.targetNilValue; 36 | if (!value && [self.secondDataKeyPath length]) { 37 | value = [data dataForKeyPath:_secondDataKeyPath]; 38 | } 39 | } 40 | 41 | for (UIView *view in _views) { 42 | //如果_urPropertyKeyPath 不满足view上的 key-value coding-compaint,这里会导致崩溃 43 | if ([_propertyKeyPath length]>0) { 44 | 45 | if ([value isKindOfClass:[NSNumber class]] && [_propertyKeyPath isEqualToString:@"text"]) { 46 | value = [value stringValue]; 47 | } 48 | 49 | if (self.convertor) { 50 | value = [self.convertor transformedValue:value]; 51 | } 52 | 53 | if ([value isString] && [value length] && self.stringFormat) { 54 | value= [NSString stringWithFormat:self.stringFormat,value]; 55 | } 56 | 57 | [view setValue:value forKeyPath:_propertyKeyPath]; 58 | } 59 | } 60 | } 61 | 62 | 63 | - (BOOL)booleanValue:(id)key{ 64 | 65 | if ([key isKindOfClass:[NSNumber class]]) { 66 | return [key boolValue]; 67 | }else if([key isKindOfClass:[NSString class]]){ 68 | // "ture" or "false" ,, "yes" or "no" ,, @"0" or @"1" 69 | if ([key isEqualToString:@"0"]||[[key uppercaseString] isEqualToString:@"NO"]||[[key uppercaseString] isEqualToString:@"TURE"]) { 70 | return NO; 71 | } 72 | } 73 | 74 | return YES; 75 | } 76 | 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /Olla4iOS/system/bind/OllaDataBindContainer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataBindContainer.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OllaDataBind.h" 11 | 12 | @interface OllaDataBindContainer : NSObject 13 | 14 | @property(nonatomic,strong) IBOutletCollection(OllaDataBind) NSArray *dataBindings; 15 | 16 | - (void)applyDataBinding:(id)data; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/system/bind/OllaDataBindContainer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaDataBindContainer.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaDataBindContainer.h" 10 | 11 | @implementation OllaDataBindContainer 12 | 13 | - (void)applyDataBinding:(id)data{ 14 | for (OllaDataBind *dataBind in _dataBindings) { 15 | [dataBind applyDataBinding:data]; 16 | } 17 | 18 | } 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Olla4iOS/system/image/OllaImagePickerController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaImagePickerController.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-16. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger , OllaImagePickerType){ 12 | OllaImagePickerCamera, 13 | OllaImagPickerAlbum, 14 | OllaImagePickerPhotoLibrary 15 | }; 16 | 17 | @class OllaImagePickerController; 18 | typedef void(^ImagePickerCompleteBlock)(OllaImagePickerController *controller,UIImage *image); 19 | 20 | //图片相机封装 21 | @interface OllaImagePickerController : NSObject 22 | 23 | @property(nonatomic,assign) OllaImagePickerType imagePickerType; 24 | @property(nonatomic,strong) ImagePickerCompleteBlock completeBlock; 25 | @property(nonatomic,assign) BOOL allowsEditing; 26 | 27 | @property(nonatomic,weak) UIViewController *presentedViewController; 28 | 29 | - (instancetype) initWithViewController:(UIViewController *)viewController; 30 | - (void)picker; 31 | - (void)pickerImage;// 快捷接口 32 | 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Olla4iOS/system/system.h: -------------------------------------------------------------------------------- 1 | // 2 | // system.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #ifndef OllaFramework_system_h 10 | #define OllaFramework_system_h 11 | 12 | 13 | //bind 14 | #import "OllaDataBindContainer.h" 15 | #import "OllaDataBind.h" 16 | 17 | 18 | // uikit 19 | #import "OllaTableSource.h" 20 | #import "OllaTableSection.h" 21 | #import "OllaCollectionViewCell.h" 22 | #import "OllaTableViewCell.h" 23 | 24 | #import "OllaButton.h" 25 | #import "OllaFadeButton.h" 26 | #import "OllaMenuLabel.h" 27 | #import "OllaTableView.h" 28 | #import "OllaResignView.h" 29 | 30 | #import "OllaRefreshView.h" 31 | #import "OllaLoadingMoreView.h" 32 | 33 | #import "OllaBannerCell.h" 34 | #import "OllaBannerView.h" 35 | 36 | #import "UIView+Gesture.h" 37 | #import "UIView+additions.h" 38 | #import "UIView+style.h" 39 | #import "UIActionSheet+Blocks.h" 40 | #import "UITableViewCell+additions.h" 41 | #import "UIApplication+additions.h" 42 | #import "UINavigationItem+MultipleButtonsAddition.h" 43 | #import "UIWebView+addtions.h" 44 | 45 | #import "UITabBarController+hidable.h" 46 | 47 | #import "OllaImagePickerController.h" 48 | #import "OllaImageBrowserView.h" 49 | #import "UIButton+CacheURL.h" 50 | #import "UIImageView+CacheURL.h" 51 | #import "UIImageView+ProgressHUD.h" 52 | #import "UIViewController+HUD.h" 53 | 54 | //forkingdog 自动算高 55 | #import "UITableView+AutoHeight.h" 56 | #import "UITableView+FDTemplateLayoutCell.h" 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/IOllaLoadingProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOllaLoadingProtocol.h 3 | // TestFoundation 4 | // 5 | // Created by null on 15/7/2. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @protocol IOllaLoadingMoreView 13 | 14 | @property(nonatomic,weak) IBOutlet UILabel *textLabel; 15 | @property(nonatomic,weak) IBOutlet UIActivityIndicatorView *indicatorView; 16 | @property(nonatomic,assign) BOOL isLoading; 17 | @property(nonatomic,assign) BOOL hasMoreData; 18 | 19 | - (void)startLoading; 20 | - (void)stopLoading; 21 | 22 | 23 | @end 24 | 25 | 26 | 27 | @protocol IOllaRefreshView 28 | 29 | - (instancetype)initInScrollView:(UIScrollView *)scrollView; 30 | 31 | - (void)beginRefreshing; 32 | - (void)endRefreshing; 33 | 34 | @end 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaButton.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaAction.h" 11 | 12 | @interface OllaButton : UIButton 13 | 14 | @property(nonatomic,assign) CGFloat expandMargin;//default 0; 15 | 16 | - (void)performSelectorBlock:(void (^)())block forControlEvents:(UIControlEvents)controlEvents; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaButton.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-6-27. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaButton.h" 10 | 11 | typedef void (^EventBlock)(); 12 | 13 | @interface OllaButton () 14 | @property(nonatomic,strong) EventBlock eventBlock; 15 | @end 16 | 17 | @implementation OllaButton 18 | 19 | @synthesize actionName = _actionName; 20 | @synthesize userInfo = _userInfo; 21 | 22 | - (id)initWithFrame:(CGRect)frame 23 | { 24 | self = [super initWithFrame:frame]; 25 | if (self) { 26 | // Initialization code 27 | } 28 | return self; 29 | } 30 | 31 | - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{ 32 | 33 | CGRect area = CGRectInset(self.bounds, -self.expandMargin, -self.expandMargin); 34 | return CGRectContainsPoint(area, point); 35 | } 36 | 37 | - (void)performSelectorBlock:(void (^)())block forControlEvents:(UIControlEvents)controlEvents{ 38 | 39 | self.eventBlock = block; 40 | [self addTarget:self action:@selector(action:) forControlEvents:controlEvents]; 41 | 42 | } 43 | 44 | - (void)action:(UIButton *)button{ 45 | 46 | self.eventBlock(); 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionViewCell.h 3 | // Olla 4 | // 5 | // Created by null on 14-10-31. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OllaDataBindContainer.h" 11 | 12 | IB_DESIGNABLE 13 | @interface OllaCollectionViewCell : UICollectionViewCell 14 | 15 | @property(nonatomic,strong) IBOutlet OllaDataBindContainer *dataBindContainer; 16 | @property(nonatomic,strong) id dataItem; 17 | @property(nonatomic,weak) IBOutlet id delegate; 18 | 19 | - (IBAction)doAction:(id)sender; 20 | - (IBAction)doAction:(id)sender event:(UIEvent *)event; 21 | 22 | 23 | @end 24 | 25 | @protocol OllaCollectionViewCellDelegate 26 | @optional 27 | - (void)collectionViewCell:(OllaCollectionViewCell *)cell doAction:(id)sender event:(UIEvent *)event; 28 | @end 29 | 30 | 31 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaCollectionViewCell.m 3 | // Olla 4 | // 5 | // Created by null on 14-10-31. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaCollectionViewCell.h" 10 | 11 | @implementation OllaCollectionViewCell 12 | 13 | 14 | - (void)setDataItem:(id)dataItem{ 15 | 16 | if (_dataItem != dataItem) { 17 | _dataItem = dataItem; 18 | 19 | [_dataBindContainer applyDataBinding:self]; 20 | 21 | // 如果cell上又网络图片控件,还要发起网络请求;也可以这样:为UIImageView新增的src添加一个KVO,这样代码更简洁 22 | 23 | } 24 | } 25 | 26 | - (IBAction)doAction:(id)sender{ 27 | [self doAction:sender event:nil]; 28 | } 29 | 30 | - (IBAction)doAction:(id)sender event:(UIEvent *)event{ 31 | 32 | if([_delegate respondsToSelector:@selector(collectionViewCell:doAction:event:)]){ 33 | [_delegate collectionViewCell:self doAction:sender event:event]; 34 | } 35 | } 36 | 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaFadeButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaFadeButton.h 3 | // Olla 4 | // 5 | // Created by null on 15-1-29. 6 | // Copyright (c) 2015年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | // 用在cell上在滚动时的图片淡入淡出的动画效果效果(优化项) 12 | @interface OllaFadeButton : UIButton 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaFadeButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaFadeButton.m 3 | // Olla 4 | // 5 | // Created by null on 15-1-29. 6 | // Copyright (c) 2015年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaFadeButton.h" 10 | 11 | @interface OllaFadeButtonLayer : CALayer 12 | @end 13 | 14 | @implementation OllaFadeButtonLayer 15 | 16 | - (id)actionForKey:(NSString *)event{ 17 | if ([event isEqualToString:@"contents"] && self.contents==nil) { 18 | CATransition *transition = [CATransition animation]; 19 | transition.duration = 0.25f; 20 | transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 21 | transition.type = kCATransitionFade; 22 | return transition; 23 | } 24 | 25 | return nil; 26 | } 27 | 28 | @end 29 | 30 | 31 | 32 | @implementation OllaFadeButton 33 | 34 | - (CALayer *)layer{ 35 | return [OllaFadeButtonLayer layer]; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaImageBrowserView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaImageBrowserView.h 3 | // OllaFramework 4 | // 5 | // Created by null on 14-9-5. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //单张图片大图浏览 12 | @interface OllaImageBrowserView : UIView 13 | 14 | @property(nonatomic,assign) CGRect startRect; 15 | @property(nonatomic,strong) UIImage *image; 16 | @property(nonatomic,strong) NSString *originalURL; 17 | 18 | @property(nonatomic,strong) NSString *imagePath; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaLoadingMoreView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaLoadingMoreView.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-17. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "IOllaLoadingProtocol.h" 11 | 12 | 13 | //TODO:7 14 | @interface OllaLoadingMoreView : UITableViewCell 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaLoadingMoreView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaLoadingMoreView.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-17. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaLoadingMoreView.h" 10 | #import "UIView+additions.h" 11 | 12 | @implementation OllaLoadingMoreView 13 | 14 | @synthesize textLabel = _textLabel; 15 | @synthesize indicatorView = _indicatorView; 16 | @synthesize isLoading = _isLoading; 17 | @synthesize hasMoreData = _hasMoreData; 18 | 19 | - (instancetype)initWithFrame:(CGRect)frame{ 20 | self = [super initWithFrame:frame]; 21 | if (self) { 22 | self.backgroundColor = [UIColor clearColor]; 23 | self.selectionStyle = UITableViewCellSelectionStyleNone; 24 | 25 | UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 26 | indicatorView.center = self.center; 27 | indicatorView.autoresizingMask = UIViewAutoresizingNone; 28 | self.indicatorView = indicatorView; 29 | [self addSubview:indicatorView]; 30 | 31 | UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 40)]; 32 | textLabel.center = self.center; 33 | indicatorView.autoresizingMask = UIViewAutoresizingNone; 34 | textLabel.textColor = [UIColor lightGrayColor]; 35 | textLabel.font = [UIFont systemFontOfSize:13.f]; 36 | textLabel.backgroundColor = [UIColor clearColor]; 37 | textLabel.textAlignment = NSTextAlignmentCenter; 38 | self.textLabel = textLabel; 39 | [self addSubview:textLabel]; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)startLoading{ 45 | self.isLoading = YES; 46 | [self.indicatorView setHidden:NO]; 47 | [self.indicatorView startAnimating]; 48 | } 49 | 50 | - (void)stopLoading{ 51 | self.isLoading = NO; 52 | [self.indicatorView stopAnimating]; 53 | } 54 | 55 | - (void)setHasMoreData:(BOOL)hasMoreData{ 56 | _hasMoreData = hasMoreData; 57 | if (!_hasMoreData) {// no more data 58 | [self.textLabel setText:NSLocalizedString(@"no more data", @"")]; 59 | self.textLabel.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 60 | [self.textLabel setHidden:NO]; 61 | [self.indicatorView setHidden:YES]; 62 | }else{ 63 | [self.textLabel setHidden:YES]; 64 | [self.indicatorView setHidden:NO]; 65 | self.indicatorView.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 66 | } 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaMenuLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaMenuLabel.h 3 | // OllaMenuLableDemo 4 | // 5 | // Created by nonstriater on 14-7-11. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger,OllaPopupMenuType){ 12 | 13 | OllaPopupMenuCopy = 0, 14 | OllaPopupMenuTranslation, 15 | OllaPopupMenuStoreUp, 16 | OllaPopupMenuTransmit, 17 | OllaPopupMenuMore 18 | 19 | 20 | }; 21 | 22 | 23 | @interface OllaMenuLabel : UILabel 24 | 25 | @property(nonatomic,assign) BOOL enablePopupMenu; 26 | @property(nonatomic,strong) UILongPressGestureRecognizer *longPressGesture; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaMenuLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaMenuLabel.m 3 | // OllaMenuLableDemo 4 | // 5 | // Created by nonstriater on 14-7-11. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaMenuLabel.h" 10 | 11 | NSString *OllaMenuLabelBecomeFirstResponderNotification = @"OllaMenuLabelBecomeFirstResponderNotification"; 12 | 13 | @implementation OllaMenuLabel 14 | 15 | - (id)initWithFrame:(CGRect)frame 16 | { 17 | self = [super initWithFrame:frame]; 18 | if (self) { 19 | // Initialization code 20 | [self commonInitial]; 21 | } 22 | return self; 23 | } 24 | 25 | - (void)awakeFromNib{ 26 | [self commonInitial]; 27 | 28 | } 29 | 30 | - (void)commonInitial{ 31 | 32 | self.enablePopupMenu = YES; 33 | self.userInteractionEnabled = YES; 34 | UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)]; 35 | //longPress.minimumPressDuration = 1.2f; 36 | _longPressGesture = longPress; 37 | [self addGestureRecognizer:longPress]; 38 | } 39 | 40 | - (void)longPressHandler:(UILongPressGestureRecognizer *)gesture{ 41 | 42 | if (gesture == self.longPressGesture ) { 43 | 44 | if (gesture.state == UIGestureRecognizerStateBegan) { 45 | 46 | [self becomeFirstResponder]; 47 | [[NSNotificationCenter defaultCenter] postNotificationName:OllaMenuLabelBecomeFirstResponderNotification object:nil]; 48 | 49 | UIMenuController *menuController = [UIMenuController sharedMenuController]; 50 | 51 | [menuController setTargetRect:self.bounds inView:self]; 52 | [menuController setMenuVisible:YES animated:YES]; 53 | } 54 | } 55 | 56 | } 57 | 58 | - (void)setEnablePopupMenu:(BOOL)enablePopupMenu{ 59 | 60 | if (_enablePopupMenu != enablePopupMenu) { 61 | 62 | [self willChangeValueForKey:@"enablePopupMenu"]; 63 | _enablePopupMenu = enablePopupMenu; 64 | [self didChangeValueForKey:@"enablePopupMenu"]; 65 | 66 | self.userInteractionEnabled = enablePopupMenu; 67 | self.longPressGesture.enabled = enablePopupMenu; 68 | 69 | } 70 | 71 | } 72 | 73 | 74 | 75 | // label default is no 76 | - (BOOL)canBecomeFirstResponder{ 77 | return self.enablePopupMenu; 78 | } 79 | 80 | - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ 81 | 82 | BOOL retValue = NO; 83 | if(action==@selector(copy:)){ 84 | if (self.enablePopupMenu) { 85 | return YES; 86 | } 87 | }else{ 88 | retValue = [super canPerformAction:action withSender:sender]; 89 | } 90 | return retValue; 91 | } 92 | 93 | - (void)copy:(id)sender{ 94 | 95 | if (self.enablePopupMenu) { 96 | 97 | //可以在代理方法中对复制的内容过个处理,如果需要的话 98 | 99 | UIPasteboard *board = [UIPasteboard generalPasteboard]; 100 | board.string = self.text; 101 | 102 | //[LLTextMessageCell _didChangeToFirstResponder:] 避免崩溃 103 | [self resignFirstResponder]; 104 | } 105 | 106 | } 107 | 108 | 109 | 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaRefreshView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaRefreshView.h 3 | // OllaFramework 4 | // https://github.com/Sephiroth87/ODRefreshControl 5 | // Created by nonstriater on 14-7-17. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "IOllaLoadingProtocol.h" 12 | 13 | 14 | //TODO:8 15 | @interface OllaRefreshView : UIControl{ 16 | CAShapeLayer *_shapeLayer; 17 | CAShapeLayer *_arrowLayer; 18 | CAShapeLayer *_highlightLayer; 19 | UIView *_activity; 20 | BOOL _refreshing; 21 | BOOL _canRefresh; 22 | BOOL _ignoreInset; 23 | BOOL _ignoreOffset; 24 | BOOL _didSetInset; 25 | BOOL _hasSectionHeaders; 26 | CGFloat _lastOffset; 27 | 28 | } 29 | 30 | @property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing; 31 | 32 | @property (nonatomic, strong) UIColor *tintColor UI_APPEARANCE_SELECTOR; 33 | @property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle UI_APPEARANCE_SELECTOR; 34 | @property (nonatomic, strong) UIColor *activityIndicatorViewColor UI_APPEARANCE_SELECTOR; // iOS5 or more 35 | 36 | 37 | - (id)initInScrollView:(UIScrollView *)scrollView; 38 | - (id)initInScrollView:(UIScrollView *)scrollView activityIndicatorView:(UIView *)activity; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaResignView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LLResignView.h 3 | // Olla 4 | // 5 | // Created by null on 14-11-4. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | // 通常用来回收键盘 12 | @interface OllaResignView : UIView 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaResignView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LLResignView.m 3 | // Olla 4 | // 5 | // Created by null on 14-11-4. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaResignView.h" 10 | #import "UIView+Gesture.h" 11 | 12 | @implementation OllaResignView 13 | 14 | 15 | - (instancetype)initWithFrame:(CGRect)frame{ 16 | 17 | self = [super initWithFrame:frame]; 18 | if (self) { 19 | [self commonInitial]; 20 | } 21 | return self; 22 | } 23 | 24 | - (void)awakeFromNib{ 25 | [self commonInitial]; 26 | } 27 | 28 | - (void)commonInitial{ 29 | 30 | [self tap:^(UITapGestureRecognizer *tapGesture) { 31 | 32 | [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; 33 | 34 | }]; 35 | 36 | } 37 | 38 | 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableSection.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableSection.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface OllaTableSection : NSObject 13 | 14 | @property(nonatomic,strong) NSString *title; 15 | @property(nonatomic,strong) IBOutlet UIView *headerView; 16 | @property(nonatomic,strong) IBOutlet UIView *footerView; 17 | @property(nonatomic,strong) IBOutletCollection(UITableViewCell) NSArray *cells; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableSection.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableSection.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTableSection.h" 10 | 11 | @implementation OllaTableSection 12 | 13 | 14 | //xib中的顺序不能保证内存中的顺序,这里做一个排序 15 | - (void)setCells:(NSArray *)cells{ 16 | 17 | if (_cells != cells) { 18 | 19 | NSArray *c = [cells sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2){ 20 | NSInteger tag1 = [(UIView *)obj1 tag]; 21 | NSInteger tag2 = [(UIView *)obj2 tag]; 22 | 23 | if (tag1tag2) { 27 | return NSOrderedDescending; 28 | } 29 | 30 | return NSOrderedSame; 31 | }]; 32 | 33 | _cells = c; 34 | 35 | } 36 | 37 | } 38 | 39 | 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableSource.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OllaTableSection.h" 11 | 12 | @interface OllaTableSource : NSObject 13 | 14 | @property(nonatomic,strong) IBOutletCollection(OllaTableSection) NSArray *sections; 15 | @property(nonatomic,strong) IBOutlet UITableView *tableView; 16 | 17 | @end 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableSource.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableSource.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTableSource.h" 10 | 11 | @implementation OllaTableSource 12 | 13 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 14 | return [_sections count]; 15 | } 16 | 17 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 18 | 19 | return [[_sections[section] cells] count]; 20 | 21 | } 22 | 23 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 24 | 25 | NSArray *cells = [_sections[indexPath.section] cells]; 26 | if ([cells count]) { 27 | return [[cells objectAtIndex:indexPath.row] frame].size.height; 28 | } 29 | 30 | return 0; 31 | 32 | } 33 | 34 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 35 | 36 | return [[_sections[indexPath.section] cells] objectAtIndex:indexPath.row]; 37 | } 38 | 39 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 40 | 41 | return [_sections[section] title]; 42 | } 43 | 44 | 45 | // header & footer //////////////////////////////////////////////////////////////////////////// 46 | 47 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 48 | UIView *header = [_sections[section] headerView]; 49 | if (header) { 50 | return header.frame.size.height; 51 | } 52 | return 0; 53 | } 54 | 55 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ 56 | UIView *footer = [_sections[section] footerView]; 57 | if (footer) { 58 | return footer.frame.size.height; 59 | } 60 | return 0; 61 | } 62 | 63 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 64 | return [_sections[section] headerView]; 65 | } 66 | 67 | -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ 68 | return [_sections[section] footerView]; 69 | } 70 | 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableView.h 3 | // Olla 4 | // 5 | // Created by null on 15-1-23. 6 | // Copyright (c) 2015年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OllaTableView : UITableView 12 | 13 | /** 14 | * for backgroundImageView 15 | */ 16 | @property(nonatomic,readwrite) NSString *backgroundImageName; 17 | 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableView.m 3 | // Olla 4 | // 5 | // Created by null on 15-1-23. 6 | // Copyright (c) 2015年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTableView.h" 10 | #import "UIView+additions.h" 11 | 12 | @implementation OllaTableView 13 | 14 | - (void)setBackgroundImageName:(NSString *)backgroundImageName{ 15 | UIImage *image = [UIImage imageNamed:backgroundImageName]; 16 | if (!image) { 17 | return; 18 | } 19 | 20 | UIImageView *iv = [[UIImageView alloc] initWithImage:image]; 21 | self.backgroundView = iv; 22 | } 23 | 24 | - (void)setBlurRadius:(CGFloat)blurRadius{ 25 | 26 | if (!self.backgroundView || ![self.backgroundView isKindOfClass:UIImageView.class]) { 27 | return; 28 | } 29 | 30 | [self.backgroundView blurWithRadius:blurRadius]; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableViewCell.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OllaDataBindContainer.h" 11 | 12 | @interface OllaTableViewCell : UITableViewCell 13 | 14 | @property(nonatomic,strong) IBOutlet OllaDataBindContainer *dataBindContainer; 15 | @property(nonatomic,weak) IBOutlet id delegate; 16 | @property(nonatomic,strong) id dataItem; 17 | 18 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier nibName:(NSString *)nibName; 19 | 20 | - (IBAction)doAction:(id)sender; 21 | - (IBAction)doAction:(id)sender event:(UIEvent *)event; 22 | 23 | - (void)cancelHTTPRequestIfNeeded; 24 | 25 | 26 | @end 27 | 28 | 29 | @protocol OllaTableViewCellDelegate 30 | @optional 31 | - (void)tableViewCell:(OllaTableViewCell *)cell doAction:(id)sender event:(UIEvent *)event; 32 | @end 33 | 34 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/OllaTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaTableViewCell.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-2. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "OllaTableViewCell.h" 10 | #import "UIImageView+CacheURL.h" 11 | 12 | @implementation OllaTableViewCell 13 | 14 | // ////////////////////////////////////////////////////////////////////////////////////////// 15 | // 使用storyboard 的dynamic cell后,dequeueReusableCellWithIdentifier: 不论如何都会返回非nil,且子类化UITableViewCell的initWithStyle方法也不会调用 16 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 17 | { 18 | return [self initWithStyle:style reuseIdentifier:reuseIdentifier nibName:nil]; 19 | } 20 | 21 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier nibName:(NSString *)nibName{ 22 | 23 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 24 | if (self) { 25 | self.backgroundColor = [UIColor clearColor]; 26 | if (![nibName length]) { 27 | return self; 28 | } 29 | NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:@{}]; 30 | for (id object in nibObjects) { 31 | if ([object isKindOfClass:[self class]]){ 32 | //[self.contentView addSubview:object]; 33 | self = object; 34 | break; 35 | 36 | } 37 | } 38 | 39 | } 40 | return self; 41 | } 42 | 43 | - (void)setDataItem:(id)dataItem{ 44 | 45 | if (_dataItem != dataItem) { 46 | _dataItem = dataItem; 47 | 48 | [_dataBindContainer applyDataBinding:self]; 49 | 50 | // 如果cell上又网络图片控件,还要发起网络请求;也可以这样:为UIImageView新增的src添加一个KVO,这样代码更简洁 51 | } 52 | } 53 | 54 | 55 | - (IBAction)doAction:(id)sender{ 56 | 57 | [self doAction:sender event:nil]; 58 | } 59 | 60 | 61 | - (IBAction)doAction:(id)sender event:(UIEvent *)event{ 62 | 63 | if ([_delegate respondsToSelector:@selector(tableViewCell:doAction: event:)]) { 64 | [_delegate tableViewCell:self doAction:sender event:event]; 65 | } 66 | } 67 | 68 | - (void)cancelHTTPRequestIfNeeded{ 69 | for (UIView *subView in [self.contentView subviews]) { 70 | if ([subView isKindOfClass:[UIImageView class]]) { 71 | [(UIImageView *)subView cancelCurrentImageLoading]; 72 | } 73 | } 74 | 75 | } 76 | 77 | 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIActionSheet+Blocks.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIActionSheet+Blocks.h 3 | // UIActionSheetBlocks 4 | // 5 | // Created by Ryan Maxwell on 31/08/13. 6 | // Copyright (c) 2013 Ryan Maxwell. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^UIActionSheetBlock) (UIActionSheet *actionSheet); 12 | typedef void (^UIActionSheetCompletionBlock) (UIActionSheet *actionSheet, NSInteger buttonIndex); 13 | 14 | @interface UIActionSheet (Blocks) 15 | 16 | + (void)showFromTabBar:(UITabBar *)tabBar 17 | withTitle:(NSString *)title 18 | cancelButtonTitle:(NSString *)cancelButtonTitle 19 | destructiveButtonTitle:(NSString *)destructiveButtonTitle 20 | otherButtonTitles:(NSArray *)otherButtonTitles 21 | tapBlock:(UIActionSheetCompletionBlock)tapBlock; 22 | 23 | + (void)showFromToolbar:(UIToolbar *)toolbar 24 | withTitle:(NSString *)title 25 | cancelButtonTitle:(NSString *)cancelButtonTitle 26 | destructiveButtonTitle:(NSString *)destructiveButtonTitle 27 | otherButtonTitles:(NSArray *)otherButtonTitles 28 | tapBlock:(UIActionSheetCompletionBlock)tapBlock; 29 | 30 | + (void)showInView:(UIView *)view 31 | withTitle:(NSString *)title 32 | cancelButtonTitle:(NSString *)cancelButtonTitle 33 | destructiveButtonTitle:(NSString *)destructiveButtonTitle 34 | otherButtonTitles:(NSArray *)otherButtonTitles 35 | tapBlock:(UIActionSheetCompletionBlock)tapBlock; 36 | 37 | + (void)showFromBarButtonItem:(UIBarButtonItem *)barButtonItem 38 | animated:(BOOL)animated 39 | withTitle:(NSString *)title 40 | cancelButtonTitle:(NSString *)cancelButtonTitle 41 | destructiveButtonTitle:(NSString *)destructiveButtonTitle 42 | otherButtonTitles:(NSArray *)otherButtonTitles 43 | tapBlock:(UIActionSheetCompletionBlock)tapBlock; 44 | 45 | + (void)showFromRect:(CGRect)rect 46 | inView:(UIView *)view 47 | animated:(BOOL)animated 48 | withTitle:(NSString *)title 49 | cancelButtonTitle:(NSString *)cancelButtonTitle 50 | destructiveButtonTitle:(NSString *)destructiveButtonTitle 51 | otherButtonTitles:(NSArray *)otherButtonTitles 52 | tapBlock:(UIActionSheetCompletionBlock)tapBlock; 53 | 54 | 55 | @property (copy, nonatomic) UIActionSheetCompletionBlock tapBlock; 56 | @property (copy, nonatomic) UIActionSheetCompletionBlock willDismissBlock; 57 | @property (copy, nonatomic) UIActionSheetCompletionBlock didDismissBlock; 58 | 59 | @property (copy, nonatomic) UIActionSheetBlock willPresentBlock; 60 | @property (copy, nonatomic) UIActionSheetBlock didPresentBlock; 61 | @property (copy, nonatomic) UIActionSheetBlock cancelBlock; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIActionSheet+iOS8.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIActionSheet+Blocks.h 3 | // CBoBo 4 | // 5 | // Created by null on 15/9/10. 6 | // Copyright (c) 2015年 bobo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "UIActionSheet+Blocks.h" 11 | 12 | @interface UIActionSheet (iOS8) 13 | 14 | + (void)showWithTitle:(NSString *)title 15 | cancelButtonTitle:(NSString *)cancelButtonTitle 16 | otherButtonTitles:(NSArray *)otherButtonTitles 17 | tapBlock:(UIActionSheetCompletionBlock)tapBlock; 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIActionSheet+iOS8.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIActionSheet+Blocks.m 3 | // CBoBo 4 | // 5 | // Created by null on 15/9/10. 6 | // Copyright (c) 2015年 bobo. All rights reserved. 7 | // 8 | 9 | #import "UIActionSheet+iOS8.h" 10 | 11 | @implementation UIActionSheet (iOS8) 12 | 13 | + (void)showWithTitle:(NSString *)title 14 | cancelButtonTitle:(NSString *)cancelButtonTitle 15 | otherButtonTitles:(NSArray *)otherButtonTitles 16 | tapBlock:(UIActionSheetCompletionBlock)tapBlock{ 17 | 18 | UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 19 | 20 | [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 21 | [actionSheet dismissViewControllerAnimated:YES completion:^{ 22 | }]; 23 | }]]; 24 | 25 | for(NSUInteger index=0;index 10 | 11 | @interface UIApplication (additions) 12 | 13 | - (void)dismissKeyboard; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIApplication+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIApplication+additions.m 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-18. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import "UIApplication+additions.h" 10 | 11 | @implementation UIApplication (additions) 12 | 13 | - (void)dismissKeyboard{ 14 | 15 | [[UIApplication sharedApplication] sendAction:nil to:nil from:nil forEvent:nil]; 16 | 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIButton+CacheURL.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+URL.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | #import 9 | 10 | @interface UIButton (CacheURL) 11 | 12 | @property(nonatomic,strong) IBInspectable NSString *remoteImageURL; 13 | @property(nonatomic,strong) IBInspectable NSString *remoteBackgroundImageURL; 14 | 15 | @property(nonatomic,strong) IBInspectable NSString *placeholder; 16 | @property(nonatomic,assign) IBInspectable BOOL placeholderDisable; 17 | @property(nonatomic,strong) IBInspectable UIColor *selectedBackgroundColor; 18 | 19 | @property(nonatomic,strong) UIImage *image; 20 | @property(nonatomic,copy) NSString *title; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIButton+CacheURL.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+URL.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-19. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | 10 | #import "Olla4iOS.h" 11 | 12 | static NSString *defaultPlaceholderImage = @"headphoto_default_128"; 13 | const static void *placeholderKey = &placeholderKey; 14 | const static void *placeholderDisableKey = &placeholderDisableKey; 15 | 16 | @implementation UIButton (CacheURL) 17 | 18 | @dynamic remoteImageURL; 19 | @dynamic remoteBackgroundImageURL; 20 | @dynamic image; 21 | @dynamic placeholderDisable; 22 | @dynamic selectedBackgroundColor; 23 | 24 | - (void)setSelectedBackgroundColor:(UIColor *)selectedBackgroundColor{ 25 | [self setBackgroundImage:[UIImage imageWithColor:selectedBackgroundColor] forState:UIControlStateHighlighted]; 26 | } 27 | 28 | 29 | - (NSString *)placeholder{ 30 | NSString *ph = objc_getAssociatedObject(self, placeholderKey); 31 | return ph; 32 | } 33 | 34 | - (void)setPlaceholder:(NSString *)placeholder{ 35 | objc_setAssociatedObject(self, placeholderKey, placeholder, OBJC_ASSOCIATION_COPY); 36 | } 37 | 38 | - (void)setTitle:(NSString *)title{ 39 | [self setTitle:title forState:UIControlStateNormal]; 40 | } 41 | 42 | - (NSString *)title{ 43 | return [self titleForState:UIControlStateNormal]; 44 | } 45 | 46 | - (void)setImage:(UIImage *)image{ 47 | [self setImage:image forState:UIControlStateNormal]; 48 | } 49 | 50 | - (UIImage *)image{ 51 | return [self imageForState:UIControlStateNormal]; 52 | } 53 | 54 | - (BOOL)placeholderDisable{ 55 | return [objc_getAssociatedObject(self, placeholderDisableKey) boolValue]; 56 | } 57 | 58 | - (void)setPlaceholderDisable:(BOOL)placeholderDisable{ 59 | objc_setAssociatedObject(self, placeholderDisableKey, @(placeholderDisable), OBJC_ASSOCIATION_ASSIGN); 60 | } 61 | 62 | -(void)setRemoteImageURL:(NSString *)remoteImageURL{ 63 | 64 | if ([self.placeholder length]==0) { 65 | self.placeholder = defaultPlaceholderImage; 66 | } 67 | 68 | if (self.placeholderDisable) { 69 | self.placeholder = nil; 70 | } 71 | 72 | if(![remoteImageURL isString]){ 73 | DDLogError(@"非法的url:%@",remoteImageURL); 74 | [self setImage:[UIImage imageNamed:self.placeholder] forState:UIControlStateNormal]; 75 | return; 76 | } 77 | 78 | __weak UIButton *wself = self; 79 | [self sd_setImageWithURL:[NSURL URLWithString:remoteImageURL] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:self.placeholder] options:SDWebImageAllowInvalidSSLCertificates|SDWebImageRetryFailed completed:^(UIImage *image,NSError *error,SDImageCacheType cacheType,NSURL *imageURL){ 80 | 81 | dispatch_main_sync_safe(^{ 82 | __strong UIButton *sself = wself; 83 | if (!sself) return; 84 | if (error) { 85 | DDLogError(@"图片(url=%@)下载失败:%@",remoteImageURL,error); 86 | [sself setImage:[UIImage imageNamed:@"PhotoDownloadfailed"] forState:UIControlStateNormal]; 87 | } 88 | }); 89 | 90 | }]; 91 | } 92 | 93 | -(void)setRemoteBackgroundImageURL:(NSString *)remoteBackgroundImageURL{ 94 | if (![remoteBackgroundImageURL isKindOfClass:[NSString class]]) { 95 | return; 96 | } 97 | [self sd_setBackgroundImageWithURL:[NSURL URLWithString:remoteBackgroundImageURL] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageAllowInvalidSSLCertificates]; 98 | } 99 | 100 | 101 | 102 | @end 103 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIImageView+CacheURL.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+CacheURL.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImageView (CacheURL) 12 | 13 | @property(nonatomic,strong) IBInspectable NSString *remoteImageURL;// 网络url 14 | @property(nonatomic,strong) IBInspectable NSString *placeholder; 15 | @property(nonatomic,strong) NSString *errorImageName; 16 | @property(nonatomic,assign) BOOL placeholderDisable;//default NO 17 | 18 | /** 19 | * 1. 取缓存,没有去网络取 20 | * 2. 取缓存,缓存失败,去网络取 21 | * 3. 没有缓存,直接去网络取 22 | * 4. 缓存图片可能还有加密存储的需求 23 | */ 24 | 25 | // 使用SDWebImage的图片处理 26 | - (void)cancelCurrentImageLoading; 27 | @end 28 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIImageView+CacheURL.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+CacheURL.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-7-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIImageView+CacheURL.h" 10 | #import "Olla4iOS.h" 11 | 12 | static NSString *defaultPlaceholderImage = @"headphoto_default_128"; 13 | const static void *placeholderKey = &placeholderKey; 14 | const static void *errorImageKey = &errorImageKey; 15 | const static void *placeholderDisableKey = &placeholderDisableKey; 16 | 17 | @implementation UIImageView (CacheURL) 18 | 19 | @dynamic remoteImageURL; 20 | 21 | 22 | - (NSString *)placeholder{ 23 | NSString *ph = objc_getAssociatedObject(self, placeholderKey); 24 | return ph; 25 | } 26 | 27 | - (void)setPlaceholder:(NSString *)placeholder{ 28 | objc_setAssociatedObject(self, placeholderKey, placeholder, OBJC_ASSOCIATION_COPY); 29 | } 30 | 31 | 32 | - (BOOL)placeholderDisable{ 33 | return [objc_getAssociatedObject(self, placeholderDisableKey) boolValue]; 34 | } 35 | 36 | - (void)setPlaceholderDisable:(BOOL)placeholderDisable{ 37 | objc_setAssociatedObject(self, placeholderDisableKey, @(placeholderDisable), OBJC_ASSOCIATION_ASSIGN); 38 | } 39 | 40 | 41 | - (NSString *)errorImageName{ 42 | return objc_getAssociatedObject(self, errorImageKey); 43 | } 44 | 45 | - (void)setErrorImageName:(NSString *)errorImageName{ 46 | objc_setAssociatedObject(self,errorImageKey , errorImageName, OBJC_ASSOCIATION_COPY); 47 | } 48 | 49 | // 网络url 50 | - (void)setRemoteImageURL:(NSString *)remoteImageURL{ 51 | 52 | if ([self.placeholder length]==0) { 53 | self.placeholder = defaultPlaceholderImage; 54 | } 55 | 56 | if (self.placeholderDisable) { 57 | self.placeholder = nil; 58 | } 59 | 60 | if(![remoteImageURL isString] || [remoteImageURL length]==0){ 61 | DDLogError(@"非法的url:%@",remoteImageURL); 62 | self.image = [UIImage imageNamed:self.placeholder]; 63 | return; 64 | } 65 | 66 | __weak UIImageView *wself = self; 67 | [self sd_setImageWithURL:[NSURL URLWithString:remoteImageURL] placeholderImage:[UIImage imageNamed:self.placeholder] options:SDWebImageAllowInvalidSSLCertificates|SDWebImageRetryFailed completed:^(UIImage *image,NSError *error,SDImageCacheType cacheType,NSURL *imageURL){ 68 | 69 | dispatch_main_sync_safe(^{ 70 | __strong UIImageView *sself = wself; 71 | if (!sself) return; 72 | if (error) { 73 | DDLogError(@"图片(url=%@)下载失败:%@",remoteImageURL,error); 74 | if ([sself.errorImageName length]==0) { 75 | sself.errorImageName = @"PhotoDownloadfailed"; 76 | } 77 | [sself setImage:[UIImage imageNamed:sself.errorImageName]]; 78 | } 79 | }); 80 | 81 | }]; 82 | 83 | } 84 | 85 | - (void)cancelCurrentImageLoading{ 86 | [self sd_cancelCurrentImageLoad]; 87 | } 88 | 89 | 90 | @end 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIImageView+ProgressHUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+ProgressHUD.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-5-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImageView (ProgressHUD) 12 | 13 | - (void)showHUDWithProgress:(CGFloat)progress; 14 | - (void)removeHUD; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIImageView+ProgressHUD.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+ProgressHUD.m 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-5-3. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIImageView+ProgressHUD.h" 10 | #import "Olla4iOS.h" 11 | 12 | static const void *ImageViewShowHUDProgressView = &ImageViewShowHUDProgressView; 13 | 14 | @implementation UIImageView (ProgressHUD) 15 | 16 | - (void)showHUDWithProgress:(CGFloat)progress{ 17 | 18 | MBRoundProgressView *progressView = objc_getAssociatedObject(self, ImageViewShowHUDProgressView); 19 | if (!progressView) { 20 | 21 | progressView = [[MBRoundProgressView alloc] initWithFrame:CGRectMake(0, 0, 80.f, 80.f)]; 22 | progressView.center = self.center; 23 | progressView.progress = 0.f; 24 | progressView.progressTintColor = [UIColor whiteColor]; 25 | progressView.backgroundTintColor = [UIColor darkGrayColor]; 26 | progressView.annular = YES; 27 | [self addSubview:progressView]; 28 | objc_setAssociatedObject(self, ImageViewShowHUDProgressView, progressView, OBJC_ASSOCIATION_RETAIN); 29 | 30 | } 31 | 32 | progressView.progress = progress; 33 | 34 | 35 | } 36 | 37 | 38 | - (void)removeHUD{ 39 | 40 | MBRoundProgressView *progressView = objc_getAssociatedObject(self, ImageViewShowHUDProgressView); 41 | [progressView removeFromSuperview]; 42 | objc_setAssociatedObject(self, ImageViewShowHUDProgressView, nil, OBJC_ASSOCIATION_ASSIGN); 43 | 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UINavigationItem+MultipleButtonsAddition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationItem+MultipleButtonsAddition.h 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-8. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UINavigationItem (MultipleButtonsAddition) 12 | 13 | @property (nonatomic, strong) IBOutletCollection(UIBarButtonItem) NSArray* rightBarButtonItemsCollection; 14 | @property (nonatomic, strong) IBOutletCollection(UIBarButtonItem) NSArray* leftBarButtonItemsCollection; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UINavigationItem+MultipleButtonsAddition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationItem+MultipleButtonsAddition.m 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-8. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import "UINavigationItem+MultipleButtonsAddition.h" 10 | 11 | @implementation UINavigationItem (MultipleButtonsAddition) 12 | 13 | - (void) setRightBarButtonItemsCollection:(NSArray *)rightBarButtonItemsCollection { 14 | self.rightBarButtonItems = [rightBarButtonItemsCollection sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"tag" ascending:YES]]]; 15 | } 16 | 17 | - (void) setLeftBarButtonItemsCollection:(NSArray *)leftBarButtonItemsCollection { 18 | self.leftBarButtonItems = [leftBarButtonItemsCollection sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"tag" ascending:YES]]]; 19 | } 20 | 21 | - (NSArray*) rightBarButtonItemsCollection { 22 | return self.rightBarButtonItems; 23 | } 24 | 25 | - (NSArray*) leftBarButtonItemsCollection { 26 | return self.leftBarButtonItems; 27 | } 28 | 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UITabBarController+hidable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Tony Million. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #import 28 | 29 | @interface UITabBarController (hidable) 30 | 31 | - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UITableView+AutoHeight.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+AutoHeight.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/29. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableView (AutoHeight) 12 | 13 | // "NO" by default 14 | @property(nonatomic,assign) IBInspectable BOOL autoHeight; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UITableView+AutoHeight.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+AutoHeight.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/29. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "UITableView+AutoHeight.h" 10 | #import "objc/runtime.h" 11 | 12 | @implementation UITableView (AutoHeight) 13 | 14 | - (void)setAutoHeight:(BOOL)autoHeight{ 15 | objc_setAssociatedObject(self, _cmd, @(autoHeight), OBJC_ASSOCIATION_ASSIGN); 16 | } 17 | 18 | -(BOOL)autoHeight{ 19 | return [objc_getAssociatedObject(self, _cmd) boolValue]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UITableViewCell+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableViewCell+additions.h 3 | // Olla 4 | // 5 | // Created by null on 14-11-5. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableViewCell (additions) 12 | 13 | @property(nonatomic,strong) IBInspectable UIColor *selectedBackgroundColor; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UITableViewCell+additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableViewCell+additions.m 3 | // Olla 4 | // 5 | // Created by null on 14-11-5. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UITableViewCell+additions.h" 10 | 11 | @implementation UITableViewCell (additions) 12 | 13 | @dynamic selectedBackgroundColor; 14 | 15 | - (void)setSelectedBackgroundColor:(UIColor *)selectedBackgroundColor{ 16 | 17 | //bacgview is default nil for tableViewPlain ,not nil for group tableview 18 | UIView *backgroundView = [[UIView alloc] initWithFrame:self.bounds]; 19 | backgroundView.backgroundColor = selectedBackgroundColor; 20 | self.selectedBackgroundView = backgroundView; 21 | 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIView+Gesture.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Gesture.h 3 | // Olla 4 | // 5 | // Created by null on 14-10-23. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^TapGestureBlock)(UITapGestureRecognizer *tapGesture) ; 12 | typedef void (^LongPressGestureBlock)(UILongPressGestureRecognizer *longPressGesture); 13 | typedef void (^SwipeGestureBlock)(UISwipeGestureRecognizer *swipeGesture); 14 | 15 | @interface UIView (Gesture) 16 | 17 | @property(nonatomic,strong) TapGestureBlock tapBlock; 18 | @property(nonatomic,strong) LongPressGestureBlock longPressBlock; 19 | @property(nonatomic,strong) SwipeGestureBlock swipeBlock; 20 | 21 | - (void)tap:(TapGestureBlock)tapBlock; 22 | - (void)longPress:(LongPressGestureBlock)longPressBlock; 23 | - (void)swipe:(SwipeGestureBlock)swipeGesture; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIView+Gesture.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Gesture.m 3 | // Olla 4 | // 5 | // Created by null on 14-10-23. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIView+Gesture.h" 10 | #import "Olla4iOS.h" 11 | 12 | static const void *UIViewGestureTapBlockKey = &UIViewGestureTapBlockKey; 13 | static const void *UIViewGestureLongPressBlockKey = &UIViewGestureLongPressBlockKey; 14 | static const void *UIViewGestureSwipeBlockKey = &UIViewGestureSwipeBlockKey; 15 | 16 | 17 | @implementation UIView (Gesture) 18 | 19 | // get & set 20 | 21 | -(TapGestureBlock)tapBlock{ 22 | return objc_getAssociatedObject(self, UIViewGestureTapBlockKey); 23 | } 24 | 25 | - (void)setTapBlock:(TapGestureBlock)tapBlock{ 26 | 27 | objc_setAssociatedObject(self, UIViewGestureTapBlockKey, tapBlock, OBJC_ASSOCIATION_RETAIN); 28 | } 29 | 30 | 31 | - (LongPressGestureBlock)longPressBlock{ 32 | return objc_getAssociatedObject(self, UIViewGestureLongPressBlockKey); 33 | } 34 | 35 | -(void)setLongPressBlock:(LongPressGestureBlock)longPressBlock{ 36 | objc_setAssociatedObject(self, UIViewGestureLongPressBlockKey, longPressBlock, OBJC_ASSOCIATION_RETAIN); 37 | } 38 | 39 | - (SwipeGestureBlock)swipeBlock{ 40 | return objc_getAssociatedObject(self, UIViewGestureSwipeBlockKey); 41 | } 42 | 43 | - (void)setSwipeBlock:(SwipeGestureBlock)swipeGesture{ 44 | objc_setAssociatedObject(self, UIViewGestureSwipeBlockKey, swipeGesture, OBJC_ASSOCIATION_RETAIN); 45 | } 46 | 47 | 48 | - (void)tap:(TapGestureBlock)tapBlock{ 49 | 50 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturehandler:)]; 51 | [self addGestureRecognizer:tap]; 52 | 53 | self.tapBlock = tapBlock; 54 | } 55 | 56 | - (void)tapGesturehandler:(UITapGestureRecognizer *)tap{ 57 | 58 | self.tapBlock(tap); 59 | } 60 | 61 | 62 | - (void)longPress:(LongPressGestureBlock)longPressBlock{ 63 | 64 | UILongPressGestureRecognizer *lpg = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)]; 65 | [self addGestureRecognizer:lpg]; 66 | 67 | self.longPressBlock = longPressBlock; 68 | } 69 | 70 | // be careful to call twice 71 | - (void)longPressHandler:(UILongPressGestureRecognizer *)longPressGesture{ 72 | 73 | if (longPressGesture.state == UIGestureRecognizerStateEnded) { 74 | self.longPressBlock(longPressGesture); 75 | } 76 | } 77 | 78 | 79 | - (void)swipe:(SwipeGestureBlock)swipeGesture{ 80 | UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGestureHandler:)]; 81 | [self addGestureRecognizer:swipe]; 82 | 83 | self.swipeBlock = swipeGesture; 84 | } 85 | 86 | - (void)swipeGestureHandler:(UISwipeGestureRecognizer *)swipe{ 87 | 88 | self.swipeBlock(swipe); 89 | } 90 | 91 | 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIView+additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+additions.h 3 | // FuShuo 4 | // 5 | // Created by nonstriater on 14-1-26. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (additions) 12 | 13 | @property (nonatomic,assign) CGFloat originX; 14 | @property (nonatomic,assign) CGFloat originY; 15 | @property (nonatomic,assign) CGFloat width; 16 | @property (nonatomic,assign) CGFloat height; 17 | 18 | 19 | - (UIImage *)convertToImage; 20 | 21 | /** 22 | * 取UIView上的一块区域作为image 23 | * 24 | * @param rect rect 25 | * 26 | * @return 27 | */ 28 | - (UIImage *)imageWithRect:(CGRect)rect; 29 | 30 | - (void)blurWithRadius:(CGFloat)radius; 31 | 32 | /** 33 | * 设置view.layer 的mask 属性 34 | * 这里的image需要是已经resing过的 35 | * @param image 36 | */ 37 | - (void)maskWithResizableImage:(UIImage *)image; 38 | - (void)maskWithResizableImage:(UIImage *)image padding:(UIEdgeInsets)padding; 39 | /** 40 | * 设置view.layer 的mask 属性 41 | * 这里的image需要是没有resing过的 42 | * 43 | * @param image orinal image 44 | * @param capInset 45 | * @param padding 46 | */ 47 | - (void)maskWithImage:(UIImage *)image resizableImage:(UIEdgeInsets)capInset padding:(UIEdgeInsets)padding; 48 | 49 | 50 | /** 51 | * 分层遍历树结构,看view树上是否存在view 52 | * 53 | * @param view 要查找的view 54 | * 55 | * @return 存在则返回YES 56 | */ 57 | - (BOOL)hasChild:(UIView *)view; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIView+style.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+style.h 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-13. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (style) 12 | 13 | @property(nonatomic,strong) IBInspectable NSString *bgColor; 14 | @property(nonatomic,assign) IBInspectable CGFloat borderWidth; 15 | @property(nonatomic,strong) IBInspectable UIColor *borderColor; 16 | 17 | @property(nonatomic,assign) IBInspectable CGFloat cornerRadius; 18 | @property(nonatomic,assign) IBInspectable CGFloat blurRadius; 19 | 20 | //设置某几个角的圆角 21 | - (void)roundingCorners:(UIRectCorner)corners cornerRadius:(CGFloat)cornerRadius; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIView+style.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+style.m 3 | // OllaFramework 4 | // 5 | // Created by nonstriater on 14-8-13. 6 | // Copyright (c) 2014年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIView+style.h" 10 | #import "Olla4iOS.h" 11 | 12 | @implementation UIView (style) 13 | 14 | @dynamic bgColor; 15 | @dynamic borderWidth; 16 | @dynamic borderColor; 17 | @dynamic blurRadius; 18 | 19 | - (void)setBgColor:(NSString *)bgColor{// #333322 20 | 21 | if ([bgColor isEqualToString:@"red"]) { 22 | self.backgroundColor = [UIColor redColor]; 23 | } 24 | } 25 | 26 | - (void)setBorderWidth:(CGFloat)borderWidth{ 27 | [self.layer setBorderWidth:borderWidth]; 28 | } 29 | 30 | 31 | -(CGFloat)cornerRadius{ 32 | return self.layer.cornerRadius; 33 | } 34 | 35 | - (void)setCornerRadius:(CGFloat)cornerRadius{ 36 | self.layer.cornerRadius = cornerRadius; 37 | self.clipsToBounds = YES; 38 | } 39 | 40 | -(void)setBorderColor:(UIColor *)borderColor{ 41 | self.layer.borderColor = borderColor.CGColor; 42 | } 43 | 44 | - (void)setBlurRadius:(CGFloat)radius{ 45 | [self blurWithRadius:radius]; 46 | } 47 | 48 | 49 | - (void)roundingCorners:(UIRectCorner)corners cornerRadius:(CGFloat)cornerRadius{ 50 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)]; 51 | CAShapeLayer *layer = [[CAShapeLayer alloc] init]; 52 | layer.frame = self.bounds; 53 | layer.path = path.CGPath; 54 | self.layer.mask = layer; 55 | } 56 | 57 | 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIViewController+HUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+HUD.h 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-11. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIViewController (HUD) 12 | 13 | /** 14 | * 显示hud停留n秒 15 | * 16 | * @param text 17 | * @param seconds 18 | */ 19 | - (void)showHUDWithText:(NSString *)text dismissAfter:(NSTimeInterval)seconds; 20 | - (void)showHUDWithText:(NSString *)text dismissAfter:(NSTimeInterval)seconds completeBlock:(void (^)())block; 21 | 22 | //进度,完成后执行block 23 | - (void)showHUDWithProgress:(float)progress text:(NSString *)text finishedBlock:(void (^)())block; 24 | 25 | 26 | - (void)showCustomHUDWithText:(NSString *)text image:(UIImage *)image dismissAfter:(NSTimeInterval)seconds; 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIViewController+HUD.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+HUD.m 3 | // EverPhoto 4 | // 5 | // Created by null on 15-5-11. 6 | // Copyright (c) 2015年 bytedance. All rights reserved. 7 | // 8 | 9 | #import "UIViewController+HUD.h" 10 | #import "Olla4iOS.h" 11 | 12 | @implementation UIViewController (HUD) 13 | 14 | - (void)showHUDWithText:(NSString *)text dismissAfter:(NSTimeInterval)seconds{ 15 | [self showHUDWithText:text dismissAfter:seconds completeBlock:nil]; 16 | } 17 | 18 | 19 | - (void)showHUDWithText:(NSString *)text dismissAfter:(NSTimeInterval)seconds completeBlock:(void (^)())block{ 20 | 21 | MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view]; 22 | [self.view addSubview:hud]; 23 | 24 | hud.labelText = text; 25 | hud.mode = MBProgressHUDModeText; 26 | [hud showAnimated:YES whileExecutingBlock:^{ 27 | sleep(seconds); 28 | } completionBlock:^{ 29 | [hud removeFromSuperview]; 30 | block(); 31 | }]; 32 | 33 | } 34 | 35 | //进度,完成后执行block 36 | - (void)showHUDWithProgress:(float)progress text:(NSString *)text finishedBlock:(void (^)())block{ 37 | 38 | MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view]; 39 | [self.view addSubview:hud]; 40 | hud.labelText = text; 41 | hud.mode = MBProgressHUDModeDeterminate; 42 | 43 | [hud showAnimated:YES whileExecutingBlock:^{ 44 | hud.progress = progress; 45 | }completionBlock:^{ 46 | [hud removeFromSuperview]; 47 | block(); 48 | }]; 49 | } 50 | 51 | - (void)showCustomHUDWithText:(NSString *)text image:(UIImage *)image dismissAfter:(NSTimeInterval)seconds{ 52 | 53 | MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view]; 54 | [self.view addSubview:hud]; 55 | hud.mode = MBProgressHUDModeCustomView; 56 | UIImageView *iv = [[UIImageView alloc] initWithImage:image]; 57 | hud.customView = iv; 58 | 59 | [hud showAnimated:YES whileExecutingBlock:^{ 60 | sleep(seconds); 61 | }completionBlock:^{ 62 | [hud removeFromSuperview]; 63 | }]; 64 | 65 | } 66 | 67 | 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIWebView+addtions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIWebView+addtions.h 3 | // Olla 4 | // 5 | // Created by null on 15-3-20. 6 | // Copyright (c) 2015年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIWebView (addtions) 12 | 13 | /** 14 | * 网页截图 15 | * 16 | * @return 网页图片 17 | */ 18 | - (UIImage *)screenshot; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/additions/UIWebView+addtions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIWebView+addtions.m 3 | // Olla 4 | // 5 | // Created by null on 15-3-20. 6 | // Copyright (c) 2015年 xiaoran. All rights reserved. 7 | // 8 | 9 | #import "UIWebView+addtions.h" 10 | 11 | @implementation UIWebView (addtions) 12 | 13 | // 14 | - (UIImage *)screenshot{ 15 | UIGraphicsBeginImageContextWithOptions(self.scrollView.contentSize, NO, 0); 16 | CGPoint oldContentOffset = self.scrollView.contentOffset; 17 | CGRect oldFrame = self.scrollView.frame; 18 | self.scrollView.contentOffset = CGPointZero; 19 | self.scrollView.frame = CGRectMake(self.scrollView.frame.origin.x, self.scrollView.frame.origin.y, self.scrollView.contentSize.width, self.scrollView.contentSize.height); 20 | [self.scrollView.layer renderInContext:UIGraphicsGetCurrentContext()]; 21 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 22 | self.scrollView.contentOffset = oldContentOffset; 23 | self.scrollView.frame = oldFrame; 24 | UIGraphicsEndImageContext(); 25 | return image; 26 | 27 | } 28 | 29 | 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/common/ScrollBanner/OllaBannerCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaBannerCell.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/23. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OllaBannerModelDelegate.h" 11 | 12 | @interface OllaBannerCell : UICollectionViewCell 13 | 14 | @property(nonatomic,strong) UIImageView *imageView; 15 | @property(nonatomic,strong) id data; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/common/ScrollBanner/OllaBannerCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // OllaBannerCell.m 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/23. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import "OllaBannerCell.h" 10 | #import "Olla4iOS.h"//for ddlogerror() 11 | 12 | @implementation OllaBannerCell 13 | 14 | - (instancetype)initWithFrame:(CGRect)frame{ 15 | if (self=[super initWithFrame:frame]) { 16 | [self layoutUI]; 17 | } 18 | return self; 19 | } 20 | 21 | - (id)initWithCoder:(NSCoder *)aDecoder{ 22 | if (self=[super initWithCoder:aDecoder]) { 23 | [self layoutUI]; 24 | } 25 | return self; 26 | } 27 | 28 | - (void)layoutUI{ 29 | self.clipsToBounds = YES;//imageView被撑大 30 | 31 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds]; 32 | imageView.backgroundColor = RGB_HEX(0xDFDFDF); 33 | imageView.contentMode = UIViewContentModeScaleAspectFill; 34 | [self addSubview:imageView]; 35 | self.imageView = imageView; 36 | } 37 | 38 | - (void)setData:(id)data{ 39 | 40 | if (![data conformsToProtocol:@protocol(OllaBannerModelDelegate)]) { 41 | return; 42 | } 43 | 44 | NSString *imageURL = data.imageURL; 45 | NSString *title = data.title; 46 | 47 | if ([imageURL isKindOfClass:NSString.class]) {//url 48 | if ([imageURL hasPrefix:@"http"]) { 49 | [self.imageView setRemoteImageURL:imageURL]; 50 | } 51 | }else if([imageURL isKindOfClass:NSURL.class]){ 52 | [self.imageView setRemoteImageURL:[(NSURL *)imageURL absoluteString]]; 53 | }else{ 54 | DDLogError(@"OllaBannerCell's data not a correct type:%@",imageURL); 55 | } 56 | 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/common/ScrollBanner/OllaBannerModelDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaBannerModelDelegate.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/11/11. 6 | // Copyright © 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | 10 | @protocol OllaBannerModelDelegate 11 | @property(nonatomic, copy) NSString *imageURL; 12 | @property(nonatomic, copy) NSString *title; 13 | @property(nonatomic, strong) id userInfo; 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Olla4iOS/system/uikit/common/ScrollBanner/OllaBannerView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OllaBannerView.h 3 | // Olla4iOSDemo 4 | // 5 | // Created by null on 15/7/23. 6 | // Copyright (c) 2015年 nonstriater. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @class OllaBannerView; 13 | typedef void (^OllaItemSelectBlock)(OllaBannerView *bannerView,NSUInteger index); 14 | 15 | @interface OllaBannerView : UIView 16 | 17 | //url:nsurl,stringUrl,uiimage 18 | @property (nonatomic,copy) NSArray *items; 19 | 20 | /** 21 | * 是否隐藏pageControl空间 22 | */ 23 | @property (nonatomic,assign) BOOL pageControlHidden; 24 | 25 | /** 26 | * 自动播放,默认NO 27 | */ 28 | @property (nonatomic,assign) BOOL autoPlay; 29 | 30 | - (void)itemSelectedThen:(OllaItemSelectBlock)block; 31 | 32 | @end 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## 安装 4 | 5 | Olla4iOS can be installed using CocoaPods 6 | > pod Olla4iOS 7 | 8 | 9 | ## Contact 10 | 11 | [@移动开发小冉](http://weibo.com/ranwj) 12 | -------------------------------------------------------------------------------- /README.md.copy: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## 安装 4 | 5 | Olla4iOS can be installed using CocaoPods 6 | > pod Olla4iOS 7 | 8 | 9 | ## Olla4iOS 框架使用演示 10 | 11 | ### 一个列表的配置过程 12 | 13 | 以制作微信首页为例: 14 | 15 | 1. cell 布局,数据绑定 16 | 2. nib/sb中,配置controller,datasource 17 | 3. 编写datasource代码 18 | 4. VC中, [self.controller reloadData] 19 | 20 | 21 | 22 | 也许你会说,我们的列表哪有这么简单,表急,下面我们看看,一些典型的开发问题,如何通过Olla4iOS框架来处理。 23 | 24 | ### Static Header Cells 25 | 比如新浪微博首页顶部的广告或者微博“消息”这个列表上最上面3个Cell分别固定是“@我的”,@“评论”,@“赞”,剩下的是chat session 列表。 26 | 27 | 28 | ### 数据model和 UI bind 时还需要转换计算 29 | 也就是,model层的定义不满足UI展现需求时。比如: 30 | 31 | 1. model中的数据类型是NSDate而UI展示需要NSString类型 32 | 2. 微信中置顶的chat sessions Cell有特殊的背景色区分 33 | 34 | 35 | ### 定制自己的refreshView 36 | 37 | 1. 实现自己的CoustomRefreshView, 实现IOllaRefreshView协议方法。 38 | 2. 在tableController里面重写: 39 | ``` 40 | - (class)refreshViewClass{ 41 | return [CoustomRefreshView class]; 42 | } 43 | ``` 44 | 45 | ### Static TableView 46 | 比如微博的“发现”页面 (PS:我专门选择了一个复杂一点的页面) 47 | 48 | 49 | ### 数据变化时UI响应变化 50 | 51 | 比如: 52 | 1. 微信首页上消息变化时 53 | 2. 点赞 54 | 55 | 56 | ## 接下来 57 | 58 | 目前Olla4iOS基本上只干了2件事情: 59 | 60 | 1. 封装了列表的基本逻辑 61 | 2. foundation里面一堆的helper类,也可以独立出来单独使用 62 | 63 | 我还会继续维护和优化Olla4iOS框架。当然,这些改进和优化都会来自我在实际业务开发中的理解。 64 | 65 | 66 | >我理解的做一个app的过程 67 | 68 | - 第一步:软件结构设计,定义各个模块以及他们之间的调用关系 69 | 例如:model,api(cyber),dao,datasource,views,controllers(集合列表用),viewControllers,util 70 | - 第二步:SB/XIB 搭建所有UI和跳转逻辑 71 | - 第三步:各个模块开发,最起码做到api,dao,datasource单元测试 72 | 73 | 目前,Olla4iOS框架还比较简单,我本身对软件结构设计的理解还比较浅陋,没准那天我有了新的理解,会重新组织整个业务框架结构。 74 | 75 | 如果你有任何关于结构设计的想法,欢迎与我联系。 76 | 77 | 78 | ## Contact 79 | 80 | [@移动开发小冉](http://weibo.com/ranwj) 81 | -------------------------------------------------------------------------------- /asset/arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nonstriater/Olla4iOS/4dac12e64caa133afdab9bc8e06bbe29a4a3c3ee/asset/arch.png --------------------------------------------------------------------------------