├── .gitignore ├── README.md ├── TWApp.xcodeproj └── project.pbxproj └── TWApp ├── AppGeneral ├── AppDefine │ ├── AppConfig.h │ ├── MacroDefine.h │ ├── NetworkAPI.h │ └── Singleton.h └── AppEngine │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Model │ ├── TableDataSource.h │ ├── TableDataSource.m │ ├── TableDelegate.h │ ├── TableDelegate.m │ ├── TableModel.h │ ├── TableModel.m │ ├── VCModel.h │ └── VCModel.m │ └── TWUIKit │ ├── TWCell.h │ ├── TWCell.m │ ├── TWLabel.h │ ├── TWLabel.m │ ├── TWTextField.h │ ├── TWTextField.m │ ├── TWViewController.h │ └── TWViewController.m ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── Lib ├── Category │ ├── CategoryUtils.h │ ├── NSData+Addition.h │ ├── NSData+Addition.m │ ├── NSDate+Addition.h │ ├── NSDate+Addition.m │ ├── NSFileManager+ Addition.m │ ├── NSFileManager+Addition.h │ ├── NSString+Addition.h │ ├── NSString+Addition.m │ ├── NSString+MD5Addition.h │ ├── NSString+MD5Addition.m │ ├── NSString+Regular.h │ ├── NSString+Regular.m │ ├── UIAlertView+Addition.h │ ├── UIAlertView+Addition.m │ ├── UIColor+Addition.h │ ├── UIColor+Addition.m │ ├── UIDevice+DeviceInfo.h │ ├── UIDevice+DeviceInfo.m │ ├── UIDevice+IdentifierAddition.h │ ├── UIDevice+IdentifierAddition.m │ ├── UIImage+Addition.h │ ├── UIImage+Addition.m │ ├── UIImageView+LBBlurredImage.h │ ├── UIImageView+LBBlurredImage.m │ ├── UITextField+LimitLength.h │ ├── UITextField+LimitLength.m │ ├── UIView+Addition.h │ ├── UIView+Addition.m │ ├── UIView+Animation.h │ ├── UIView+Animation.m │ ├── UIView+Frame.h │ ├── UIView+Frame.m │ ├── UIView+Layer.h │ └── UIView+Layer.m ├── FMDB │ ├── FMDatabase.h │ ├── FMDatabase.m │ ├── FMDatabaseAdditions.h │ ├── FMDatabaseAdditions.m │ ├── FMDatabasePool.h │ ├── FMDatabasePool.m │ ├── FMDatabaseQueue.h │ ├── FMDatabaseQueue.m │ ├── FMResultSet.h │ └── FMResultSet.m ├── MKNetworkKit │ ├── Categories │ │ ├── NSData+MKBase64.h │ │ ├── NSData+MKBase64.m │ │ ├── NSDate+RFC1123.h │ │ ├── NSDate+RFC1123.m │ │ ├── NSDictionary+RequestEncoding.h │ │ ├── NSDictionary+RequestEncoding.m │ │ ├── NSString+MKNetworkKitAdditions.h │ │ ├── NSString+MKNetworkKitAdditions.m │ │ ├── UIAlertView+MKNetworkKitAdditions.h │ │ ├── UIAlertView+MKNetworkKitAdditions.m │ │ ├── UIImageView+MKNetworkKitAdditions.h │ │ └── UIImageView+MKNetworkKitAdditions.m │ ├── MKNetworkEngine.h │ ├── MKNetworkEngine.m │ ├── MKNetworkKit.h │ ├── MKNetworkOperation.h │ ├── MKNetworkOperation.m │ └── Reachability │ │ ├── Reachability.h │ │ └── Reachability.m └── Views │ ├── AttriButedLabel │ ├── AttributedLabel.h │ └── AttributedLabel.m │ ├── BBCyclingLabel │ ├── BBCyclingLabel.h │ └── BBCyclingLabel.m │ ├── CheckBoxView │ ├── CheckBoxView.h │ ├── CheckBoxView.m │ └── Graphics │ │ ├── cb_box_off.png │ │ ├── cb_box_off@2x.png │ │ ├── cb_box_on.png │ │ ├── cb_box_on@2x.png │ │ ├── cb_dark_off.png │ │ ├── cb_dark_off@2x.png │ │ ├── cb_dark_on.png │ │ ├── cb_dark_on@2x.png │ │ ├── cb_glossy_off.png │ │ ├── cb_glossy_off@2x.png │ │ ├── cb_glossy_on.png │ │ ├── cb_glossy_on@2x.png │ │ ├── cb_green_off.png │ │ ├── cb_green_off@2x.png │ │ ├── cb_green_on.png │ │ ├── cb_green_on@2x.png │ │ ├── cb_mono_off.png │ │ ├── cb_mono_off@2x.png │ │ ├── cb_mono_on.png │ │ └── cb_mono_on@2x.png │ ├── EDStarRating │ ├── EDStarRating.h │ ├── EDStarRating.m │ ├── starRating.png │ └── starRatinghighlighted.png │ ├── GlowLabel │ ├── RRSGlowLabel.h │ └── RRSGlowLabel.m │ ├── LEffectLabel │ ├── LEffectLabel.h │ └── LEffectLabel.m │ ├── MBAlertView │ ├── Categories │ │ ├── NSString+Trim.h │ │ ├── NSString+Trim.m │ │ ├── UIFont+Alert.h │ │ ├── UIFont+Alert.m │ │ ├── UIView+Animations.h │ │ └── UIView+Animations.m │ ├── MBAlertView.h │ ├── MBAlertView.m │ ├── MBHUDView.h │ ├── MBHUDView.m │ ├── Protected │ │ ├── MBAlertViewItem.h │ │ ├── MBAlertViewItem.m │ │ └── MBAlertViewSubclass.h │ └── Views │ │ ├── AlertViewUI.h │ │ ├── MBAlertViewButton.h │ │ ├── MBAlertViewButton.m │ │ ├── MBCheckMarkView.h │ │ ├── MBCheckMarkView.m │ │ ├── MBSpinningCircle.h │ │ └── MBSpinningCircle.m │ ├── MTActivityIndicatorView │ ├── MTActivityIndicatorView.h │ └── MTActivityIndicatorView.m │ ├── MarqueeLabel │ ├── MarqueeLabel.h │ └── MarqueeLabel.m │ ├── MessageStatusBar │ ├── MessageStatusBar.h │ └── MessageStatusBar.m │ ├── PopoverView │ ├── PopoverView.h │ ├── PopoverView.m │ └── PopoverView_Configuration.h │ ├── PullTableView │ ├── PullTableView.h │ ├── PullTableView.m │ ├── RefreshView.h │ ├── RefreshView.m │ ├── arrowDown.png │ └── arrowUp.png │ ├── RadioButton │ ├── RadioButton-Selected.png │ ├── RadioButton-Unselected.png │ ├── RadioButton.h │ └── RadioButton.m │ ├── SEFilterControl │ ├── SEFilterControl.h │ ├── SEFilterControl.m │ ├── SEFilterKnob.h │ └── SEFilterKnob.m │ ├── StatusBarLoading │ ├── StatusBarLoading.h │ └── StatusBarLoading.m │ ├── THLabel │ ├── THLabel.h │ └── THLabel.m │ └── TVCalibratedSlider │ ├── Classes │ ├── TVCalibratedSlider.h │ ├── TVCalibratedSlider.m │ ├── TVSlider.h │ └── TVSlider.m │ └── Resources │ ├── marker.png │ ├── marker@2x.png │ ├── slider_blue.png │ ├── slider_blue@2x.png │ ├── slider_gray.png │ ├── slider_gray@2x.png │ ├── slider_hover.png │ ├── slider_hover@2x.png │ ├── slider_normal.png │ └── slider_normal@2x.png ├── MainStoryboard.storyboard ├── TWApp-Info.plist ├── TWApp-Prefix.pch ├── TWApp └── Test │ ├── TestCell.h │ ├── TestCell.m │ ├── TestVC.h │ └── TestVC.m ├── en.lproj └── InfoPlist.strings └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | iOSApp 2 | ====== 3 | 4 | 一个简易的iOS开发框架,简化iOS开发工作量。 5 | 6 | ##### 说明:SDWebImage不知道为什么,传不上去,自己手动添加一下吧。还有状态栏提示建议去掉,虽然很炫,但不会通过审核的。 7 | 8 | 9 | ### Lib 10 | * 为第三方类库,基本保持不变 11 | * 主要引入一些常用的第三方类库,可直接使用。 12 | * Category:常用的分类工具 13 | * FMDB:著名的OC版SQLite 14 | * MKNetworkKit:网络交互工具 15 | * SDWebImage:异步加载Image工具 16 | * Views:一些常用的第三方自定义的View,包括各种自定义特效的Label,单选按钮,复选框,alertView,状态栏消息通知,筛选控件等等。 17 | 18 | ### AppGeneral 19 | * AppConfig.h : 定义了项目的一些全局参数,如字体、UserDefaults关键字、全局通知等 20 | * MacroDefine.h :定义了通用的宏定义,可保持所有项目不变 21 | * NetworkAPI.h : 定义了网络请求接口,各自项目根据需要自行定义 22 | * Singleton.h : 单例宏定义模板 23 | 24 | ### AppEngine 25 | * 定义了程序里一些通用的模板 26 | 27 | ##### Model 28 | * TableDataSource.h : 定义了TableView的DataSource模板,让控制器专注于数据处理 29 | * TableDelegate.h : 定义了TableView的相关代理,包括上下拉刷新的代理 模板 30 | * VCModel.h : 定义了控制器的Model,主要是相关网络请求接口,让Controller只需要调用的网络接口,传入参数值,即可得到返回数据,另外若有需要,可子类化该类,将数据在该子类中进行解析处理,然后由Controller来读取。 31 | * TableModel.h : 定义了可上下拉刷新的TableView的控制器的Model,为VCModel的子类。 32 | 33 | ##### TWUIKit 34 | * 包含了程序里一些常用的View的子类。如TextField,在程序中通常会有相同的外观设置,如字体,背景等,可在TWTextField中设置好,然后项目中所有的TextField继承自TWTextField,则可实现统一的外观。还有如程序中的VC要设置背景、返回手势,则可在TWViewController中设置好,然后继承该类,则可统一实现相关的定制。等等,其它的类似。 35 | 36 | ### TWApp 37 | * 程序的实际功能模块,如Demo中的Setting、Login等,可在项目中创建对应的实体文件夹,方便管理。 38 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppDefine/AppConfig.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /*--------------------app的相关配置------------------*/ 4 | /*---------------------------------相关值根据需要自行更改------------------------*/ 5 | 6 | 7 | 8 | /*---------------------------------用户相关信息-------------------------------------*/ 9 | 10 | #define kUsername @"usernameNew" 11 | #define kUserNickname @"userNicknameNew" 12 | #define kUserPassword @"userPassword" 13 | #define kUserID @"userID" 14 | #define kUserToken @"userToken" 15 | #define kUserPortraitUrl @"userPortraitUrl" 16 | #define kUserEmail @"userEmail" 17 | #define kUserGender @"userGender" 18 | 19 | 20 | /*---------------------------------程序相关常数-------------------------------------*/ 21 | //App Id、下载地址、评价地址 22 | #define kAppId @"593499239" 23 | #define kAppUrl [NSString stringWithFormat:@"https://itunes.apple.com/us/app/ling-hao-xian/id%@?ls=1&mt=8",kAppId] 24 | #define kRateUrl [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",kAppId] 25 | 26 | #define kPlaceholderImage [UIImage imageNamed:@"placeholderImage.png"] 27 | 28 | 29 | /*---------------------------------程序全局通知-------------------------------------*/ 30 | //重新登录通知 31 | #define kReLoginNotification @"ReLoginNotification" 32 | 33 | 34 | /*---------------------------------程序界面配置信息-------------------------------------*/ 35 | 36 | //设置app界面字体及颜色 37 | #define kTitleFont1 [UIFont boldSystemFontOfSize:20]//一级标题字号 38 | #define kTitleFont2 [UIFont boldSystemFontOfSize:17]//二级标题字号 39 | #define kContentFont [UIFont systemFontOfSize:14.5] //内容部分字号 40 | //内容部分正常显示颜色和突出显示颜色 41 | #define kContentNormalColor [UIColor colorWithRed:57/255.0 green:32/255.0 blue:0/255.0 alpha:1] 42 | #define kContentHighlightColor [UIColor colorWithRed:57/255.0 green:32/255.0 blue:0/255.0 alpha:1] 43 | 44 | //按钮上字体颜色 45 | #define kBtnTitleNormalColor [UIColor colorWithRed:57/255.0 green:32/255.0 blue:0/255.0 alpha:1] 46 | #define kBtnTitleHighlightColor [UIColor colorWithRed:255/255.0 green:96/255.0 blue:0/255.0 alpha:1] 47 | 48 | //设置应用的页面背景色 49 | #define kAppBgColor [UIColor colorWithRed:154/255.0 green:154/255.0 blue:154/255.0 alpha:1] 50 | 51 | 52 | //TableView相关设置 53 | //设置TableView分割线颜色 54 | #define kSeparatorColor [UIColor colorWithRed:154/255.0 green:154/255.0 blue:154/255.0 alpha:1] 55 | //设置TableView背景色 56 | #define kTableViewBgColor [UIColor colorWithRed:154/255.0 green:154/255.0 blue:154/255.0 alpha:1] 57 | //设置TableView选中背景,自行根据需要更改里面函数 58 | UIKIT_STATIC_INLINE UIView *selectedBgView(CGRect rect) 59 | { 60 | UIView *selectedBgView = [[UIView alloc] initWithFrame:rect]; 61 | [selectedBgView setBackgroundColor:[UIColor colorWithRed:60/255. green:180/255. blue:255/255. alpha:0.5]]; 62 | return selectedBgView; 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppDefine/MacroDefine.h: -------------------------------------------------------------------------------- 1 | 2 | #import "AppDelegate.h" 3 | 4 | /*--------------------------------开发中常用到的宏定义--------------------------------------*/ 5 | 6 | //系统目录 7 | #define kDocuments [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] 8 | 9 | 10 | //----------方法简写------- 11 | #define mAppDelegate (AppDelegate *)[[UIApplication sharedApplication] delegate] 12 | #define mWindow [[[UIApplication sharedApplication] windows] lastObject] 13 | #define mKeyWindow [[UIApplication sharedApplication] keyWindow] 14 | #define mUserDefaults [NSUserDefaults standardUserDefaults] 15 | #define mNotificationCenter [NSNotificationCenter defaultCenter] 16 | 17 | //加载图片 18 | #define mImageByName(name) [UIImage imageNamed:name] 19 | #define mImageByPath(name, ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:ext]] 20 | 21 | //以tag读取View 22 | #define mViewByTag(parentView, tag, Class) (Class *)[parentView viewWithTag:tag] 23 | //读取Xib文件的类 24 | #define mViewByNib(Class, owner) [[[NSBundle mainBundle] loadNibNamed:Class owner:owner options:nil] lastObject] 25 | 26 | //id对象与NSData之间转换 27 | #define mObjectToData(object) [NSKeyedArchiver archivedDataWithRootObject:object] 28 | #define mDataToObject(data) [NSKeyedUnarchiver unarchiveObjectWithData:data] 29 | 30 | //度弧度转换 31 | #define mDegreesToRadian(x) (M_PI * (x) / 180.0) 32 | #define mRadianToDegrees(radian) (radian*180.0) / (M_PI) 33 | 34 | //颜色转换 35 | #define mRGBColor(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] 36 | #define mRGBAColor(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] 37 | //rgb颜色转换(16进制->10进制) 38 | #define mRGBToColor(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] 39 | 40 | //G-C-D 41 | #define kGCDBackground(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block) 42 | #define kGCDMain(block) dispatch_async(dispatch_get_main_queue(),block) 43 | 44 | //简单的以AlertView显示提示信息 45 | #define mAlertView(title, msg) \ 46 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil \ 47 | cancelButtonTitle:@"确定" \ 48 | otherButtonTitles:nil]; \ 49 | [alert show]; 50 | 51 | 52 | //----------页面设计相关------- 53 | 54 | #define mNavBarHeight 44 55 | #define mTabBarHeight 49 56 | #define mScreenWidth ([UIScreen mainScreen].bounds.size.width) 57 | #define mScreenHeight ([UIScreen mainScreen].bounds.size.height) 58 | 59 | 60 | //----------设备系统相关--------- 61 | #define mRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO) 62 | #define mIsiP5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136),[[UIScreen mainScreen] currentMode].size) : NO) 63 | #define mIsPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 64 | #define mIsiphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 65 | 66 | #define mSystemVersion ([[UIDevice currentDevice] systemVersion]) 67 | #define mCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) 68 | #define mAPPVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] 69 | #define mFirstLaunch mAPPVersion //以系统版本来判断是否是第一次启动,包括升级后启动。 70 | #define mFirstRun @"firstRun" //判断是否为第一次运行,升级后启动不算是第一次运行 71 | 72 | //--------调试相关------- 73 | 74 | //ARC 75 | #if __has_feature(objc_arc) 76 | //compiling with ARC 77 | #else 78 | #define mSafeRelease(object) [object release]; x=nil 79 | #endif 80 | 81 | //调试模式下输入NSLog,发布后不再输入。 82 | #ifndef __OPTIMIZE__ 83 | #define NSLog(...) NSLog(__VA_ARGS__) 84 | #else 85 | #define NSLog(...) {} 86 | #endif 87 | 88 | #if mTargetOSiPhone 89 | //iPhone Device 90 | #endif 91 | 92 | #if mTargetOSiPhoneSimulator 93 | //iPhone Simulator 94 | #endif 95 | 96 | //获取appDelegate实例。 97 | UIKIT_STATIC_INLINE AppDelegate *appDelegate() 98 | { 99 | return (AppDelegate *)[[UIApplication sharedApplication] delegate]; 100 | } 101 | 102 | 103 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppDefine/NetworkAPI.h: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkAPI.h 3 | // Line0New 4 | // 5 | // Created by line0 on 13-4-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | //网络状态返回码,按需定义 10 | typedef enum 11 | { 12 | TWSucceed = 100, //请求成功 13 | TWFailed = 101, //请求失败 14 | TWNeedLogin = 103, //需要重新登录 15 | 16 | }TWStatusCode; 17 | 18 | //操作系统平台 19 | typedef enum 20 | { 21 | TWWeb = 0, 22 | TWAndroid = 1, 23 | TWiOS = 3, 24 | TWWindowsPhone = 4 25 | } TWOSPlatform; 26 | 27 | //成功失败Blocks 28 | typedef void (^TWFinishedBlock) (NSDictionary *data); 29 | typedef void (^TWFailedBlock) (NSString *error); 30 | 31 | //加载更多和更新数据 32 | typedef void (^TWLoadMoreDataBlock) (void); 33 | typedef void (^TWUpdateDataBlock) (void); 34 | 35 | 36 | #define kImagePrex @"http://mybb.leepood.com/" 37 | 38 | #define kMainWebsite @"mybb.leepood.com/index.php/api"//线上地址 39 | 40 | //主页新鲜事 41 | #define kHomeList @"getFeeds" 42 | 43 | 44 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppDefine/Singleton.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ARCDemo 4 | // 5 | // Created by 振东 何 on 12-7-19. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #define kSingleton(classname) \ 10 | \ 11 | static classname *shared##classname = nil; \ 12 | \ 13 | + (classname *)shared##Instance \ 14 | { \ 15 | @synchronized(self) \ 16 | { \ 17 | if (shared##classname == nil) \ 18 | { \ 19 | shared##classname = [[self alloc] init]; \ 20 | } \ 21 | } \ 22 | \ 23 | return shared##classname; \ 24 | } \ 25 | \ 26 | + (id)allocWithZone:(NSZone *)zone \ 27 | { \ 28 | @synchronized(self) \ 29 | { \ 30 | if (shared##classname == nil) \ 31 | { \ 32 | shared##classname = [super allocWithZone:zone]; \ 33 | return shared##classname; \ 34 | } \ 35 | } \ 36 | \ 37 | return nil; \ 38 | } \ 39 | \ 40 | - (id)copyWithZone:(NSZone *)zone \ 41 | { \ 42 | return self; \ 43 | } \ 44 | \ 45 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MKNetworkKit.h" 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (strong, nonatomic) UIWindow *window; 15 | @property (strong, nonatomic) MKNetworkEngine *networkEngine; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | self.networkEngine = [[MKNetworkEngine alloc] initWithHostName:kMainWebsite]; 16 | [self.networkEngine useCache]; 17 | 18 | return YES; 19 | } 20 | 21 | - (void)applicationWillResignActive:(UIApplication *)application 22 | { 23 | // 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. 24 | // 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. 25 | } 26 | 27 | - (void)applicationDidEnterBackground:(UIApplication *)application 28 | { 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 | { 35 | // 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. 36 | } 37 | 38 | - (void)applicationDidBecomeActive:(UIApplication *)application 39 | { 40 | // 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. 41 | } 42 | 43 | - (void)applicationWillTerminate:(UIApplication *)application 44 | { 45 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/TableDataSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableDataSource.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TWCell.h" 11 | 12 | //Cell Block,用于配置Cell 13 | typedef void (^CellConfigureBlock) (TWCell *cell, id cellDatas); 14 | 15 | @interface TableDataSource : NSObject 16 | @property (strong, nonatomic) NSMutableArray *tableItems; 17 | 18 | - (id)initWithCellIdentifier:(NSString *)cellIdentifier 19 | cellconfigureBlock:(CellConfigureBlock)cellConfigureBlock; 20 | 21 | - (id)itemAtIndexPath:(NSIndexPath *)indexPath; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/TableDataSource.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableDataSource.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TableDataSource.h" 10 | 11 | @interface TableDataSource () 12 | @property (copy, nonatomic) NSString *cellIdentifier; 13 | @property (copy, nonatomic) CellConfigureBlock cellConfigureBlock; 14 | 15 | @end 16 | 17 | @implementation TableDataSource 18 | 19 | - (id)initWithCellIdentifier:(NSString *)cellIdentifier cellconfigureBlock:(CellConfigureBlock)cellConfigureBlock 20 | { 21 | self = [super init]; 22 | if (self) 23 | { 24 | self.cellIdentifier = cellIdentifier; 25 | self.cellConfigureBlock = [cellConfigureBlock copy]; 26 | self.tableItems = [NSMutableArray array]; 27 | } 28 | return self; 29 | } 30 | 31 | - (id)itemAtIndexPath:(NSIndexPath *)indexPath 32 | { 33 | return self.tableItems[(NSUInteger) indexPath.row]; 34 | } 35 | 36 | 37 | #pragma mark - TableView Datasource 38 | 39 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 40 | { 41 | return self.tableItems.count; 42 | } 43 | 44 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 45 | { 46 | TWCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier]; 47 | id item = [self itemAtIndexPath:indexPath]; 48 | self.cellConfigureBlock(cell, item); 49 | return cell; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/TableDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableDelegate.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //路径下的cell高 12 | typedef CGFloat (^CellHeightBlock) (NSIndexPath *indexPath); 13 | 14 | //选中某行时的block 15 | typedef void (^SelectCellBlock) (NSIndexPath *indexPath, id item); 16 | 17 | 18 | @interface TableDelegate : NSObject 19 | 20 | @property (strong, nonatomic) NSMutableArray *tableItems; 21 | 22 | @property (copy, nonatomic) SelectCellBlock selectCell; 23 | @property (copy, nonatomic) CellHeightBlock cellHeight;//如果没有设置,则为默认的44高 24 | 25 | @property (copy, nonatomic) TWLoadMoreDataBlock loadMoreData; 26 | @property (copy, nonatomic) TWUpdateDataBlock updateData; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/TableDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableDelegate.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TableDelegate.h" 10 | 11 | @implementation TableDelegate 12 | 13 | - (id)init 14 | { 15 | self = [super init]; 16 | if (self) 17 | { 18 | self.tableItems = [NSMutableArray array]; 19 | } 20 | return self; 21 | } 22 | 23 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 24 | { 25 | if (self.cellHeight) 26 | { 27 | return self.cellHeight(indexPath); 28 | } 29 | 30 | return 44; 31 | } 32 | 33 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 34 | { 35 | id item = self.tableItems[indexPath.row]; 36 | self.selectCell(indexPath, item); 37 | 38 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 39 | } 40 | 41 | 42 | #pragma mark - PullTable Delegate 43 | 44 | - (void)pullTableViewDidStartPullDownRefresh:(PullTableView *)tableView 45 | { 46 | self.updateData(); 47 | } 48 | 49 | - (void)pullTableViewDidStartPullUpLoadMore:(PullTableView *)tableView 50 | { 51 | self.loadMoreData(); 52 | } 53 | 54 | 55 | #pragma mark - ScrollView Delegate 56 | 57 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView 58 | { 59 | if ([scrollView isKindOfClass:[PullTableView class]]) 60 | { 61 | PullTableView *tableView = (PullTableView *)scrollView; 62 | [tableView pullTableViewDidScroll:scrollView]; 63 | } 64 | } 65 | 66 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 67 | { 68 | if ([scrollView isKindOfClass:[PullTableView class]]) 69 | { 70 | PullTableView *tableView = (PullTableView *)scrollView; 71 | [tableView pullTableViewDidEndDragging:scrollView]; 72 | } 73 | } 74 | 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/TableModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewModel.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | /* 10 | *带TableView的视图控制器的Model。 11 | */ 12 | 13 | #import "VCModel.h" 14 | 15 | @interface TableModel : VCModel 16 | @property (strong, nonatomic) NSMutableArray *tableItems;//TableView数据 17 | @property (assign, nonatomic) NSInteger totalPage;//初始值为-1 18 | @property (assign, nonatomic) NSInteger toPage;//初始值为0 19 | 20 | //判断是下拉刷新数据还是加载更多,默认为YES 21 | @property (assign, nonatomic, getter = isRefreshData) BOOL refreshData; 22 | 23 | //在更新数据时复位参数 24 | - (void)resetRequestParams; 25 | 26 | //更新Model数据,子类可重写这个方法。 27 | - (void)updateModelData:(NSDictionary *)datas; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/TableModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewModel.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TableModel.h" 10 | 11 | @implementation TableModel 12 | 13 | - (id)init 14 | { 15 | if ([super init]) 16 | { 17 | [self resetRequestParams]; 18 | self.tableItems = [NSMutableArray array]; 19 | } 20 | return self; 21 | } 22 | 23 | - (void)resetRequestParams 24 | { 25 | self.refreshData = YES; 26 | self.toPage = 0; 27 | self.totalPage = -1; 28 | [self.tableItems removeAllObjects]; 29 | } 30 | 31 | - (void)updateModelData:(NSDictionary *)data 32 | { 33 | self.totalPage = [data[@"total"] integerValue]; 34 | self.toPage = [data[@"index"] integerValue] + 1; 35 | [self.tableItems addObjectsFromArray:data[@"body"]]; 36 | } 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/Model/VCModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // VCModel.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | /* 10 | *控制器Model,用作数据请求、计算处理等,这里定义一个模板,子类继承来实现具体功能,如果是简单的操作,也可不具体化子类,直接操作本类 11 | */ 12 | 13 | #import 14 | 15 | @interface VCModel : NSObject 16 | 17 | //网络请求方法,默认为POST 18 | @property (copy, nonatomic) NSString *httpMethod; 19 | 20 | - (void)requestDataWithParams:(NSDictionary *)params 21 | forPath:(NSString *)path 22 | finished:(TWFinishedBlock)finished 23 | failed:(TWFailedBlock)failed; 24 | 25 | //下载文件,hostName为主站点名。 26 | - (void)downloadFileWithFilePath:(NSString *)filePath 27 | hostName:(NSString *)hostName 28 | toSavePath:(NSString *)savePath 29 | finished:(TWFinishedBlock)finished 30 | failed:(TWFailedBlock)failed; 31 | 32 | //上传文件,path为要上传的接口,photoKey为后台设定的关键字,fileName为自行设定的文件名。 33 | - (void)upLoadFile:(NSData *)fileData 34 | hostName:(NSString *)hostName 35 | path:(NSString *)path 36 | photoKey:(NSString *)photoKey 37 | fileName:(NSString *)fileName 38 | finished:(TWFinishedBlock)finished 39 | failed:(TWFailedBlock)failed; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // TWCell.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TWCell : UITableViewCell 12 | 13 | //基类方法,由子类实现具体功能 14 | - (void)configureCellWithCellDatas:(id)cellDatas; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // TWCell.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TWCell.h" 10 | 11 | @implementation TWCell 12 | 13 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 14 | { 15 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 16 | if (self) 17 | {} 18 | return self; 19 | } 20 | 21 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated 22 | { 23 | [super setSelected:selected animated:animated]; 24 | } 25 | 26 | - (void)configureCellWithCellDatas:(id)cellDatas{} 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // TWLabel.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TWLabel : UILabel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // TWLabel.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TWLabel.h" 10 | 11 | @implementation TWLabel 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | self = [super initWithFrame:frame]; 16 | if (self) 17 | { 18 | self.backgroundColor = [UIColor clearColor]; 19 | self.font = [UIFont systemFontOfSize:15]; 20 | } 21 | return self; 22 | } 23 | 24 | /* 25 | // Only override drawRect: if you perform custom drawing. 26 | // An empty implementation adversely affects performance during animation. 27 | - (void)drawRect:(CGRect)rect 28 | { 29 | // Drawing code 30 | } 31 | */ 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWTextField.h: -------------------------------------------------------------------------------- 1 | // 2 | // TWTextField.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TWTextField : UITextField 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWTextField.m: -------------------------------------------------------------------------------- 1 | // 2 | // TWTextField.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TWTextField.h" 10 | 11 | @implementation TWTextField 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | self = [super initWithFrame:frame]; 16 | if (self) 17 | { 18 | [self defaultInit]; 19 | } 20 | return self; 21 | } 22 | 23 | - (id)initWithCoder:(NSCoder *)aDecoder 24 | { 25 | self = [super initWithCoder:aDecoder]; 26 | if (self) 27 | { 28 | [self defaultInit]; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)defaultInit 34 | { 35 | self.layer.cornerRadius = 5; 36 | self.clipsToBounds = YES; 37 | self.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.5].CGColor; 38 | self.layer.borderWidth = 1; 39 | [self setFont:[UIFont systemFontOfSize:15]]; 40 | [self setClearButtonMode:UITextFieldViewModeWhileEditing]; 41 | } 42 | 43 | - (CGRect)textRectForBounds:(CGRect)bounds 44 | { 45 | return CGRectInset(bounds, 5, 2.5); 46 | } 47 | 48 | - (CGRect)editingRectForBounds:(CGRect)bounds 49 | { 50 | return CGRectInset(bounds, 5, 2.5); 51 | } 52 | 53 | - (CGRect)placeholderRectForBounds:(CGRect)bounds 54 | { 55 | return CGRectInset(bounds, 5, 2.5); 56 | } 57 | 58 | //根据需求自定义输入框背景 59 | //- (void)drawRect:(CGRect)rect 60 | //{ 61 | // UIImage *textFieldBackground = [[UIImage imageNamed:@"text_field_teal.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15.0, 5.0, 15.0, 5.0)]; 62 | // [textFieldBackground drawInRect:[self bounds]]; 63 | //} 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TWViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TWApp/AppGeneral/AppEngine/TWUIKit/TWViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TWViewController.h" 10 | 11 | @interface TWViewController () 12 | 13 | @end 14 | 15 | @implementation TWViewController 16 | 17 | - (void)viewDidLoad 18 | { 19 | [super viewDidLoad]; 20 | 21 | [self.view setBackgroundColor:[UIColor orangeColor]]; 22 | } 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /TWApp/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Default-568h@2x.png -------------------------------------------------------------------------------- /TWApp/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Default.png -------------------------------------------------------------------------------- /TWApp/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Default@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Category/CategoryUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // CategoryUtils.h 3 | // Line0New 4 | // 5 | // Created by line0 on 13-4-13. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | /*----------分类工具的头文件引入-----*/ 10 | 11 | #import 12 | #import "UITextField+LimitLength.h" 13 | #import "NSData+Addition.h" 14 | #import "UIDevice+DeviceInfo.h" 15 | #import "NSFileManager+Addition.h" 16 | #import "NSDate+Addition.h" 17 | #import "NSString+Addition.h" 18 | #import "UIAlertView+Addition.h" 19 | #import "UIColor+Addition.h" 20 | #import "UIColor+Addition.h" 21 | #import "UIImage+Addition.h" 22 | #import "UIView+Animation.h" 23 | #import "UIView+Frame.h" 24 | #import "UIView+Layer.h" 25 | #import "NSString+MD5Addition.h" 26 | #import "UIDevice+IdentifierAddition.h" 27 | #import "UIImageView+LBBlurredImage.h" 28 | #import "NSString+Regular.h" 29 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSData+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Addition.h 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-5. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSData (Addition) 12 | - (NSData *)dataWithObject:(id)object; 13 | - (id)convertDataToObject; 14 | + (NSString *)contentTypeForImageData:(NSData *)data; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSData+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Addition.m 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-5. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import "NSData+Addition.h" 10 | 11 | @implementation NSData (Addition) 12 | 13 | - (NSData *)dataWithObject:(id)object 14 | { 15 | NSData *data = [NSKeyedArchiver archivedDataWithRootObject:object]; 16 | return data; 17 | } 18 | 19 | - (id)convertDataToObject 20 | { 21 | NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:self]; 22 | return array; 23 | } 24 | 25 | + (NSString *)contentTypeForImageData:(NSData *)data 26 | { 27 | uint8_t c; 28 | [data getBytes:&c length:1]; 29 | 30 | switch (c) 31 | { 32 | case 0xFF: 33 | return @"image/jpeg"; 34 | case 0x89: 35 | return @"image/png"; 36 | case 0x47: 37 | return @"image/gif"; 38 | case 0x49: 39 | case 0x4D: 40 | return @"image/tiff"; 41 | } 42 | return nil; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSDate+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+HW.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDate (Addition) 12 | 13 | /** 14 | * 将日期转化为字符串。 15 | * @param format:转化格式,形如@"yyyy年MM月dd日hh时mm分ss秒"。 16 | * return 返回转化后的字符串。 17 | */ 18 | - (NSString *)convertDateToStringWithFormat:(NSString *)format; 19 | 20 | /** 21 | * 将字符串转化为日期。 22 | * @param string:给定的字符串日期。 23 | * @param format:转化格式,形如@"yyyy年MM月dd日hh时mm分ss秒"。日期格式要和string格式一致,否则会为空。 24 | * return 返回转化后的日期。 25 | */ 26 | - (NSDate *)convertStringToDate:(NSString *)string format:(NSString *)format; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSDate+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+HW.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "NSDate+Addition.h" 10 | 11 | @implementation NSDate (Addition) 12 | 13 | - (NSString *)convertDateToStringWithFormat:(NSString *)format 14 | { 15 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 16 | [dateFormatter setDateFormat:format]; 17 | // NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; 18 | // [dateFormatter setTimeZone:timeZone]; 19 | NSString *dateStr = [dateFormatter stringFromDate:self]; 20 | return dateStr; 21 | } 22 | 23 | - (NSDate *)convertStringToDate:(NSString *)string format:(NSString *)format 24 | { 25 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 26 | [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; 27 | [dateFormatter setDateFormat:format]; 28 | // NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; 29 | // [dateFormatter setTimeZone:timeZone]; 30 | NSDate *date = [dateFormatter dateFromString:string]; 31 | return date; 32 | } 33 | 34 | - (NSDate *)cc_dateByMovingToBeginningOfDay 35 | { 36 | unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; 37 | NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:self]; 38 | [parts setHour:0]; 39 | [parts setMinute:0]; 40 | [parts setSecond:0]; 41 | return [[NSCalendar currentCalendar] dateFromComponents:parts]; 42 | } 43 | 44 | - (NSDate *)cc_dateByMovingToEndOfDay 45 | { 46 | unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; 47 | NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:self]; 48 | [parts setHour:23]; 49 | [parts setMinute:59]; 50 | [parts setSecond:59]; 51 | return [[NSCalendar currentCalendar] dateFromComponents:parts]; 52 | } 53 | 54 | - (NSDate *)cc_dateByMovingToFirstDayOfTheMonth 55 | { 56 | NSDate *d = nil; 57 | BOOL ok = [[NSCalendar currentCalendar] rangeOfUnit:NSMonthCalendarUnit startDate:&d interval:NULL forDate:self]; 58 | NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self); 59 | return d; 60 | } 61 | 62 | - (NSDate *)cc_dateByMovingToFirstDayOfThePreviousMonth 63 | { 64 | NSDateComponents *c = [[NSDateComponents alloc] init]; 65 | c.month = -1; 66 | return [[[NSCalendar currentCalendar] dateByAddingComponents:c toDate:self options:0] cc_dateByMovingToFirstDayOfTheMonth]; 67 | } 68 | 69 | - (NSDate *)cc_dateByMovingToFirstDayOfTheFollowingMonth 70 | { 71 | NSDateComponents *c = [[NSDateComponents alloc] init]; 72 | c.month = 1; 73 | return [[[NSCalendar currentCalendar] dateByAddingComponents:c toDate:self options:0] cc_dateByMovingToFirstDayOfTheMonth]; 74 | } 75 | 76 | - (NSDateComponents *)cc_componentsForMonthDayAndYear 77 | { 78 | return [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:self]; 79 | } 80 | 81 | - (NSUInteger)cc_weekday 82 | { 83 | return [[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:self]; 84 | } 85 | 86 | - (NSUInteger)cc_numberOfDaysInMonth 87 | { 88 | return [[NSCalendar currentCalendar] rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:self].length; 89 | } 90 | 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSFileManager+ Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager+HW.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "NSFileManager+Addition.h" 10 | 11 | @implementation NSFileManager (Addition) 12 | 13 | + (BOOL)createFolder:(NSString *)folder atPath:(NSString *)path 14 | { 15 | NSString *savePath = [path stringByAppendingPathComponent:folder]; 16 | NSFileManager *fileManager = [NSFileManager defaultManager]; 17 | BOOL isDirectory; 18 | BOOL exist = [fileManager fileExistsAtPath:savePath isDirectory:&isDirectory]; 19 | NSError *error = nil; 20 | if (!exist || !isDirectory) 21 | { 22 | [fileManager createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:&error]; 23 | } 24 | 25 | return [fileManager fileExistsAtPath:savePath isDirectory:&isDirectory]; 26 | } 27 | 28 | + (BOOL)saveData:(NSData *)data withName:(NSString *)name atPath:(NSString *)path 29 | { 30 | if (data && name && path) 31 | { 32 | NSString *filePath = [path stringByAppendingPathComponent:name]; 33 | return [data writeToFile:filePath atomically:YES]; 34 | } 35 | 36 | return NO; 37 | } 38 | 39 | + (NSData *)findFile:(NSString *)fileName atPath:(NSString *)path 40 | { 41 | NSData *data = nil; 42 | if (fileName && path) 43 | { 44 | NSFileManager *fileManager = [NSFileManager defaultManager]; 45 | NSString *filePath = [path stringByAppendingPathComponent:fileName]; 46 | 47 | if ([fileManager fileExistsAtPath:filePath]) 48 | { 49 | data = [NSData dataWithContentsOfFile:filePath]; 50 | } 51 | } 52 | 53 | return data; 54 | } 55 | 56 | + (BOOL)deleteFile:(NSString *)fileName atPath:(NSString *)path 57 | { 58 | NSFileManager *fileManager = [NSFileManager defaultManager]; 59 | NSString *filePath = [path stringByAppendingPathComponent:fileName]; 60 | NSError *error; 61 | BOOL success = [fileManager removeItemAtPath:filePath error:&error]; 62 | return success; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSFileManager+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager+HW.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSFileManager (Addition) 12 | 13 | /** 14 | * 在相应目录下创建一个文件夹。 15 | * @param folder:文件夹名。 16 | * @param path:文件夹所在路径。 17 | * return 成功返回YES,失败返回NO。若已存在直接返回YES。 18 | */ 19 | + (BOOL)createFolder:(NSString *)folder atPath:(NSString *)path; 20 | 21 | /** 22 | * 保存文件到相应路径下。 23 | * @param data:要保存的数据。 24 | * @param name:要保存的文件名,如a.txt等。 25 | * @param path:文件保存的路径目录。 26 | * return 成功返回YES,失败返回NO。 27 | */ 28 | + (BOOL)saveData:(NSData *)data withName:(NSString *)name atPath:(NSString *)path; 29 | 30 | /** 31 | * 查找并返回文件。 32 | * @param fileName:要查找的文件名。 33 | * @param path:文件所在的目录。 34 | * return 成功返回文件,失败返回nil。 35 | */ 36 | + (NSData *)findFile:(NSString *)fileName atPath:(NSString *)path; 37 | 38 | /** 39 | * 删除文件。 40 | * @param fileName:要删除的文件名。 41 | * @param path:文件所在的目录。 42 | * return 成功返回YES,失败返回NO。 43 | */ 44 | + (BOOL)deleteFile:(NSString *)fileName atPath:(NSString *)path; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSString+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+HW.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (Addition) 12 | 13 | /** 14 | * 计算字符串的字数。 15 | * @param string:输入字符串。 16 | * return 返回输入字符串的字数。 17 | */ 18 | - (int)wordsCount; 19 | 20 | - (NSString *)URLDecodedString; 21 | - (NSString *)URLEncodedString; 22 | - (NSString *)encodeStringWithUTF8; 23 | - (NSUInteger)byteLengthWithEncoding:(NSStringEncoding)encoding; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSString+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+HW.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "NSString+Addition.h" 10 | 11 | @implementation NSString (Addition) 12 | 13 | - (int)wordsCount 14 | { 15 | int i,n = [self length], l = 0, a = 0, b = 0; 16 | unichar c; 17 | for(i = 0;i < n; i++) 18 | { 19 | c = [self characterAtIndex:i]; 20 | if(isblank(c)) 21 | { 22 | b++; 23 | }else if(isascii(c)) 24 | { 25 | a++; 26 | }else{ 27 | l++; 28 | } 29 | } 30 | if(a == 0 && l == 0) return 0; 31 | return l + (int)ceilf((float)(a + b) / 2.0); 32 | } 33 | 34 | - (NSString *)URLEncodedString 35 | { 36 | NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 37 | (CFStringRef)self, 38 | NULL, 39 | CFSTR("!*'();:@&=+$,/?%#[]"), 40 | kCFStringEncodingUTF8)); 41 | return result; 42 | } 43 | 44 | - (NSString *)URLDecodedString 45 | { 46 | NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, 47 | (CFStringRef)self, 48 | CFSTR(""), 49 | kCFStringEncodingUTF8)); 50 | return result; 51 | } 52 | 53 | - (NSString *)encodeStringWithUTF8 54 | { 55 | NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin1); 56 | const char *c = [self cStringUsingEncoding:encoding]; 57 | NSString *str = [NSString stringWithCString:c encoding:NSUTF8StringEncoding]; 58 | 59 | return str; 60 | } 61 | 62 | - (NSUInteger)byteLengthWithEncoding:(NSStringEncoding)encoding 63 | { 64 | if (!self) 65 | { 66 | return 0; 67 | } 68 | 69 | const char *byte = [self cStringUsingEncoding:encoding]; 70 | return strlen(byte); 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSString+MD5Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MD5Addition.h 3 | // UIDeviceAddition 4 | // 5 | // Created by Georg Kitz on 20.08.11. 6 | // Copyright 2011 Aurora Apps. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString(MD5Addition) 12 | 13 | - (NSString *) stringFromMD5; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSString+MD5Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MD5Addition.m 3 | // UIDeviceAddition 4 | // 5 | // Created by Georg Kitz on 20.08.11. 6 | // Copyright 2011 Aurora Apps. All rights reserved. 7 | // 8 | 9 | #import "NSString+MD5Addition.h" 10 | #import 11 | 12 | @implementation NSString(MD5Addition) 13 | 14 | - (NSString *) stringFromMD5{ 15 | 16 | if(self == nil || [self length] == 0) 17 | return nil; 18 | 19 | const char *value = [self UTF8String]; 20 | 21 | unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH]; 22 | CC_MD5(value, strlen(value), outputBuffer); 23 | 24 | NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; 25 | for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){ 26 | [outputString appendFormat:@"%02x",outputBuffer[count]]; 27 | } 28 | 29 | return outputString; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSString+Regular.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Regular.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (Regular) 12 | 13 | - (BOOL)isValidateEmail;//邮箱符合性验证。 14 | - (BOOL)isNumber;//全是数字。 15 | - (BOOL)isEnglishWords;//验证英文字母。 16 | - (BOOL)isValidatePassword;//验证密码:6—16位,只能包含字符、数字和 下划线。 17 | - (BOOL)isChineseWords;//验证是否为汉字。 18 | - (BOOL)isInternetUrl;//验证是否为网络链接。 19 | - (BOOL)isPhoneNumber;//验证是否为电话号码。正确格式为:XXXX-XXXXXXX,XXXX-XXXXXXXX,XXX-XXXXXXX,XXX-XXXXXXXX,XXXXXXX,XXXXXXXX 20 | - (BOOL)isElevenDigitNum;//判断是否为11位的数字 21 | - (BOOL)isIdentifyCardNumber;//验证15或18位身份证。 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/NSString+Regular.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Regular.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "NSString+Regular.h" 10 | 11 | @implementation NSString (Regular) 12 | 13 | - (BOOL)isValidateEmail 14 | { 15 | NSString *regex = @"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b"; 16 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 17 | return [predicate evaluateWithObject:self]; 18 | } 19 | 20 | - (BOOL)isNumber 21 | { 22 | NSString *regex = @"^[0-9]*$"; 23 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 24 | return [predicate evaluateWithObject:self]; 25 | } 26 | 27 | - (BOOL)isEnglishWords 28 | { 29 | NSString *regex = @"^[A-Za-z]+$"; 30 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 31 | return [predicate evaluateWithObject:self]; 32 | } 33 | 34 | //字母数字下划线,6-16位 35 | - (BOOL)isValidatePassword 36 | { 37 | NSString *regex = @"^[\\w\\d_]{6,16}$"; 38 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 39 | return [predicate evaluateWithObject:self]; 40 | } 41 | 42 | - (BOOL)isChineseWords 43 | { 44 | NSString *regex = @"^[\u4e00-\u9fa5],{0,}$"; 45 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 46 | return [predicate evaluateWithObject:self]; 47 | } 48 | 49 | - (BOOL)isInternetUrl 50 | { 51 | NSString *regex = @"^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$ ;^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$"; 52 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 53 | return [predicate evaluateWithObject:self]; 54 | } 55 | 56 | - (BOOL)isPhoneNumber 57 | { 58 | NSString *regex = @"^(\(\\d{3,4}\\)|\\d{3,4}-)?\\d{7,8}$"; 59 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 60 | return [predicate evaluateWithObject:self]; 61 | } 62 | 63 | - (BOOL)isElevenDigitNum 64 | { 65 | NSString *regex = @"^[0-9]*$"; 66 | 67 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 68 | BOOL result = [predicate evaluateWithObject:self]; 69 | 70 | if (result && self.length == 11) 71 | return YES; 72 | 73 | return NO; 74 | } 75 | 76 | - (BOOL)isIdentifyCardNumber 77 | { 78 | NSString *regex = @"^\\d{15}|\\d{}18$"; 79 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; 80 | return [predicate evaluateWithObject:self]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIAlertView+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+Addition.h 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-4. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIAlertView (Addition) 12 | + (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)msg; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIAlertView+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+Addition.m 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-4. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import "UIAlertView+Addition.h" 10 | 11 | @implementation UIAlertView (Addition) 12 | 13 | + (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)msg 14 | { 15 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title 16 | message:msg 17 | delegate:nil 18 | cancelButtonTitle:@"确定" 19 | otherButtonTitles:nil, nil]; 20 | [alertView show]; 21 | } 22 | 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIColor+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+WSK.h 3 | // CTCockpit 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (Addition) 12 | 13 | /** 14 | * 根据RGB返回UIColor。 15 | * @param red、green、blue:范围0—255。 16 | * @param alpha:透明度。 17 | * return UIColor。 18 | */ 19 | + (UIColor *)red:(int)red green:(int)green blue:(int)blue alpha:(CGFloat)alpha; 20 | 21 | /** 22 | * 根据UIColor返回RGB数组。 23 | * @param color:传递的参数。 24 | * return RGB数组 25 | */ 26 | + (NSArray *)convertColorToRBG:(UIColor *)color; 27 | 28 | /** 29 | * 根据十六进制颜色值返回UIColor。 30 | * @param hexColor:十六进制颜色值。 31 | * return UIColor。 32 | */ 33 | + (UIColor *)convertHexColorToUIColor:(NSInteger)hexColor; 34 | 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIColor+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+WSK.m 3 | // CTCockpit 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // 7 | // 8 | 9 | #import "UIColor+Addition.h" 10 | 11 | @implementation UIColor (Addition) 12 | 13 | + (UIColor *)red:(int)red green:(int)green blue:(int)blue alpha:(CGFloat)alpha 14 | { 15 | UIColor *color = [UIColor colorWithRed:red/255.f green:green/255.f blue:blue/255.f alpha:alpha]; 16 | return color; 17 | } 18 | 19 | + (NSArray *)convertColorToRBG:(UIColor *)uicolor 20 | { 21 | CGColorRef color = [uicolor CGColor]; 22 | int numComponents = CGColorGetNumberOfComponents(color); 23 | NSArray *array = nil; 24 | 25 | if (numComponents == 4) 26 | { 27 | int rValue, gValue, bValue; 28 | const CGFloat *components = CGColorGetComponents(color); 29 | rValue = (int)(components[0] * 255); 30 | gValue = (int)(components[1] * 255); 31 | bValue = (int)(components[2] * 255); 32 | 33 | array = [NSArray arrayWithObjects:[NSNumber numberWithInt:rValue], [NSNumber numberWithInt:gValue], [NSNumber numberWithInt:bValue], nil]; 34 | } 35 | 36 | return array; 37 | } 38 | 39 | UIColor* UIColorFromHex(NSInteger colorInHex) 40 | { 41 | // colorInHex should be value like 0xFFFFFF 42 | return [UIColor colorWithRed:((float) ((colorInHex & 0xFF0000) >> 16)) / 0xFF 43 | green:((float) ((colorInHex & 0xFF00) >> 8)) / 0xFF 44 | blue:((float) (colorInHex & 0xFF)) / 0xFF 45 | alpha:1.0]; 46 | } 47 | 48 | + (UIColor *)convertHexColorToUIColor:(NSInteger)hexColor 49 | { 50 | return [UIColor colorWithRed:((float) ((hexColor & 0xFF0000) >> 16)) / 0xFF 51 | green:((float) ((hexColor & 0xFF00) >> 8)) / 0xFF 52 | blue:((float) (hexColor & 0xFF)) / 0xFF 53 | alpha:1.0]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIDevice+DeviceInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Erica Sadun, http://ericasadun.com 3 | iPhone Developer's Cookbook, 6.x Edition 4 | BSD License, Use at your own risk 5 | */ 6 | 7 | #import 8 | 9 | #define IFPGA_NAMESTRING @"iFPGA" 10 | 11 | #define IPHONE_1G_NAMESTRING @"iPhone 1G" 12 | #define IPHONE_3G_NAMESTRING @"iPhone 3G" 13 | #define IPHONE_3GS_NAMESTRING @"iPhone 3GS" 14 | #define IPHONE_4_NAMESTRING @"iPhone 4" 15 | #define IPHONE_4S_NAMESTRING @"iPhone 4S" 16 | #define IPHONE_5_NAMESTRING @"iPhone 5" 17 | #define IPHONE_UNKNOWN_NAMESTRING @"Unknown iPhone" 18 | 19 | #define IPOD_1G_NAMESTRING @"iPod touch 1G" 20 | #define IPOD_2G_NAMESTRING @"iPod touch 2G" 21 | #define IPOD_3G_NAMESTRING @"iPod touch 3G" 22 | #define IPOD_4G_NAMESTRING @"iPod touch 4G" 23 | #define IPOD_UNKNOWN_NAMESTRING @"Unknown iPod" 24 | 25 | #define IPAD_1G_NAMESTRING @"iPad 1G" 26 | #define IPAD_2G_NAMESTRING @"iPad 2G" 27 | #define IPAD_3G_NAMESTRING @"iPad 3G" 28 | #define IPAD_4G_NAMESTRING @"iPad 4G" 29 | #define IPAD_UNKNOWN_NAMESTRING @"Unknown iPad" 30 | 31 | #define APPLETV_2G_NAMESTRING @"Apple TV 2G" 32 | #define APPLETV_3G_NAMESTRING @"Apple TV 3G" 33 | #define APPLETV_4G_NAMESTRING @"Apple TV 4G" 34 | #define APPLETV_UNKNOWN_NAMESTRING @"Unknown Apple TV" 35 | 36 | #define IOS_FAMILY_UNKNOWN_DEVICE @"Unknown iOS device" 37 | 38 | #define SIMULATOR_NAMESTRING @"iPhone Simulator" 39 | #define SIMULATOR_IPHONE_NAMESTRING @"iPhone Simulator" 40 | #define SIMULATOR_IPAD_NAMESTRING @"iPad Simulator" 41 | #define SIMULATOR_APPLETV_NAMESTRING @"Apple TV Simulator" // :) 42 | 43 | //iPhone 3G 以后各代的CPU型号和频率 44 | #define IPHONE_3G_CPUTYPE @"ARM11" 45 | #define IPHONE_3G_CPUFREQUENCY @"412MHz" 46 | #define IPHONE_3GS_CPUTYPE @"ARM Cortex A8" 47 | #define IPHONE_3GS_CPUFREQUENCY @"600MHz" 48 | #define IPHONE_4_CPUTYPE @"Apple A4" 49 | #define IPHONE_4_CPUFREQUENCY @"1GMHz" 50 | #define IPHONE_4S_CPUTYPE @"Apple A5 Double Core" 51 | #define IPHONE_4S_CPUFREQUENCY @"800MHz" 52 | 53 | //iPod touch 4G 的CPU型号和频率 54 | #define IPOD_4G_CPUTYPE @"Apple A4" 55 | #define IPOD_4G_CPUFREQUENCY @"800MHz" 56 | 57 | #define IOS_CPUTYPE_UNKNOWN @"Unknown CPU type" 58 | #define IOS_CPUFREQUENCY_UNKNOWN @"Unknown CPU frequency" 59 | 60 | typedef enum 61 | { 62 | UIDeviceUnknown, 63 | 64 | UIDeviceSimulator, 65 | UIDeviceSimulatoriPhone, 66 | UIDeviceSimulatoriPad, 67 | UIDeviceSimulatorAppleTV, 68 | 69 | UIDevice1GiPhone, 70 | UIDevice3GiPhone, 71 | UIDevice3GSiPhone, 72 | UIDevice4iPhone, 73 | UIDevice4SiPhone, 74 | UIDevice5iPhone, 75 | 76 | UIDevice1GiPod, 77 | UIDevice2GiPod, 78 | UIDevice3GiPod, 79 | UIDevice4GiPod, 80 | 81 | UIDevice1GiPad, 82 | UIDevice2GiPad, 83 | UIDevice3GiPad, 84 | UIDevice4GiPad, 85 | 86 | UIDeviceAppleTV2, 87 | UIDeviceAppleTV3, 88 | UIDeviceAppleTV4, 89 | 90 | UIDeviceUnknowniPhone, 91 | UIDeviceUnknowniPod, 92 | UIDeviceUnknowniPad, 93 | UIDeviceUnknownAppleTV, 94 | UIDeviceIFPGA, 95 | 96 | } UIDevicePlatform; 97 | 98 | typedef enum 99 | { 100 | UIDeviceFamilyiPhone, 101 | UIDeviceFamilyiPod, 102 | UIDeviceFamilyiPad, 103 | UIDeviceFamilyAppleTV, 104 | UIDeviceFamilyUnknown, 105 | 106 | } UIDeviceFamily; 107 | 108 | @interface UIDevice (DeviceInfo) 109 | 110 | /** 获取设备型号*/ 111 | + (NSString *)deviceVersion; 112 | 113 | /** 获取iOS系统的版本号 */ 114 | + (NSString*)systemVersion; 115 | 116 | /** 判断当前设备是否ipad */ 117 | + (BOOL)isIpad; 118 | 119 | /** 判断当前设备是否iphone */ 120 | + (BOOL)isIphone; 121 | 122 | /** 判断当前系统是否有摄像头 */ 123 | + (BOOL)hasCamera; 124 | 125 | //获取设备状态,是否插入耳机,如果插入耳机,则返回“YES" 126 | //+ (BOOL)isHeadphone; 127 | 128 | //获取用户语言。 129 | + (NSString *)userPreferLanguages; 130 | 131 | //判断是否为5系列。 132 | + (BOOL)isIphone5OriPod5; 133 | 134 | 135 | 136 | 137 | - (NSString *)platformInfo; //平台信息 138 | 139 | - (NSString *)cpuType; //cpu型号 140 | - (NSString *)cpuFrequency; //cpu频率 141 | - (NSUInteger)cpuCount; //cpu核数 142 | - (NSArray *)cpuUsage; //cpu利用率 143 | 144 | - (NSUInteger)totalMemoryBytes; //获取手机内存总量,返回的是字节数 145 | - (NSUInteger)freeMemoryBytes; //获取手机可用内存,返回的是字节数 146 | 147 | - (long long)freeDiskSpaceBytes; //获取手机硬盘空闲空间,返回的是字节数 148 | - (long long)totalDiskSpaceBytes; //获取手机硬盘总空间,返回的是字节数 149 | 150 | - (BOOL)isJailBreak; //是否越狱 151 | 152 | - (BOOL)bluetoothCheck; //是否支持蓝牙 153 | 154 | 155 | 156 | 157 | @end 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIDevice+IdentifierAddition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice(Identifier).h 3 | // UIDeviceAddition 4 | // 5 | // Created by Georg Kitz on 20.08.11. 6 | // Copyright 2011 Aurora Apps. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface UIDevice (IdentifierAddition) 13 | 14 | /* 15 | * @method uniqueDeviceIdentifier 16 | * @description use this method when you need a unique identifier in one app. 17 | * It generates a hash from the MAC-address in combination with the bundle identifier 18 | * of your app. 19 | */ 20 | 21 | - (NSString *) uniqueDeviceIdentifier; 22 | 23 | /* 24 | * @method uniqueGlobalDeviceIdentifier 25 | * @description use this method when you need a unique global identifier to track a device 26 | * with multiple apps. as example a advertising network will use this method to track the device 27 | * from different apps. 28 | * It generates a hash from the MAC-address only. 29 | */ 30 | 31 | - (NSString *) uniqueGlobalDeviceIdentifier; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIDevice+IdentifierAddition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice(Identifier).m 3 | // UIDeviceAddition 4 | // 5 | // Created by Georg Kitz on 20.08.11. 6 | // Copyright 2011 Aurora Apps. All rights reserved. 7 | // 8 | 9 | #import "UIDevice+IdentifierAddition.h" 10 | #import "NSString+MD5Addition.h" 11 | 12 | #include // Per msqr 13 | #include 14 | #include 15 | #include 16 | 17 | @interface UIDevice(Private) 18 | 19 | - (NSString *) macaddress; 20 | 21 | @end 22 | 23 | @implementation UIDevice (IdentifierAddition) 24 | 25 | //////////////////////////////////////////////////////////////////////////////// 26 | #pragma mark - 27 | #pragma mark Private Methods 28 | 29 | // Return the local MAC addy 30 | // Courtesy of FreeBSD hackers email list 31 | // Accidentally munged during previous update. Fixed thanks to erica sadun & mlamb. 32 | - (NSString *) macaddress{ 33 | 34 | int mib[6]; 35 | size_t len; 36 | char *buf; 37 | unsigned char *ptr; 38 | struct if_msghdr *ifm; 39 | struct sockaddr_dl *sdl; 40 | 41 | mib[0] = CTL_NET; 42 | mib[1] = AF_ROUTE; 43 | mib[2] = 0; 44 | mib[3] = AF_LINK; 45 | mib[4] = NET_RT_IFLIST; 46 | 47 | if ((mib[5] = if_nametoindex("en0")) == 0) { 48 | printf("Error: if_nametoindex error\n"); 49 | return NULL; 50 | } 51 | 52 | if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { 53 | printf("Error: sysctl, take 1\n"); 54 | return NULL; 55 | } 56 | 57 | if ((buf = malloc(len)) == NULL) { 58 | printf("Could not allocate memory. error!\n"); 59 | return NULL; 60 | } 61 | 62 | if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { 63 | printf("Error: sysctl, take 2"); 64 | free(buf); 65 | return NULL; 66 | } 67 | 68 | ifm = (struct if_msghdr *)buf; 69 | sdl = (struct sockaddr_dl *)(ifm + 1); 70 | ptr = (unsigned char *)LLADDR(sdl); 71 | NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 72 | *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; 73 | free(buf); 74 | 75 | return outstring; 76 | } 77 | 78 | //////////////////////////////////////////////////////////////////////////////// 79 | #pragma mark - 80 | #pragma mark Public Methods 81 | 82 | - (NSString *) uniqueDeviceIdentifier{ 83 | NSString *macaddress = [[UIDevice currentDevice] macaddress]; 84 | NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; 85 | 86 | NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier]; 87 | NSString *uniqueIdentifier = [stringToHash stringFromMD5]; 88 | 89 | return uniqueIdentifier; 90 | } 91 | 92 | - (NSString *) uniqueGlobalDeviceIdentifier{ 93 | NSString *macaddress = [[UIDevice currentDevice] macaddress]; 94 | NSString *uniqueIdentifier = [macaddress stringFromMD5]; 95 | 96 | return uniqueIdentifier; 97 | } 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIImage+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WSK.h 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (Addition) 12 | 13 | /** 14 | * 抓取屏幕。 15 | * @param scale:屏幕放大倍数,1为原尺寸。 16 | * return 屏幕后的Image。 17 | */ 18 | + (UIImage *)grabScreenWithScale:(CGFloat)scale; 19 | 20 | /** 21 | * 抓取UIView及其子类。 22 | * @param view: UIView及其子类。 23 | * @param scale:屏幕放大倍数,1为原尺寸。 24 | * return 抓取图片后的Image。 25 | */ 26 | + (UIImage *)grabImageWithView:(UIView *)view scale:(CGFloat)scale; 27 | 28 | /** 29 | * 合并两个Image。 30 | * @param image1、image2: 两张图片。 31 | * @param frame1、frame2:两张图片放置的位置。 32 | * @param size:返回图片的尺寸。 33 | * return 合并后的两个图片的Image。 34 | */ 35 | + (UIImage *)mergeWithImage1:(UIImage *)image1 image2:(UIImage *)image2 frame1:(CGRect)frame1 frame2:(CGRect)frame2 size:(CGSize)size; 36 | 37 | /** 38 | * 把一个Image盖在另一个Image上面。 39 | * @param image: 底图。 40 | * @param mask:盖在上面的图。 41 | * return Image。 42 | */ 43 | + (UIImage *)maskImage:(UIImage *)image withMask:(UIImage *)mask; 44 | 45 | /** 46 | * 把一个Image尺寸缩放到另一个尺寸。 47 | * @param view: UIView及其子类。 48 | * @param scale:屏幕放大倍数,1为原尺寸。 49 | * return 尺寸更改后的Image。 50 | */ 51 | + (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size; 52 | 53 | /** 54 | * 改变一个Image的色彩。 55 | * @param image: 被改变的Image。 56 | * @param color: 要改变的目标色彩。 57 | * return 色彩更改后的Image。 58 | */ 59 | +(UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color; 60 | 61 | //按frame裁减图片 62 | + (UIImage *)captureView:(UIView *)view frame:(CGRect)frame; 63 | 64 | 65 | - (UIImage *)imageAtRect:(CGRect)rect; 66 | - (UIImage *)imageByScalingProportionallyToMinimumSize:(CGSize)targetSize; 67 | - (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize; 68 | - (UIImage *)imageByScalingToSize:(CGSize)targetSize; 69 | - (UIImage *)imageRotatedByRadians:(CGFloat)radians; 70 | - (UIImage *)imageRotatedByDegrees:(CGFloat)degrees; 71 | 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIImageView+LBBlurredImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+LBBlurredImage.h 3 | // LBBlurredImage 4 | // 5 | // Created by Luca Bernardi on 11/11/12. 6 | // Copyright (c) 2012 Luca Bernardi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^LBBlurredImageCompletionBlock)(NSError *error); 12 | 13 | extern NSString *const kLBBlurredImageErrorDomain; 14 | 15 | extern CGFloat const kLBBlurredImageDefaultBlurRadius; 16 | 17 | enum LBBlurredImageError 18 | { 19 | LBBlurredImageErrorFilterNotAvailable = 0, 20 | }; 21 | 22 | 23 | @interface UIImageView (LBBlurredImage) 24 | 25 | /** 26 | Set the blurred version of the provided image to the UIImageView 27 | 28 | @param UIImage the image to blur and set as UIImageView's image 29 | @param CGFLoat the radius of the blur used by the Gaussian filter 30 | *param LBBlurredImageCompletionBlock a completion block called after the image 31 | was blurred and set to the UIImageView (the block is dispatched on main thread) 32 | */ 33 | - (void)setImageToBlur: (UIImage *)image 34 | blurRadius: (CGFloat)blurRadius 35 | completionBlock: (LBBlurredImageCompletionBlock) completion; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIImageView+LBBlurredImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+LBBlurredImage.m 3 | // LBBlurredImage 4 | // 5 | // Created by Luca Bernardi on 11/11/12. 6 | // Copyright (c) 2012 Luca Bernardi. All rights reserved. 7 | // 8 | 9 | #import "UIImageView+LBBlurredImage.h" 10 | #import 11 | 12 | 13 | NSString *const kLBBlurredImageErrorDomain = @"com.lucabernardi.blurred_image_additions"; 14 | CGFloat const kLBBlurredImageDefaultBlurRadius = 20.0; 15 | 16 | 17 | @implementation UIImageView (LBBlurredImage) 18 | 19 | #pragma mark - LBBlurredImage Additions 20 | 21 | - (void)setImageToBlur: (UIImage *)image 22 | blurRadius: (CGFloat)blurRadius 23 | completionBlock: (LBBlurredImageCompletionBlock) completion 24 | 25 | { 26 | CIContext *context = [CIContext contextWithOptions:nil]; 27 | CIImage *sourceImage = [CIImage imageWithCGImage:image.CGImage]; 28 | 29 | // Apply clamp filter: 30 | // this is needed because the CIGaussianBlur when applied makes 31 | // a trasparent border around the image 32 | 33 | NSString *clampFilterName = @"CIAffineClamp"; 34 | CIFilter *clamp = [CIFilter filterWithName:clampFilterName]; 35 | 36 | if (!clamp) { 37 | 38 | NSError *error = [self errorForNotExistingFilterWithName:clampFilterName]; 39 | if (completion) { 40 | completion(error); 41 | } 42 | return; 43 | } 44 | 45 | [clamp setValue:sourceImage 46 | forKey:kCIInputImageKey]; 47 | 48 | CIImage *clampResult = [clamp valueForKey:kCIOutputImageKey]; 49 | 50 | // Apply Gaussian Blur filter 51 | 52 | NSString *gaussianBlurFilterName = @"CIGaussianBlur"; 53 | CIFilter *gaussianBlur = [CIFilter filterWithName:gaussianBlurFilterName]; 54 | 55 | if (!gaussianBlur) { 56 | 57 | NSError *error = [self errorForNotExistingFilterWithName:gaussianBlurFilterName]; 58 | if (completion) { 59 | completion(error); 60 | } 61 | return; 62 | } 63 | 64 | [gaussianBlur setValue:clampResult 65 | forKey:kCIInputImageKey]; 66 | [gaussianBlur setValue:[NSNumber numberWithFloat:blurRadius] 67 | forKey:@"inputRadius"]; 68 | 69 | CIImage *gaussianBlurResult = [gaussianBlur valueForKey:kCIOutputImageKey]; 70 | 71 | __weak UIImageView *selfWeak = self; 72 | 73 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 74 | 75 | CGImageRef cgImage = [context createCGImage:gaussianBlurResult 76 | fromRect:[sourceImage extent]]; 77 | 78 | UIImage *blurredImage = [UIImage imageWithCGImage:cgImage]; 79 | CGImageRelease(cgImage); 80 | 81 | dispatch_async(dispatch_get_main_queue(), ^{ 82 | selfWeak.image = blurredImage; 83 | if (completion){ 84 | completion(nil); 85 | } 86 | }); 87 | }); 88 | } 89 | 90 | /** 91 | Internal method for generate an NSError if the provided CIFilter name doesn't exists 92 | */ 93 | - (NSError *)errorForNotExistingFilterWithName:(NSString *)filterName 94 | { 95 | NSString *errorDescription = [NSString stringWithFormat:@"The CIFilter named %@ doesn't exist",filterName]; 96 | NSError *error = [NSError errorWithDomain:kLBBlurredImageErrorDomain 97 | code:LBBlurredImageErrorFilterNotAvailable 98 | userInfo:@{NSLocalizedDescriptionKey : errorDescription}]; 99 | return error; 100 | } 101 | 102 | @end 103 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UITextField+LimitLength.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+LimitLength.h 3 | // TextLengthLimitDemo 4 | // 5 | // Created by Su XinDe on 13-4-8. 6 | // Copyright (c) 2013年 Su XinDe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITextField (LimitLength) 12 | 13 | - (void)limitTextLength:(int)length; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UITextField+LimitLength.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+LimitLength.m 3 | // TextLengthLimitDemo 4 | // 5 | // Created by Su XinDe on 13-4-8. 6 | // Copyright (c) 2013年 Su XinDe. All rights reserved. 7 | // 8 | 9 | #import "UITextField+LimitLength.h" 10 | #import 11 | #import 12 | 13 | @implementation UITextField (LimitLength) 14 | 15 | static NSString *kLimitTextLengthKey = @"kLimitTextLengthKey"; 16 | 17 | - (void)limitTextLength:(int)length 18 | { 19 | objc_setAssociatedObject(self, (__bridge const void *)(kLimitTextLengthKey), [NSNumber numberWithInt:length], OBJC_ASSOCIATION_RETAIN_NONATOMIC); 20 | [self addTarget:self action:@selector(textFieldTextLengthLimit:) forControlEvents:UIControlEventEditingChanged]; 21 | } 22 | 23 | - (void)textFieldTextLengthLimit:(id)sender 24 | { 25 | NSNumber *lengthNumber = objc_getAssociatedObject(self, (__bridge const void *)(kLimitTextLengthKey)); 26 | int length = [lengthNumber intValue]; 27 | if(self.text.length > length){ 28 | self.text = [self.text substringToIndex:length]; 29 | } 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Addition.h 3 | // Line0New 4 | // 5 | // Created by line0 on 13-5-17. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Addition) 12 | - (UIView *)subViewWithTag:(int)tag; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Addition.m 3 | // Line0New 4 | // 5 | // Created by line0 on 13-5-17. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "UIView+Addition.h" 10 | 11 | @implementation UIView (Addition) 12 | 13 | - (UIView *)subViewWithTag:(int)tag 14 | { 15 | for (UIView *v in self.subviews) 16 | { 17 | if (v.tag == tag) 18 | { 19 | return v; 20 | } 21 | } 22 | return nil; 23 | } 24 | 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Animation.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Animation.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | /** 10 | * direction取值:kCATransitionFromTop kCATransitionFromBottom 11 | * kCATransitionFromLeft kCATransitionFromRight 12 | */ 13 | 14 | #define kCameraEffectOpen @"cameraIrisHollowOpen" 15 | #define kCameraEffectClose @"cameraIrisHollowClose" 16 | 17 | 18 | #import 19 | #import "QuartzCore/QuartzCore.h" 20 | 21 | @interface UIView (Animation) 22 | 23 | //揭开 24 | + (void)animationReveal:(UIView *)view direction:(NSString *)direction; 25 | 26 | //渐隐渐消 27 | + (void)animationFade:(UIView *)view; 28 | 29 | //翻转 30 | + (void)animationFlip:(UIView *)view direction:(NSString *)direction; 31 | 32 | //旋转缩放 33 | + (void)animationRotateAndScaleEffects:(UIView *)view;//各种旋转缩放效果。 34 | + (void)animationRotateAndScaleDownUp:(UIView *)view;//旋转同时缩小放大效果 35 | 36 | //push 37 | + (void)animationPush:(UIView *)view direction:(NSString *)direction; 38 | 39 | //Curl UnCurl 40 | + (void)animationCurl:(UIView *)view direction:(NSString *)direction; 41 | + (void)animationUnCurl:(UIView *)view direction:(NSString *)direction; 42 | 43 | //Move 44 | + (void)animationMove:(UIView *)view direction:(NSString *)direction; 45 | 46 | //立方体 47 | + (void)animationCube:(UIView *)view direction:(NSString *)direction; 48 | 49 | //水波纹 50 | + (void)animationRippleEffect:(UIView *)view; 51 | 52 | //相机开合 53 | + (void)animationCameraEffect:(UIView *)view type:(NSString *)type; 54 | 55 | //吸收 56 | + (void)animationSuckEffect:(UIView *)view; 57 | 58 | + (void)animationBounceOut:(UIView *)view; 59 | + (void)animationBounceIn:(UIView *)view; 60 | + (void)animationBounce:(UIView *)view; 61 | 62 | 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Frame.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Frame.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Frame) 12 | 13 | /** 14 | * 返回UIView及其子类的位置和尺寸。分别为左、右边界在X轴方向上的距离,上、下边界在Y轴上的距离,View的宽和高。 15 | */ 16 | 17 | @property(nonatomic) CGFloat left; 18 | @property(nonatomic) CGFloat right; 19 | @property(nonatomic) CGFloat top; 20 | @property(nonatomic) CGFloat bottom; 21 | @property(nonatomic) CGFloat width; 22 | @property(nonatomic) CGFloat height; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Frame.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Frame.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "UIView+Frame.h" 10 | 11 | @implementation UIView (Frame) 12 | 13 | - (CGFloat)left 14 | { 15 | return self.frame.origin.x; 16 | } 17 | 18 | - (void)setLeft:(CGFloat)x 19 | { 20 | CGRect frame = self.frame; 21 | frame.origin.x = x; 22 | self.frame = frame; 23 | } 24 | 25 | - (CGFloat)right 26 | { 27 | return self.frame.origin.x + self.frame.size.width; 28 | } 29 | 30 | - (void)setRight:(CGFloat)right 31 | { 32 | CGRect frame = self.frame; 33 | frame.origin.x = right - frame.size.width; 34 | self.frame = frame; 35 | } 36 | 37 | - (CGFloat)top 38 | { 39 | return self.frame.origin.y; 40 | } 41 | 42 | - (void)setTop:(CGFloat)y 43 | { 44 | CGRect frame = self.frame; 45 | frame.origin.y = y; 46 | self.frame = frame; 47 | } 48 | 49 | - (CGFloat)bottom 50 | { 51 | return self.frame.origin.y + self.frame.size.height; 52 | } 53 | 54 | - (void)setBottom:(CGFloat)bottom 55 | { 56 | CGRect frame = self.frame; 57 | frame.origin.y = bottom - frame.size.height; 58 | self.frame = frame; 59 | } 60 | 61 | - (CGFloat)width 62 | { 63 | return self.frame.size.width; 64 | } 65 | 66 | - (void)setWidth:(CGFloat)width 67 | { 68 | CGRect frame = self.frame; 69 | frame.size.width = width; 70 | self.frame = frame; 71 | } 72 | 73 | - (CGFloat)height 74 | { 75 | return self.frame.size.height; 76 | } 77 | 78 | - (void)setHeight:(CGFloat)height 79 | { 80 | CGRect frame = self.frame; 81 | frame.size.height = height; 82 | self.frame = frame; 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Layer.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+WSK.h 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Layer) 12 | 13 | /** 14 | * 产生一个Image的倒影,并把这个倒影图片加在一个View上面。 15 | * @param image:被倒影的原图。 16 | * @param frame:盖在上面的图。 17 | * @param opacity:倒影的透明度,0为完全透明,即倒影不可见;1为完全不透明。 18 | * @param view:倒影加载在上面。 19 | * return 产生倒影后的View。 20 | */ 21 | + (UIView *)reflectImage:(UIImage *)image withFrame:(CGRect)frame opacity:(CGFloat)opacity atView:(UIView *)view; 22 | 23 | //开始和停止旋转动画 24 | - (void)startRotationAnimatingWithDuration:(CGFloat)duration; 25 | - (void)stopRotationAnimating; 26 | 27 | //暂停恢复动画 28 | - (void)pauseAnimating; 29 | - (void)resumeAnimating; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /TWApp/Lib/Category/UIView+Layer.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+WSK.m 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import "UIView+Layer.h" 10 | #import "QuartzCore/QuartzCore.h" 11 | 12 | #define DEGREES_TO_RADIANS(d) (d * M_PI / 180) 13 | 14 | @implementation UIView (Layer) 15 | 16 | 17 | + (UIView *)reflectImage:(UIImage *)image withFrame:(CGRect)frame opacity:(CGFloat)opacity atView:(UIView *)view 18 | { 19 | // Image Layer 20 | CALayer *imageLayer = [CALayer layer]; 21 | imageLayer.contents = (id)image.CGImage; 22 | imageLayer.frame = frame; 23 | // imageLayer.borderColor = [UIColor darkGrayColor].CGColor; 24 | // imageLayer.borderWidth = 6.0; 25 | [view.layer addSublayer:imageLayer]; 26 | 27 | // Reflection Layer 28 | CALayer *reflectionLayer = [CALayer layer]; 29 | reflectionLayer.contents = imageLayer.contents; 30 | reflectionLayer.frame = CGRectMake(imageLayer.frame.origin.x, imageLayer.frame.origin.y + imageLayer.frame.size.height, imageLayer.frame.size.width, imageLayer.frame.size.height); 31 | // reflectionLayer.borderColor = imageLayer.borderColor; 32 | // reflectionLayer.borderWidth = imageLayer.borderWidth; 33 | reflectionLayer.opacity = opacity; 34 | // Transform X by 180 degrees 35 | [reflectionLayer setValue:[NSNumber numberWithFloat:DEGREES_TO_RADIANS(180)] forKeyPath:@"transform.rotation.x"]; 36 | 37 | // Gradient Layer - Use as mask 38 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; 39 | gradientLayer.bounds = reflectionLayer.bounds; 40 | gradientLayer.position = CGPointMake(reflectionLayer.bounds.size.width / 2, reflectionLayer.bounds.size.height * 0.5); 41 | gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor],(id)[[UIColor whiteColor] CGColor], nil]; 42 | gradientLayer.startPoint = CGPointMake(0.5, 0.6); 43 | gradientLayer.endPoint = CGPointMake(0.5, 1.0); 44 | 45 | // Add gradient layer as a mask 46 | reflectionLayer.mask = gradientLayer; 47 | [view.layer addSublayer:reflectionLayer]; 48 | 49 | return view; 50 | } 51 | 52 | 53 | - (void)startRotationAnimatingWithDuration:(CGFloat)duration 54 | { 55 | CABasicAnimation *animation = [ CABasicAnimation animationWithKeyPath: @"transform" ]; 56 | animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; 57 | 58 | //围绕Z轴旋转,垂直与屏幕 59 | animation.toValue = [ NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 0.0, 1.0) ]; 60 | animation.duration = duration; 61 | //旋转效果累计,先转180度,接着再旋转180度,从而实现360旋转 62 | animation.cumulative = YES; 63 | animation.removedOnCompletion = NO; 64 | animation.repeatCount = HUGE_VALL; 65 | 66 | [self.layer setShouldRasterize:YES];//抗锯齿 67 | [self.layer setRasterizationScale:[[UIScreen mainScreen] scale]]; 68 | [self.layer addAnimation:animation forKey:nil]; 69 | 70 | //如果暂停了,则恢复动画运行 71 | if (self.layer.speed == 0.0) 72 | { 73 | [self resumeAnimating]; 74 | } 75 | } 76 | 77 | - (void)stopRotationAnimating 78 | { 79 | [self.layer removeAllAnimations]; 80 | } 81 | 82 | - (void)pauseAnimating 83 | { 84 | CFTimeInterval pausedTime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil]; 85 | self.layer.speed = 0.0; 86 | self.layer.timeOffset = pausedTime; 87 | } 88 | 89 | - (void)resumeAnimating 90 | { 91 | CFTimeInterval pausedTime = [self.layer timeOffset]; 92 | self.layer.speed = 1.0; 93 | self.layer.timeOffset = 0.0; 94 | self.layer.beginTime = 0.0; 95 | CFTimeInterval timeSincePause = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; 96 | self.layer.beginTime = timeSincePause; 97 | } 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /TWApp/Lib/FMDB/FMDatabaseAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabaseAdditions.h 3 | // fmkit 4 | // 5 | // Created by August Mueller on 10/30/05. 6 | // Copyright 2005 Flying Meat Inc.. All rights reserved. 7 | // 8 | 9 | #import 10 | @interface FMDatabase (FMDatabaseAdditions) 11 | 12 | 13 | - (int)intForQuery:(NSString*)objs, ...; 14 | - (long)longForQuery:(NSString*)objs, ...; 15 | - (BOOL)boolForQuery:(NSString*)objs, ...; 16 | - (double)doubleForQuery:(NSString*)objs, ...; 17 | - (NSString*)stringForQuery:(NSString*)objs, ...; 18 | - (NSData*)dataForQuery:(NSString*)objs, ...; 19 | - (NSDate*)dateForQuery:(NSString*)objs, ...; 20 | 21 | // Notice that there's no dataNoCopyForQuery:. 22 | // That would be a bad idea, because we close out the result set, and then what 23 | // happens to the data that we just didn't copy? Who knows, not I. 24 | 25 | 26 | - (BOOL)tableExists:(NSString*)tableName; 27 | - (FMResultSet*)getSchema; 28 | - (FMResultSet*)getTableSchema:(NSString*)tableName; 29 | 30 | - (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName; 31 | 32 | - (BOOL)validateSQL:(NSString*)sql error:(NSError**)error; 33 | 34 | // deprecated - use columnExists:inTableWithName: instead. 35 | - (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated)); 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /TWApp/Lib/FMDB/FMDatabasePool.h: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabasePool.h 3 | // fmdb 4 | // 5 | // Created by August Mueller on 6/22/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "sqlite3.h" 11 | 12 | /* 13 | 14 | ***README OR SUFFER*** 15 | Before using FMDatabasePool, please consider using FMDatabaseQueue instead. 16 | 17 | If you really really really know what you're doing and FMDatabasePool is what 18 | you really really need (ie, you're using a read only database), OK you can use 19 | it. But just be careful not to deadlock! 20 | 21 | For an example on deadlocking, search for: 22 | ONLY_USE_THE_POOL_IF_YOU_ARE_DOING_READS_OTHERWISE_YOULL_DEADLOCK_USE_FMDATABASEQUEUE_INSTEAD 23 | in the main.m file. 24 | 25 | */ 26 | 27 | 28 | 29 | @class FMDatabase; 30 | 31 | @interface FMDatabasePool : NSObject { 32 | NSString *_path; 33 | 34 | dispatch_queue_t _lockQueue; 35 | 36 | NSMutableArray *_databaseInPool; 37 | NSMutableArray *_databaseOutPool; 38 | 39 | __unsafe_unretained id _delegate; 40 | 41 | NSUInteger _maximumNumberOfDatabasesToCreate; 42 | } 43 | 44 | @property (atomic, retain) NSString *path; 45 | @property (atomic, assign) id delegate; 46 | @property (atomic, assign) NSUInteger maximumNumberOfDatabasesToCreate; 47 | 48 | + (id)databasePoolWithPath:(NSString*)aPath; 49 | - (id)initWithPath:(NSString*)aPath; 50 | 51 | - (NSUInteger)countOfCheckedInDatabases; 52 | - (NSUInteger)countOfCheckedOutDatabases; 53 | - (NSUInteger)countOfOpenDatabases; 54 | - (void)releaseAllDatabases; 55 | 56 | - (void)inDatabase:(void (^)(FMDatabase *db))block; 57 | 58 | - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 59 | - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 60 | 61 | #if SQLITE_VERSION_NUMBER >= 3007000 62 | // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock. 63 | // If you need to nest, use FMDatabase's startSavePointWithName:error: instead. 64 | - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block; 65 | #endif 66 | 67 | @end 68 | 69 | 70 | @interface NSObject (FMDatabasePoolDelegate) 71 | 72 | - (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database; 73 | 74 | @end 75 | 76 | -------------------------------------------------------------------------------- /TWApp/Lib/FMDB/FMDatabaseQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabaseQueue.h 3 | // fmdb 4 | // 5 | // Created by August Mueller on 6/22/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "sqlite3.h" 11 | 12 | @class FMDatabase; 13 | 14 | @interface FMDatabaseQueue : NSObject { 15 | NSString *_path; 16 | dispatch_queue_t _queue; 17 | FMDatabase *_db; 18 | } 19 | 20 | @property (atomic, retain) NSString *path; 21 | 22 | + (id)databaseQueueWithPath:(NSString*)aPath; 23 | - (id)initWithPath:(NSString*)aPath; 24 | - (void)close; 25 | 26 | - (void)inDatabase:(void (^)(FMDatabase *db))block; 27 | 28 | - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 29 | - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 30 | 31 | #if SQLITE_VERSION_NUMBER >= 3007000 32 | // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock. 33 | // If you need to nest, use FMDatabase's startSavePointWithName:error: instead. 34 | - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block; 35 | #endif 36 | 37 | @end 38 | 39 | -------------------------------------------------------------------------------- /TWApp/Lib/FMDB/FMResultSet.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "sqlite3.h" 3 | 4 | #ifndef __has_feature // Optional. 5 | #define __has_feature(x) 0 // Compatibility with non-clang compilers. 6 | #endif 7 | 8 | #ifndef NS_RETURNS_NOT_RETAINED 9 | #if __has_feature(attribute_ns_returns_not_retained) 10 | #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained)) 11 | #else 12 | #define NS_RETURNS_NOT_RETAINED 13 | #endif 14 | #endif 15 | 16 | @class FMDatabase; 17 | @class FMStatement; 18 | 19 | @interface FMResultSet : NSObject { 20 | FMDatabase *_parentDB; 21 | FMStatement *_statement; 22 | 23 | NSString *_query; 24 | NSMutableDictionary *_columnNameToIndexMap; 25 | } 26 | 27 | @property (atomic, retain) NSString *query; 28 | @property (readonly) NSMutableDictionary *columnNameToIndexMap; 29 | @property (atomic, retain) FMStatement *statement; 30 | 31 | + (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB; 32 | 33 | - (void)close; 34 | 35 | - (void)setParentDB:(FMDatabase *)newDb; 36 | 37 | - (BOOL)next; 38 | - (BOOL)hasAnotherRow; 39 | 40 | - (int)columnCount; 41 | 42 | - (int)columnIndexForName:(NSString*)columnName; 43 | - (NSString*)columnNameForIndex:(int)columnIdx; 44 | 45 | - (int)intForColumn:(NSString*)columnName; 46 | - (int)intForColumnIndex:(int)columnIdx; 47 | 48 | - (long)longForColumn:(NSString*)columnName; 49 | - (long)longForColumnIndex:(int)columnIdx; 50 | 51 | - (long long int)longLongIntForColumn:(NSString*)columnName; 52 | - (long long int)longLongIntForColumnIndex:(int)columnIdx; 53 | 54 | - (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName; 55 | - (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx; 56 | 57 | - (BOOL)boolForColumn:(NSString*)columnName; 58 | - (BOOL)boolForColumnIndex:(int)columnIdx; 59 | 60 | - (double)doubleForColumn:(NSString*)columnName; 61 | - (double)doubleForColumnIndex:(int)columnIdx; 62 | 63 | - (NSString*)stringForColumn:(NSString*)columnName; 64 | - (NSString*)stringForColumnIndex:(int)columnIdx; 65 | 66 | - (NSDate*)dateForColumn:(NSString*)columnName; 67 | - (NSDate*)dateForColumnIndex:(int)columnIdx; 68 | 69 | - (NSData*)dataForColumn:(NSString*)columnName; 70 | - (NSData*)dataForColumnIndex:(int)columnIdx; 71 | 72 | - (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx; 73 | - (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName; 74 | 75 | // returns one of NSNumber, NSString, NSData, or NSNull 76 | - (id)objectForColumnName:(NSString*)columnName; 77 | - (id)objectForColumnIndex:(int)columnIdx; 78 | 79 | - (id)objectForKeyedSubscript:(NSString *)columnName; 80 | - (id)objectAtIndexedSubscript:(int)columnIdx; 81 | 82 | /* 83 | If you are going to use this data after you iterate over the next row, or after you close the 84 | result set, make sure to make a copy of the data first (or just use dataForColumn:/dataForColumnIndex:) 85 | If you don't, you're going to be in a world of hurt when you try and use the data. 86 | */ 87 | - (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED; 88 | - (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED; 89 | 90 | - (BOOL)columnIndexIsNull:(int)columnIdx; 91 | - (BOOL)columnIsNull:(NSString*)columnName; 92 | 93 | 94 | /* Returns a dictionary of the row results mapped to case sensitive keys of the column names. */ 95 | - (NSDictionary*)resultDictionary; 96 | 97 | /* Please use resultDictionary instead. Also, beware that resultDictionary is case sensitive! */ 98 | - (NSDictionary*)resultDict __attribute__ ((deprecated)); 99 | 100 | - (void)kvcMagic:(id)object; 101 | 102 | 103 | @end 104 | 105 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSData+MKBase64.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+MKNKBase64.h 3 | // base64 4 | // 5 | // Created by Matt Gallagher on 2009/06/03. 6 | // Copyright 2009 Matt Gallagher. All rights reserved. 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. Permission is granted to anyone to 11 | // use this software for any purpose, including commercial applications, and to 12 | // alter it and redistribute it freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would be 17 | // appreciated but is not required. 18 | // 2. Altered source versions must be plainly marked as such, and must not be 19 | // misrepresented as being the original software. 20 | // 3. This notice may not be removed or altered from any source 21 | // distribution. 22 | // 23 | 24 | #import 25 | 26 | void *mk_NewBase64Decode( 27 | const char *inputBuffer, 28 | size_t length, 29 | size_t *outputLength); 30 | 31 | char *mk_NewBase64Encode( 32 | const void *inputBuffer, 33 | size_t length, 34 | bool separateLines, 35 | size_t *outputLength); 36 | 37 | @interface NSData (MKNKBase64) 38 | 39 | + (NSData *)dataFromBase64String:(NSString *)aString; 40 | - (NSString *)base64EncodedString; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSDate+RFC1123.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+RFC1123.h 3 | // MKNetworkKit 4 | // 5 | // Created by Marcus Rohrmoser 6 | // http://blog.mro.name/2009/08/nsdateformatter-http-header/ 7 | // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 8 | 9 | // No obvious license attached 10 | 11 | @interface NSDate (RFC1123) 12 | /** 13 | Convert a RFC1123 'Full-Date' string 14 | (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1) 15 | into NSDate. 16 | */ 17 | +(NSDate*)dateFromRFC1123:(NSString*)value_; 18 | 19 | /** 20 | Convert NSDate into a RFC1123 'Full-Date' string 21 | (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1). 22 | */ 23 | -(NSString*)rfc1123String; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSDate+RFC1123.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+RFC1123.m 3 | // MKNetworkKit 4 | // 5 | // Originally created by Marcus Rohrmoser 6 | // http://blog.mro.name/2009/08/nsdateformatter-http-header/ 7 | // Updated with strptime methods by Bo98 8 | // 9 | // No obvious license attached 10 | 11 | #import "NSDate+RFC1123.h" 12 | #import 13 | #import 14 | 15 | @implementation NSDate (RFC1123) 16 | 17 | +(NSDate*)dateFromRFC1123:(NSString*)value_ 18 | { 19 | if(value_ == nil) 20 | return nil; 21 | 22 | const char *str = [value_ UTF8String]; 23 | const char *fmt; 24 | NSDate *retDate; 25 | char *ret; 26 | 27 | fmt = "%a, %d %b %Y %H:%M:%S %Z"; 28 | struct tm rfc1123timeinfo; 29 | memset(&rfc1123timeinfo, 0, sizeof(rfc1123timeinfo)); 30 | ret = strptime_l(str, fmt, &rfc1123timeinfo, NULL); 31 | if (ret) { 32 | time_t rfc1123time = mktime(&rfc1123timeinfo); 33 | retDate = [NSDate dateWithTimeIntervalSince1970:rfc1123time]; 34 | if (retDate != nil) 35 | return retDate; 36 | } 37 | 38 | 39 | fmt = "%A, %d-%b-%y %H:%M:%S %Z"; 40 | struct tm rfc850timeinfo; 41 | memset(&rfc850timeinfo, 0, sizeof(rfc850timeinfo)); 42 | ret = strptime_l(str, fmt, &rfc850timeinfo, NULL); 43 | if (ret) { 44 | time_t rfc850time = mktime(&rfc850timeinfo); 45 | retDate = [NSDate dateWithTimeIntervalSince1970:rfc850time]; 46 | if (retDate != nil) 47 | return retDate; 48 | } 49 | 50 | fmt = "%a %b %e %H:%M:%S %Y"; 51 | struct tm asctimeinfo; 52 | memset(&asctimeinfo, 0, sizeof(asctimeinfo)); 53 | ret = strptime_l(str, fmt, &asctimeinfo, NULL); 54 | if (ret) { 55 | time_t asctime = mktime(&asctimeinfo); 56 | return [NSDate dateWithTimeIntervalSince1970:asctime]; 57 | } 58 | 59 | return nil; 60 | } 61 | 62 | -(NSString*)rfc1123String 63 | { 64 | time_t date = (time_t)[self timeIntervalSince1970]; 65 | struct tm timeinfo; 66 | gmtime_r(&date, &timeinfo); 67 | char buffer[32]; 68 | size_t ret = strftime_l(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S GMT", &timeinfo, NULL); 69 | if (ret) { 70 | return @(buffer); 71 | } else { 72 | return nil; 73 | } 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+RequestEncoding.h 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | @interface NSDictionary (RequestEncoding) 27 | 28 | -(NSString*) urlEncodedKeyValueString; 29 | -(NSString*) jsonEncodedKeyValueString; 30 | -(NSString*) plistEncodedKeyValueString; 31 | @end 32 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+RequestEncoding.m 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import "MKNetworkKit.h" 27 | 28 | @implementation NSDictionary (RequestEncoding) 29 | 30 | -(NSString*) urlEncodedKeyValueString { 31 | 32 | NSMutableString *string = [NSMutableString string]; 33 | for (NSString *key in self) { 34 | 35 | NSObject *value = [self valueForKey:key]; 36 | if([value isKindOfClass:[NSString class]]) 37 | [string appendFormat:@"%@=%@&", [key mk_urlEncodedString], [((NSString*)value) mk_urlEncodedString]]; 38 | else 39 | [string appendFormat:@"%@=%@&", [key mk_urlEncodedString], value]; 40 | } 41 | 42 | if([string length] > 0) 43 | [string deleteCharactersInRange:NSMakeRange([string length] - 1, 1)]; 44 | 45 | return string; 46 | } 47 | 48 | 49 | -(NSString*) jsonEncodedKeyValueString { 50 | 51 | NSError *error = nil; 52 | NSData *data = [NSJSONSerialization dataWithJSONObject:self 53 | options:0 // non-pretty printing 54 | error:&error]; 55 | if(error) 56 | DLog(@"JSON Parsing Error: %@", error); 57 | 58 | return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 59 | } 60 | 61 | 62 | -(NSString*) plistEncodedKeyValueString { 63 | 64 | NSError *error = nil; 65 | NSData *data = [NSPropertyListSerialization dataWithPropertyList:self 66 | format:NSPropertyListXMLFormat_v1_0 67 | options:0 error:&error]; 68 | if(error) 69 | DLog(@"JSON Parsing Error: %@", error); 70 | 71 | return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MKNetworkKitAdditions.h 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | @interface NSString (MKNetworkKitAdditions) 27 | 28 | - (NSString *) md5; 29 | + (NSString*) uniqueString; 30 | - (NSString*) mk_urlEncodedString; 31 | - (NSString*) urlDecodedString; 32 | @end 33 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MKNetworkKitAdditions.m 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import "NSString+MKNetworkKitAdditions.h" 27 | #import 28 | 29 | @implementation NSString (MKNetworkKitAdditions) 30 | 31 | - (NSString *) md5 32 | { 33 | const char *cStr = [self UTF8String]; 34 | unsigned char result[16]; 35 | CC_MD5( cStr, (unsigned int) strlen(cStr), result); 36 | return [NSString stringWithFormat: 37 | @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 38 | result[0], result[1], result[2], result[3], 39 | result[4], result[5], result[6], result[7], 40 | result[8], result[9], result[10], result[11], 41 | result[12], result[13], result[14], result[15] 42 | ]; 43 | } 44 | 45 | + (NSString*) uniqueString 46 | { 47 | CFUUIDRef uuidObj = CFUUIDCreate(nil); 48 | NSString *uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuidObj); 49 | CFRelease(uuidObj); 50 | return uuidString; 51 | } 52 | 53 | - (NSString*) mk_urlEncodedString { // mk_ prefix prevents a clash with a private api 54 | 55 | CFStringRef encodedCFString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 56 | (__bridge CFStringRef) self, 57 | nil, 58 | CFSTR("?!@#$^&%*+,:;='\"`<>()[]{}/\\| "), 59 | kCFStringEncodingUTF8); 60 | 61 | NSString *encodedString = [[NSString alloc] initWithString:(__bridge_transfer NSString*) encodedCFString]; 62 | 63 | if(!encodedString) 64 | encodedString = @""; 65 | 66 | return encodedString; 67 | } 68 | 69 | - (NSString*) urlDecodedString { 70 | 71 | CFStringRef decodedCFString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, 72 | (__bridge CFStringRef) self, 73 | CFSTR(""), 74 | kCFStringEncodingUTF8); 75 | 76 | // We need to replace "+" with " " because the CF method above doesn't do it 77 | NSString *decodedString = [[NSString alloc] initWithString:(__bridge_transfer NSString*) decodedCFString]; 78 | return (!decodedString) ? @"" : [decodedString stringByReplacingOccurrencesOfString:@"+" withString:@" "]; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+MKNetworkKitAdditions.h 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | #if TARGET_OS_IPHONE 26 | #import 27 | 28 | @interface UIAlertView (MKNetworkKitAdditions) 29 | +(UIAlertView*) showWithError:(NSError*) networkError; 30 | @end 31 | #endif 32 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+MKNetworkKitAdditions.m 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | #if TARGET_OS_IPHONE 26 | #import "UIAlertView+MKNetworkKitAdditions.h" 27 | 28 | @implementation UIAlertView (MKNetworkKitAdditions) 29 | 30 | +(UIAlertView*) showWithError:(NSError*) networkError { 31 | 32 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[networkError localizedDescription] 33 | message:[networkError localizedRecoverySuggestion] 34 | delegate:nil 35 | cancelButtonTitle:NSLocalizedString(@"Dismiss", @"") 36 | otherButtonTitles:nil]; 37 | [alert show]; 38 | return alert; 39 | } 40 | @end 41 | #endif 42 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+MKNetworkKitAdditions.h 3 | // MKNetworkKit-iOS 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import 27 | 28 | extern const float kFromCacheAnimationDuration; 29 | extern const float kFreshLoadAnimationDuration; 30 | 31 | @class MKNetworkEngine; 32 | @class MKNetworkOperation; 33 | 34 | @interface UIImageView (MKNetworkKitAdditions) 35 | +(void) setDefaultEngine:(MKNetworkEngine*) engine; 36 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url; 37 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image; 38 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image animation:(BOOL) yesOrNo; 39 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; 40 | @end 41 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+MKNetworkKitAdditions.m 3 | // MKNetworkKitDemo 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import "UIImageView+MKNetworkKitAdditions.h" 27 | 28 | #import "MKNetworkEngine.h" 29 | 30 | #import 31 | 32 | static MKNetworkEngine *DefaultEngine; 33 | static char imageFetchOperationKey; 34 | 35 | const float kFromCacheAnimationDuration = 0.1f; 36 | const float kFreshLoadAnimationDuration = 0.35f; 37 | 38 | @interface UIImageView (/*Private Methods*/) 39 | @property (strong, nonatomic) MKNetworkOperation *imageFetchOperation; 40 | @end 41 | 42 | @implementation UIImageView (MKNetworkKitAdditions) 43 | 44 | -(MKNetworkOperation*) imageFetchOperation { 45 | 46 | return (MKNetworkOperation*) objc_getAssociatedObject(self, &imageFetchOperationKey); 47 | } 48 | 49 | -(void) setImageFetchOperation:(MKNetworkOperation *)imageFetchOperation { 50 | 51 | objc_setAssociatedObject(self, &imageFetchOperationKey, imageFetchOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 52 | } 53 | 54 | +(void) setDefaultEngine:(MKNetworkEngine*) engine { 55 | 56 | DefaultEngine = engine; 57 | } 58 | 59 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url { 60 | 61 | return [self setImageFromURL:url placeHolderImage:nil]; 62 | } 63 | 64 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image { 65 | 66 | return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:YES]; 67 | } 68 | 69 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image animation:(BOOL) yesOrNo { 70 | 71 | return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:yesOrNo]; 72 | } 73 | 74 | -(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo { 75 | 76 | if(image) self.image = image; 77 | [self.imageFetchOperation cancel]; 78 | if(!imageCacheEngine) imageCacheEngine = DefaultEngine; 79 | 80 | if(imageCacheEngine) { 81 | self.imageFetchOperation = [imageCacheEngine imageAtURL:url 82 | size:self.frame.size 83 | completionHandler:^(UIImage *fetchedImage, NSURL *url, BOOL isInCache) { 84 | 85 | [UIView transitionWithView:self.superview 86 | duration:isInCache?kFromCacheAnimationDuration:kFreshLoadAnimationDuration 87 | options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction 88 | animations:^{ 89 | self.image = fetchedImage; 90 | } completion:nil]; 91 | 92 | } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { 93 | 94 | DLog(@"%@", error); 95 | }]; 96 | } else { 97 | 98 | DLog(@"No default engine found and imageCacheEngine parameter is null") 99 | } 100 | 101 | return self.imageFetchOperation; 102 | } 103 | @end 104 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/MKNetworkKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // MKNetworkKit.h 3 | // MKNetworkKit 4 | // 5 | // Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. 6 | // Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd 7 | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #ifndef MKNetworkKit_MKNetworkKit_h 27 | #define MKNetworkKit_MKNetworkKit_h 28 | 29 | #ifndef __IPHONE_4_0 30 | #error "MKNetworkKit uses features only available in iOS SDK 4.0 and later." 31 | #endif 32 | 33 | #if TARGET_OS_IPHONE 34 | #import 35 | #import 36 | #elif TARGET_OS_MAC 37 | #import 38 | #import 39 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 40 | #define DO_GCD_RETAIN_RELEASE 0 41 | #else 42 | #define DO_GCD_RETAIN_RELEASE 1 43 | #endif 44 | #endif 45 | 46 | #ifdef DEBUG 47 | #ifndef DLog 48 | # define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);} 49 | #endif 50 | #ifndef ELog 51 | # define ELog(err) {if(err) DLog(@"%@", err)} 52 | #endif 53 | #else 54 | #ifndef DLog 55 | # define DLog(...) 56 | #endif 57 | #ifndef ELog 58 | # define ELog(err) 59 | #endif 60 | #endif 61 | 62 | // ALog always displays output regardless of the DEBUG setting 63 | #ifndef ALog 64 | #define ALog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}; 65 | #endif 66 | 67 | #import "Categories/NSString+MKNetworkKitAdditions.h" 68 | #import "Categories/NSDictionary+RequestEncoding.h" 69 | #import "Categories/NSDate+RFC1123.h" 70 | #import "Categories/NSData+MKBase64.h" 71 | #import "Categories/UIImageView+MKNetworkKitAdditions.h" 72 | #if TARGET_OS_IPHONE 73 | #import "Categories/UIAlertView+MKNetworkKitAdditions.h" 74 | #elif TARGET_OS_MAC 75 | #import "Categories/NSAlert+MKNetworkKitAdditions.h" 76 | #endif 77 | 78 | #import "Reachability/Reachability.h" 79 | 80 | #import "MKNetworkOperation.h" 81 | #import "MKNetworkEngine.h" 82 | 83 | #define kMKNetworkEngineOperationCountChanged @"kMKNetworkEngineOperationCountChanged" 84 | #define MKNETWORKCACHE_DEFAULT_COST 10 85 | #define MKNETWORKCACHE_DEFAULT_DIRECTORY @"MKNetworkKitCache" 86 | #define kMKNetworkKitDefaultCacheDuration 60 // 1 minute 87 | #define kMKNetworkKitDefaultImageHeadRequestDuration 3600*24*1 // 1 day (HEAD requests with eTag are sent only after expiry of this. Not that these are not RFC compliant, but needed for performance tuning) 88 | #define kMKNetworkKitDefaultImageCacheDuration 3600*24*7 // 1 day 89 | 90 | // if your server takes longer than 30 seconds to provide real data, 91 | // you should hire a better server developer. 92 | // on iOS (or any mobile device), 30 seconds is already considered high. 93 | 94 | #define kMKNetworkKitRequestTimeOutInSeconds 30 95 | #endif 96 | 97 | 98 | -------------------------------------------------------------------------------- /TWApp/Lib/MKNetworkKit/Reachability/Reachability.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, 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 | 28 | #import 29 | 30 | #import 31 | #import 32 | #import 33 | #import 34 | #import 35 | #import 36 | 37 | /** 38 | * Does ARC support support GCD objects? 39 | * It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ 40 | **/ 41 | #if TARGET_OS_IPHONE 42 | 43 | // Compiling for iOS 44 | 45 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later 46 | #define NEEDS_DISPATCH_RETAIN_RELEASE 0 47 | #else // iOS 5.X or earlier 48 | #define NEEDS_DISPATCH_RETAIN_RELEASE 1 49 | #endif 50 | 51 | #else 52 | 53 | // Compiling for Mac OS X 54 | 55 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later 56 | #define NEEDS_DISPATCH_RETAIN_RELEASE 0 57 | #else 58 | #define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier 59 | #endif 60 | 61 | #endif 62 | 63 | 64 | extern NSString *const kReachabilityChangedNotification; 65 | 66 | typedef enum 67 | { 68 | // Apple NetworkStatus Compatible Names. 69 | NotReachable = 0, 70 | ReachableViaWiFi = 2, 71 | ReachableViaWWAN = 1 72 | } NetworkStatus; 73 | 74 | @class Reachability; 75 | 76 | typedef void (^NetworkReachable)(Reachability * reachability); 77 | typedef void (^NetworkUnreachable)(Reachability * reachability); 78 | 79 | @interface Reachability : NSObject 80 | 81 | @property (nonatomic, copy) NetworkReachable reachableBlock; 82 | @property (nonatomic, copy) NetworkUnreachable unreachableBlock; 83 | 84 | 85 | @property (nonatomic, assign) BOOL reachableOnWWAN; 86 | 87 | +(Reachability*)reachabilityWithHostname:(NSString*)hostname; 88 | +(Reachability*)reachabilityForInternetConnection; 89 | +(Reachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; 90 | +(Reachability*)reachabilityForLocalWiFi; 91 | 92 | -(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; 93 | 94 | -(BOOL)startNotifier; 95 | -(void)stopNotifier; 96 | 97 | -(BOOL)isReachable; 98 | -(BOOL)isReachableViaWWAN; 99 | -(BOOL)isReachableViaWiFi; 100 | 101 | // WWAN may be available, but not active until a connection has been established. 102 | // WiFi may require a connection for VPN on Demand. 103 | -(BOOL)isConnectionRequired; // Identical DDG variant. 104 | -(BOOL)connectionRequired; // Apple's routine. 105 | // Dynamic, on demand connection? 106 | -(BOOL)isConnectionOnDemand; 107 | // Is user intervention required? 108 | -(BOOL)isInterventionRequired; 109 | 110 | -(NetworkStatus)currentReachabilityStatus; 111 | -(SCNetworkReachabilityFlags)reachabilityFlags; 112 | -(NSString*)currentReachabilityString; 113 | -(NSString*)currentReachabilityFlags; 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/AttriButedLabel/AttributedLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // AttributedLabel.h 3 | // AttributedStringTest 4 | // 5 | // Created by sun huayu on 13-2-19. 6 | // Copyright (c) 2013年 sun huayu. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AttributedLabel : UILabel 13 | 14 | //以下三个属性重设text值后需要重新设置 15 | 16 | // 设置某段字的颜色 17 | - (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length; 18 | 19 | // 设置某段字的字体 20 | - (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length; 21 | 22 | // 设置某段字的风格 23 | - (void)setStyle:(CTUnderlineStyle)style fromIndex:(NSInteger)location length:(NSInteger)length; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/AttriButedLabel/AttributedLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // AttributedLabel.m 3 | // AttributedStringTest 4 | // 5 | // Created by sun huayu on 13-2-19. 6 | // Copyright (c) 2013年 sun huayu. All rights reserved. 7 | // 8 | 9 | #import "AttributedLabel.h" 10 | #import "QuartzCore/QuartzCore.h" 11 | 12 | @interface AttributedLabel() 13 | @property (nonatomic, strong) NSMutableAttributedString *attString; 14 | @property (nonatomic, strong) CATextLayer *textLayer; 15 | 16 | @end 17 | 18 | @implementation AttributedLabel 19 | 20 | - (id)initWithFrame:(CGRect)frame 21 | { 22 | self = [super initWithFrame:frame]; 23 | if (self) 24 | { 25 | [self defaultInit]; 26 | 27 | [self setTextColor:[UIColor darkTextColor]]; 28 | [self setFont:[UIFont systemFontOfSize:15]]; 29 | } 30 | return self; 31 | } 32 | 33 | - (id)initWithCoder:(NSCoder *)aDecoder 34 | { 35 | self = [super initWithCoder:aDecoder]; 36 | if (self) 37 | { 38 | [self defaultInit]; 39 | 40 | [self setText:self.text]; 41 | [self setTextColor:self.textColor]; 42 | [self setFont:self.font]; 43 | } 44 | 45 | return self; 46 | } 47 | 48 | - (void)defaultInit 49 | { 50 | self.textLayer = [CATextLayer layer]; 51 | self.textLayer.contentsScale = [[UIScreen mainScreen] scale]; 52 | self.textLayer.frame = self.bounds; 53 | [self.layer addSublayer:self.textLayer]; 54 | } 55 | 56 | - (void)setFrame:(CGRect)frame 57 | { 58 | [super setFrame:frame]; 59 | [self.textLayer setFrame:self.bounds]; 60 | } 61 | 62 | - (void)drawRect:(CGRect)rect 63 | { 64 | self.textLayer.string = self.attString; 65 | } 66 | 67 | - (void)setText:(NSString *)text 68 | { 69 | [super setText:text]; 70 | 71 | if (text == nil) 72 | { 73 | self.attString = nil; 74 | } 75 | else 76 | { 77 | self.attString = [[NSMutableAttributedString alloc] initWithString:text]; 78 | [self setFont:self.font]; 79 | [self setTextColor:self.textColor]; 80 | } 81 | } 82 | 83 | - (void)setTextColor:(UIColor *)textColor 84 | { 85 | [super setTextColor:textColor]; 86 | 87 | [self setColor:textColor fromIndex:0 length:self.text.length]; 88 | } 89 | 90 | - (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length 91 | { 92 | if (location < 0||location>self.text.length-1||length+location>self.text.length) 93 | { 94 | return; 95 | } 96 | [self.attString addAttribute:(NSString *)kCTForegroundColorAttributeName 97 | value:(id)color.CGColor 98 | range:NSMakeRange(location, length)]; 99 | } 100 | 101 | - (void)setFont:(UIFont *)font 102 | { 103 | [super setFont:font]; 104 | 105 | [self setFont:font fromIndex:0 length:self.text.length]; 106 | } 107 | 108 | - (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length 109 | { 110 | if (location < 0||location>self.text.length-1||length+location>self.text.length) 111 | { 112 | return; 113 | } 114 | [self.attString addAttribute:(NSString *)kCTFontAttributeName 115 | value:(id)CFBridgingRelease(CTFontCreateWithName((CFStringRef)CFBridgingRetain(font.fontName), 116 | font.pointSize, 117 | NULL)) 118 | range:NSMakeRange(location, length)]; 119 | } 120 | 121 | - (void)setStyle:(CTUnderlineStyle)style fromIndex:(NSInteger)location length:(NSInteger)length 122 | { 123 | if (location < 0 || location>self.text.length - 1 || length + location > self.text.length) 124 | { 125 | return; 126 | } 127 | [self.attString addAttribute:(NSString *)kCTUnderlineStyleAttributeName 128 | value:(id)[NSNumber numberWithInt:style] 129 | range:NSMakeRange(location, length)]; 130 | } 131 | 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/BBCyclingLabel/BBCyclingLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2013 BiasedBit 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | // 18 | // Created by Bruno de Carvalho -- @biasedbit / http://biasedbit.com 19 | // Copyright (c) 2013 BiasedBit. All rights reserved. 20 | // 21 | 22 | #pragma mark - Enums 23 | 24 | typedef enum 25 | { 26 | // User must provide pre-transition and transition blocks 27 | BBCyclingLabelTransitionEffectCustom = 0, 28 | 29 | BBCyclingLabelTransitionEffectFadeIn = 1 << 0, 30 | BBCyclingLabelTransitionEffectFadeOut = 1 << 1, 31 | BBCyclingLabelTransitionEffectCrossFade = BBCyclingLabelTransitionEffectFadeIn | 32 | BBCyclingLabelTransitionEffectFadeOut, 33 | 34 | BBCyclingLabelTransitionEffectZoomIn = 1 << 2, 35 | BBCyclingLabelTransitionEffectZoomOut = 1 << 3, 36 | 37 | BBCyclingLabelTransitionEffectScaleFadeOut = BBCyclingLabelTransitionEffectFadeIn | 38 | BBCyclingLabelTransitionEffectFadeOut | 39 | BBCyclingLabelTransitionEffectZoomOut, 40 | BBCyclingLabelTransitionEffectScaleFadeIn = BBCyclingLabelTransitionEffectFadeIn | 41 | BBCyclingLabelTransitionEffectFadeOut | 42 | BBCyclingLabelTransitionEffectZoomIn, 43 | 44 | // These two move the entering label from above/below to center and exiting label up/down without cross-fade 45 | // It's a good idea to set the clipsToBounds property of the BBCyclingLabel to true and use this in a confined space 46 | BBCyclingLabelTransitionEffectScrollUp = 1 << 4, 47 | BBCyclingLabelTransitionEffectScrollDown = 1 << 5, 48 | 49 | BBCyclingLabelTransitionEffectDefault = BBCyclingLabelTransitionEffectCrossFade 50 | } BBCyclingLabelTransitionEffect; 51 | 52 | 53 | 54 | #pragma mark - Custom types 55 | 56 | typedef void(^BBCyclingLabelPreTransitionBlock)(UILabel* labelToEnter); 57 | typedef void(^BBCyclingLabelTransitionBlock)(UILabel* labelToExit, UILabel* labelToEnter); 58 | 59 | 60 | 61 | #pragma mark - 62 | 63 | @interface BBCyclingLabel : UIView 64 | 65 | 66 | #pragma mark Properties 67 | 68 | @property(assign, nonatomic) BBCyclingLabelTransitionEffect transitionEffect; 69 | @property(assign, nonatomic) NSTimeInterval transitionDuration; 70 | @property(copy, nonatomic) BBCyclingLabelPreTransitionBlock preTransitionBlock; 71 | @property(copy, nonatomic) BBCyclingLabelTransitionBlock transitionBlock; 72 | // Same properties as UILabel, these will be propagated to the underlying labels 73 | @property(copy, nonatomic) NSString* text; 74 | @property(strong, nonatomic) UIFont* font; 75 | @property(strong, nonatomic) UIColor* textColor; 76 | @property(strong, nonatomic) UIColor* shadowColor; 77 | @property(assign, nonatomic) CGSize shadowOffset; 78 | @property(assign, nonatomic) NSTextAlignment textAlignment; 79 | @property(assign, nonatomic) NSLineBreakMode lineBreakMode; 80 | @property(assign, nonatomic) NSInteger numberOfLines; 81 | @property(assign, nonatomic) BOOL adjustsFontSizeToFitWidth; 82 | @property(assign, nonatomic) CGFloat minimumFontSize; 83 | @property(assign, nonatomic) UIBaselineAdjustment baselineAdjustment; 84 | 85 | 86 | #pragma mark Creation 87 | 88 | - (id)initWithFrame:(CGRect)frame andTransitionType:(BBCyclingLabelTransitionEffect)transitionEffect; 89 | 90 | 91 | #pragma mark Interface 92 | 93 | /*! Sets the text for the next label and performs a transition between current and next label (if animated is YES) */ 94 | - (void)setText:(NSString*)text animated:(BOOL)animated; 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/CheckBoxView.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2011 Ahmet Ardal 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | // 19 | // SSCheckBoxView.h 20 | // SSCheckBoxView 21 | // 22 | // Created by Ahmet Ardal on 12/6/11. 23 | // Copyright 2011 SpinningSphere Labs. All rights reserved. 24 | // 25 | 26 | #import 27 | @class CheckBoxView; 28 | 29 | typedef enum CheckBoxViewStyle_ 30 | { 31 | kCheckBoxViewStyleBox = 0, 32 | kCheckBoxViewStyleDark, 33 | kCheckBoxViewStyleGlossy, 34 | kCheckBoxViewStyleGreen, 35 | kCheckBoxViewStyleMono, 36 | kCheckBoxViewStylesCount 37 | }CheckBoxViewStyle; 38 | 39 | void (^stateChangedBlock)(CheckBoxView *cbv); 40 | 41 | 42 | @interface CheckBoxView: UIView 43 | 44 | //按钮样式 45 | @property (assign, nonatomic, readonly) CheckBoxViewStyle style; 46 | 47 | //按钮状态 48 | @property (assign, nonatomic) BOOL checked; 49 | @property (assign, nonatomic) BOOL enabled; 50 | 51 | //右侧的文字、颜色、字体 52 | @property (copy, nonatomic) NSString *text; 53 | @property (strong, nonatomic) UIColor *textColor; 54 | @property (strong, nonatomic) UIFont *textFont; 55 | 56 | - (id)initWithFrame:(CGRect)frame style:(CheckBoxViewStyle)aStyle checked:(BOOL)aChecked; 57 | 58 | 59 | //blocks响应方法 60 | @property (nonatomic, copy) void (^stateChangedBlock)(CheckBoxView *cbv); 61 | 62 | //常规响应方法 63 | - (void)addStateChangedTarget:(id)target selector:(SEL)selector; 64 | 65 | @end 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_off.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_off@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_on.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_box_on@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_off.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_off@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_on.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_dark_on@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_off.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_off@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_on.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_glossy_on@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_off.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_off@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_on.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_green_on@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_off.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_off@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_on.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/CheckBoxView/Graphics/cb_mono_on@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/EDStarRating/EDStarRating.h: -------------------------------------------------------------------------------- 1 | // 2 | // EDStartRatingView. 3 | // 4 | // Created by Ernesto Garcia on 26/02/12. 5 | // Copyright (c) 2012 cocoawithchurros.com All rights reserved. 6 | // Distributed under MIT license 7 | 8 | 9 | 10 | 11 | // 12 | // ARC Helper 13 | // 14 | // Version 1.2.1 15 | // 16 | // Created by Nick Lockwood on 05/01/2012. 17 | // Copyright 2012 Charcoal Design 18 | // 19 | // Distributed under the permissive zlib license 20 | // Get the latest version from here: 21 | // 22 | // https://gist.github.com/1563325 23 | // 24 | 25 | #ifndef AH_RETAIN 26 | #if __has_feature(objc_arc) 27 | #define AH_RETAIN(x) (x) 28 | #define AH_RELEASE(x) 29 | #define AH_AUTORELEASE(x) (x) 30 | #define AH_SUPER_DEALLOC 31 | #else 32 | #define __AH_WEAK 33 | #define AH_WEAK assign 34 | #define AH_RETAIN(x) [(x) retain] 35 | #define AH_RELEASE(x) [(x) release] 36 | #define AH_AUTORELEASE(x) [(x) autorelease] 37 | #define AH_SUPER_DEALLOC [super dealloc] 38 | #endif 39 | #endif 40 | 41 | // Weak reference support 42 | 43 | #ifndef AH_WEAK 44 | #if defined __IPHONE_OS_VERSION_MIN_REQUIRED 45 | #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 46 | #define __AH_WEAK __weak 47 | #define AH_WEAK weak 48 | #else 49 | #define __AH_WEAK __unsafe_unretained 50 | #define AH_WEAK unsafe_unretained 51 | #endif 52 | #elif defined __MAC_OS_X_VERSION_MIN_REQUIRED 53 | #if __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6 54 | #define __AH_WEAK __weak 55 | #define AH_WEAK weak 56 | #else 57 | #define __AH_WEAK __unsafe_unretained 58 | #define AH_WEAK unsafe_unretained 59 | #endif 60 | #endif 61 | #endif 62 | 63 | // ARC Helper ends 64 | 65 | 66 | #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED 67 | #define EDSTAR_MACOSX 1 68 | #define EDSTAR_IOS 0 69 | #else 70 | #define EDSTAR_MACOSX 0 71 | #define EDSTAR_IOS 1 72 | #endif 73 | 74 | #if EDSTAR_MAC 75 | #import 76 | #endif 77 | 78 | 79 | enum { 80 | EDStarRatingDisplayFull=0, 81 | EDStarRatingDisplayHalf, 82 | EDStarRatingDisplayAccurate 83 | }; 84 | typedef NSUInteger EDStarRatingDisplayMode; 85 | typedef void(^EDStarRatingReturnBlock)(float rating); 86 | @protocol EDStarRatingProtocol; 87 | 88 | #if EDSTAR_MACOSX 89 | #define EDControl NSControl 90 | typedef NSColor EDColor; 91 | typedef NSImage EDImage; 92 | #else 93 | #define EDControl UIControl 94 | typedef UIColor EDColor; 95 | typedef UIImage EDImage; 96 | 97 | #endif 98 | 99 | @interface EDStarRating : EDControl 100 | 101 | #if EDSTAR_MACOSX 102 | @property (nonatomic,strong) EDColor *backgroundColor; 103 | #endif 104 | @property (nonatomic,strong) EDImage *backgroundImage; 105 | @property (nonatomic,strong) EDImage *starHighlightedImage; 106 | @property (nonatomic,strong) EDImage *starImage; 107 | @property (nonatomic) NSInteger maxRating; 108 | @property (nonatomic) float rating; 109 | @property (nonatomic) CGFloat horizontalMargin; 110 | @property (nonatomic) BOOL editable; 111 | @property (nonatomic) EDStarRatingDisplayMode displayMode; 112 | @property (nonatomic) float halfStarThreshold; 113 | 114 | @property (nonatomic,unsafe_unretained) id delegate; 115 | @property (nonatomic,copy) EDStarRatingReturnBlock returnBlock; 116 | @end 117 | 118 | 119 | @protocol EDStarRatingProtocol 120 | 121 | @optional 122 | -(void)starsSelectionChanged:(EDStarRating*)control rating:(float)rating; 123 | 124 | @end 125 | 126 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/EDStarRating/starRating.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/EDStarRating/starRating.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/EDStarRating/starRatinghighlighted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/EDStarRating/starRatinghighlighted.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/GlowLabel/RRSGlowLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // RRSGlowLabel.h 3 | // TextGlowDemo 4 | // 5 | // Created by Andrew on 28/04/2010. 6 | // Copyright 2010 Red Robot Studios. All rights reserved. 7 | // 8 | 9 | 10 | @interface RRSGlowLabel : UILabel 11 | { 12 | CGColorSpaceRef colorSpaceRef; 13 | CGColorRef glowColorRef; 14 | } 15 | 16 | @property (nonatomic, assign) CGSize glowOffset; 17 | @property (nonatomic, assign) CGFloat glowAmount; 18 | @property (nonatomic, strong) UIColor *glowColor; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/GlowLabel/RRSGlowLabel.m: -------------------------------------------------------------------------------- 1 | // 2 | // RRSGlowLabel.m 3 | // TextGlowDemo 4 | // 5 | // Created by Andrew on 28/04/2010. 6 | // Red Robot Studios 2010. 7 | // 8 | 9 | #import "RRSGlowLabel.h" 10 | 11 | @implementation RRSGlowLabel 12 | 13 | - (void)setGlowColor:(UIColor *)newGlowColor 14 | { 15 | if (newGlowColor != _glowColor) 16 | { 17 | _glowColor = newGlowColor; 18 | CGColorRelease(glowColorRef); 19 | glowColorRef = CGColorCreate(colorSpaceRef, CGColorGetComponents(_glowColor.CGColor)); 20 | [self setNeedsDisplay]; 21 | } 22 | } 23 | 24 | - (void)setGlowAmount:(CGFloat)glowAmount 25 | { 26 | _glowAmount = glowAmount; 27 | [self setNeedsDisplay]; 28 | } 29 | 30 | - (void)setGlowOffset:(CGSize)glowOffset 31 | { 32 | _glowOffset = glowOffset; 33 | [self setNeedsDisplay]; 34 | } 35 | 36 | - (void)initialize 37 | { 38 | colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 39 | 40 | self.glowOffset = CGSizeMake(0.0, 0.0); 41 | self.glowAmount = 10.0; 42 | self.glowColor = [UIColor orangeColor]; 43 | } 44 | 45 | - (void)awakeFromNib 46 | { 47 | [self initialize]; 48 | } 49 | 50 | - (id)initWithFrame:(CGRect)frame 51 | { 52 | self = [super initWithFrame:frame]; 53 | if(self != nil) 54 | { 55 | [self initialize]; 56 | } 57 | return self; 58 | } 59 | 60 | - (void)drawTextInRect:(CGRect)rect 61 | { 62 | [super drawTextInRect:rect]; 63 | 64 | CGContextRef context = UIGraphicsGetCurrentContext(); 65 | CGContextSaveGState(context); 66 | 67 | CGContextSetShadow(context, self.glowOffset, self.glowAmount); 68 | CGContextSetShadowWithColor(context, self.glowOffset, self.glowAmount, glowColorRef); 69 | 70 | CGContextRestoreGState(context); 71 | } 72 | 73 | - (void)dealloc 74 | { 75 | CGColorRelease(glowColorRef); 76 | CGColorSpaceRelease(colorSpaceRef); 77 | } 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/LEffectLabel/LEffectLabel.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | typedef enum tagEffectDirection 5 | { 6 | EffectDirectionLeftToRight, 7 | EffectDirectionRightToLeft, 8 | EffectDirectionTopToBottom, 9 | EffectDirectionBottomToTop, 10 | EffectDirectionTopLeftToBottomRight, 11 | EffectDirectionBottomRightToTopLeft, 12 | EffectDirectionBottomLeftToTopRight, 13 | EffectDirectionTopRightToBottomLeft 14 | } 15 | EffectDirection; 16 | 17 | 18 | @interface LEffectLabel : UIView 19 | { 20 | UILabel *_effectLabel; 21 | CGImageRef _alphaImage; 22 | CALayer *_textLayer; 23 | } 24 | 25 | @property (strong, nonatomic) UIFont *font; 26 | @property (strong, nonatomic) UIColor *textColor; 27 | @property (strong, nonatomic) UIColor *effectColor; 28 | @property (strong, nonatomic) NSString *text; 29 | 30 | @property (assign, nonatomic) EffectDirection effectDirection; 31 | 32 | - (void)performEffectAnimation; 33 | 34 | 35 | @end -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Categories/NSString+Trim.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trim.h 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (Trim) 12 | -(NSString*)stringByTruncatingToSize:(CGSize)size withFont:(UIFont*)font addQuotes:(BOOL)addQuotes; 13 | @end 14 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Categories/NSString+Trim.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trim.m 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trim.h" 10 | 11 | @implementation NSString (Trim) 12 | 13 | -(NSString*)stringByTruncatingToSize:(CGSize)size withFont:(UIFont*)font addQuotes:(BOOL)addQuotes 14 | { 15 | int min = 0, max = self.length, mid; 16 | while (min < max) { 17 | mid = (min+max)/2; 18 | 19 | NSString *currentString = [self substringWithRange:[self rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, mid)]]; 20 | CGSize currentSize = [currentString sizeWithFont:font constrainedToSize:CGSizeMake(size.width, MAXFLOAT)]; 21 | currentString = nil; 22 | 23 | if (currentSize.height < size.height){ 24 | min = mid + 1; 25 | } else if (currentSize.height > size.height) { 26 | max = mid - 1; 27 | } else { 28 | min = mid; 29 | break; 30 | } 31 | } 32 | /* handle emoji */ 33 | NSMutableString *finalString = [[self substringWithRange:[self rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, min)]] mutableCopy]; 34 | int length = addQuotes ? 4 : 3; 35 | NSString *appendString = addQuotes ? @"...\"" : @"..."; 36 | if(finalString.length < self.length && finalString.length > length) { 37 | [finalString replaceCharactersInRange:[finalString rangeOfComposedCharacterSequencesForRange:NSMakeRange(finalString.length - length, length)] withString:appendString]; 38 | } 39 | return finalString; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Categories/UIFont+Alert.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIFont+Alert.h 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIFont (Alert) 12 | +(UIFont*)boldSystemFontThatFitsSize:(CGSize)size maxFontSize:(int)max minSize:(int)min text:(NSString*)text; 13 | @end 14 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Categories/UIFont+Alert.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIFont+Alert.m 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "UIFont+Alert.h" 10 | 11 | @implementation UIFont (Alert) 12 | 13 | +(UIFont*)boldSystemFontThatFitsSize:(CGSize)size maxFontSize:(int)max minSize:(int)min text:(NSString*)text 14 | { 15 | for(int i = max; i > min; i--) { 16 | UIFont *font = [UIFont boldSystemFontOfSize:i]; 17 | CGSize _size = [text sizeWithFont:font constrainedToSize:CGSizeMake(size.width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping]; 18 | if(_size.height <= size.height) 19 | return font; 20 | } 21 | return [UIFont boldSystemFontOfSize:min]; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Categories/UIView+Animations.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Animations.h 3 | // TwoTask 4 | // 5 | // Created by M B. Bitar on 12/21/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Animations) 12 | -(void)animationPop; 13 | -(void)addFadingAnimation; 14 | -(void)removePulseAnimation; 15 | -(BOOL)hasPulseAnimation; 16 | -(void)addPulsingAnimation; 17 | -(void)addFadingAnimationWithDuration:(CGFloat)duration; 18 | 19 | // other 20 | -(void)centerViewsVerticallyWithin:(NSArray*)views; 21 | -(void)resignFirstRespondersForSubviews; 22 | @end 23 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/MBAlertView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBAlertView.h 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/8/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in 17 | // all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | // THE SOFTWARE. 26 | 27 | #import 28 | #import "MBAlertViewItem.h" 29 | 30 | // notifications called when an alert/hud appears/disappears 31 | extern NSString *const MBAlertViewDidAppearNotification; 32 | extern NSString *const MBAlertViewDidDismissNotification; 33 | 34 | // use these as needed 35 | extern CGFloat MBAlertViewMaxHUDDisplayTime; 36 | extern CGFloat MBAlertViewDefaultHUDHideDelay; 37 | 38 | @interface MBAlertView : UIViewController 39 | // if yes, will wait until alert has disappeared before performing any button blocks 40 | @property (nonatomic, assign) BOOL shouldPerformBlockAfterDismissal; 41 | 42 | // perform something after the alert dismisses 43 | @property (nonatomic, copy) id uponDismissalBlock; 44 | 45 | // huds by default are put on super view controller. however sometimes a hud appears right before a modal disappears. in that case we'll add the hud to the window 46 | @property (nonatomic, assign) BOOL addsToWindow; 47 | 48 | // offset for HUD icons, or image offset if supplied 49 | @property (nonatomic, assign) CGSize iconOffset; 50 | 51 | // body is the main text of the alert 52 | @property (nonatomic, copy) NSString *bodyText; 53 | @property (nonatomic, strong) UIFont *bodyFont; 54 | 55 | // just set the imageView's image to activate 56 | @property (nonatomic, strong) UIImageView *imageView; 57 | 58 | // if not assigned, will be full screen 59 | @property (nonatomic, assign) CGSize size; 60 | 61 | // the opacity of the background 62 | @property (nonatomic, assign) float backgroundAlpha; 63 | 64 | -(void)dismiss; 65 | -(void)addToDisplayQueue; 66 | -(void)addButtonWithText:(NSString*)text type:(MBAlertViewItemType)type block:(void (^)())block; 67 | 68 | #pragma mark Class methods 69 | // factory method 70 | +(MBAlertView*)alertWithBody:(NSString*)body cancelTitle:(NSString*)cancelTitle cancelBlock:(void (^)())cancelBlock; 71 | 72 | // yes if there is currently an alert or hud on screen 73 | +(BOOL)alertIsVisible; 74 | 75 | // dismisses current hud in queue, whether or not its visible 76 | +(void)dismissCurrentHUD; 77 | +(void)dismissCurrentHUDAfterDelay:(float)delay; 78 | 79 | // a helper method that returns a size 80 | +(CGSize)halfScreenSize; 81 | 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/MBHUDView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBHUDView.h 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/30/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "MBAlertView.h" 10 | 11 | typedef enum { 12 | MBAlertViewHUDTypeDefault, 13 | MBAlertViewHUDTypeActivityIndicator, 14 | MBAlertViewHUDTypeCheckmark, 15 | MBAlertViewHUDTypeExclamationMark, 16 | MBAlertViewHUDTypeLabelIcon, 17 | MBAlertViewHUDTypeImage, 18 | MBAlertViewHUDTypeImagePositive 19 | } MBAlertViewHUDType; 20 | 21 | @interface MBHUDView : MBAlertView 22 | @property (nonatomic, assign) MBAlertViewHUDType hudType; 23 | @property (nonatomic, assign) float hudHideDelay; 24 | @property (nonatomic, assign) CGSize bodyOffset; 25 | @property (nonatomic, strong) UILabel *iconLabel; 26 | @property (nonatomic, strong) UIColor *backgroundColor; 27 | 28 | // if you want to customize the HUD before showing, set show to NO, else setting to YES displays it right away 29 | +(MBHUDView *)hudWithBody:(NSString*)body type:(MBAlertViewHUDType)type hidesAfter:(float)delay show:(BOOL)show; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Protected/MBAlertViewItem.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBAlertViewItem.h 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum { 12 | MBAlertViewItemTypeDefault, 13 | MBAlertViewItemTypeDestructive, 14 | MBAlertViewItemTypePositive, 15 | }MBAlertViewItemType; 16 | 17 | @interface MBAlertViewItem : NSObject 18 | @property (nonatomic, copy) id block; 19 | @property (nonatomic, copy) NSString *title; 20 | @property (nonatomic, assign) MBAlertViewItemType type; 21 | -(id)initWithTitle:(NSString*)text type:(MBAlertViewItemType)type block:(void (^)())block; 22 | @end 23 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Protected/MBAlertViewItem.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBAlertViewItem.m 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "MBAlertViewItem.h" 10 | 11 | @implementation MBAlertViewItem 12 | 13 | -(id)initWithTitle:(NSString*)text type:(MBAlertViewItemType)type block:(void (^)())block 14 | { 15 | if(self = [super init]) { 16 | _title = text; 17 | _type = type; 18 | self.block = block; 19 | } 20 | return self; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Protected/MBAlertViewSubclass.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBAlertViewSubclass.h 3 | // AlertsDemo 4 | // 5 | // Created by M B. Bitar on 1/15/13. 6 | // Copyright (c) 2013 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "MBAlertView.h" 10 | 11 | @interface MBAlertView () 12 | @property (nonatomic, strong) UIButton *bodyLabelButton; 13 | @property (nonatomic, assign) CGRect contentRect; 14 | @property (nonatomic, strong) NSTimer *hideTimer; 15 | -(void)addToWindow; 16 | @end 17 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/AlertViewUI.h: -------------------------------------------------------------------------------- 1 | // 2 | // AlertViewUI.h 3 | // TwoTask 4 | // 5 | // Created by M B. Bitar on 12/25/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #ifndef TwoTask_AlertViewUI_h 10 | #define TwoTask_AlertViewUI_h 11 | 12 | #define BLUE_GLOW_COLOR [UIColor colorWithRed:50.0/255.0 green:155.0/255.0 blue:255.0/255.0 alpha:1.0] 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/MBAlertViewButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBAlertViewButton.h 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/8/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MBAlertView.h" 11 | 12 | @interface MBAlertViewButton : UIButton 13 | @property (nonatomic, copy) NSString *title; 14 | @property (nonatomic, assign) MBAlertViewItemType alertButtonType; 15 | - (id)initWithTitle:(NSString*)title; 16 | @end 17 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/MBAlertViewButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBAlertViewButton.m 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/8/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "MBAlertViewButton.h" 10 | #import 11 | #import "AlertViewUI.h" 12 | 13 | @implementation MBAlertViewButton 14 | 15 | #define kShadowSize 8 16 | #define kButtonFont [UIFont boldSystemFontOfSize:18] 17 | - (id)initWithTitle:(NSString*)title 18 | { 19 | self = [super initWithFrame:CGRectMake(0, 0, 100, 40)]; 20 | if (self) { 21 | [self setBackgroundColor:[UIColor clearColor]]; 22 | _title = title; 23 | } 24 | return self; 25 | } 26 | 27 | -(UIColor*)colorForButtonStyle 28 | { 29 | if(_alertButtonType == MBAlertViewItemTypeDefault) { 30 | return [UIColor whiteColor]; 31 | } else if(_alertButtonType == MBAlertViewItemTypeDestructive) { 32 | return [UIColor redColor]; 33 | } else if(_alertButtonType == MBAlertViewItemTypePositive) { 34 | return BLUE_GLOW_COLOR; 35 | } 36 | 37 | return [UIColor whiteColor]; 38 | } 39 | 40 | -(UIColor*)textColor 41 | { 42 | if(_alertButtonType == MBAlertViewItemTypeDefault) { 43 | return [UIColor colorWithWhite:0.2 alpha:1.0]; 44 | } else if(_alertButtonType == MBAlertViewItemTypeDestructive) { 45 | return [UIColor whiteColor]; 46 | } else if(_alertButtonType == MBAlertViewItemTypePositive) { 47 | return [UIColor whiteColor]; 48 | } 49 | 50 | return [UIColor whiteColor]; 51 | } 52 | 53 | - (void)drawRect:(CGRect)rect 54 | { 55 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:2.0]; 56 | [[self colorForButtonStyle] setFill]; 57 | [path fill]; 58 | 59 | float actualSize = 0; 60 | [_title sizeWithFont:kButtonFont minFontSize:8 actualFontSize:&actualSize forWidth:self.bounds.size.width - 20 lineBreakMode:NSLineBreakByClipping]; 61 | CGSize otherSize = [_title sizeWithFont:[UIFont boldSystemFontOfSize:actualSize]]; 62 | 63 | CGPoint origin = CGPointMake(self.bounds.size.width/2.0 - otherSize.width/2.0, self.bounds.size.height/2.0 - otherSize.height/2.0); 64 | CGRect frame = CGRectMake(origin.x, origin.y, otherSize.width, otherSize.height); 65 | 66 | [[self textColor] set]; 67 | [_title drawInRect:frame withFont:[UIFont boldSystemFontOfSize:actualSize] lineBreakMode:NSLineBreakByClipping]; 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/MBCheckMarkView.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSCheckmarkView.h 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/24/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum { 12 | MBCheckmarkSizeVerySmall, 13 | MBCheckmarkSizeSmall, 14 | MBCheckmarkSizeMedium, 15 | MBCheckmarkSizeLarge 16 | }MBCheckmarkSize; 17 | 18 | @interface MBCheckMarkView : UIView 19 | @property (nonatomic, strong) UIColor *color; 20 | @property (nonatomic, assign) MBCheckmarkSize size; 21 | 22 | +(MBCheckMarkView*)checkMarkWithSize:(MBCheckmarkSize)size color:(UIColor*)color; 23 | @end 24 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/MBCheckMarkView.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSCheckmarkView.m 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/24/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "MBCheckMarkView.h" 10 | #import 11 | 12 | static CGFloat largeSize = 50; 13 | static CGFloat mediumSize = 30; 14 | static CGFloat smallSize = 14; 15 | static CGFloat xSmallSize = 8; 16 | 17 | @implementation MBCheckMarkView 18 | 19 | +(MBCheckMarkView*)checkMarkWithSize:(MBCheckmarkSize)size color:(UIColor*)color 20 | { 21 | CGSize xySize; 22 | switch (size) { 23 | case MBCheckmarkSizeLarge: 24 | xySize = CGSizeMake(largeSize, largeSize); 25 | break; 26 | case MBCheckmarkSizeMedium: 27 | xySize = CGSizeMake(mediumSize, mediumSize); 28 | break; 29 | case MBCheckmarkSizeSmall: 30 | xySize = CGSizeMake(smallSize, smallSize); 31 | break; 32 | case MBCheckmarkSizeVerySmall: 33 | xySize = CGSizeMake(xSmallSize, xSmallSize); 34 | break; 35 | } 36 | 37 | CGRect rect = CGRectMake(0, 0, xySize.width, xySize.height); 38 | MBCheckMarkView *checkMark = [[MBCheckMarkView alloc] initWithFrame:rect]; 39 | checkMark.size = size; 40 | checkMark.opaque = NO; 41 | checkMark.color = color; 42 | return checkMark; 43 | } 44 | 45 | -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 46 | { 47 | return NO; 48 | } 49 | 50 | 51 | UIBezierPath *CheckMarkPath(CGRect frame) 52 | { 53 | float p = CGRectGetHeight(frame) / 90; 54 | UIBezierPath* bezierPath = [UIBezierPath bezierPath]; 55 | [bezierPath moveToPoint: CGPointMake(0*p, 42*p)]; 56 | [bezierPath addLineToPoint: CGPointMake(16*p, 26*p)]; 57 | [bezierPath addLineToPoint: CGPointMake(32*p, 42*p)]; 58 | [bezierPath addLineToPoint: CGPointMake(74*p, 0*p)]; 59 | [bezierPath addLineToPoint: CGPointMake(90*p, 16*p)]; 60 | [bezierPath addLineToPoint: CGPointMake(32*p, 74*p)]; 61 | [bezierPath addLineToPoint: CGPointMake(0*p, 42*p)]; 62 | [bezierPath closePath]; 63 | return bezierPath; 64 | } 65 | 66 | -(void)drawLarge 67 | { 68 | UIBezierPath* bezierPath = CheckMarkPath(CGRectMake(0, 0, 0, largeSize)); 69 | [bezierPath fill]; 70 | } 71 | 72 | -(void)drawMedium 73 | { 74 | UIBezierPath* bezierPath = CheckMarkPath(CGRectMake(0, 0, 0, mediumSize)); 75 | [bezierPath fill]; 76 | } 77 | 78 | -(void)drawSmall 79 | { 80 | UIBezierPath* bezierPath = CheckMarkPath(CGRectMake(0, 0, 0, smallSize)); 81 | [bezierPath fill]; 82 | } 83 | 84 | -(void)drawVerySmall 85 | { 86 | UIBezierPath* bezierPath = CheckMarkPath(CGRectMake(0, 0, 0, xSmallSize)); 87 | [bezierPath fill]; 88 | } 89 | 90 | - (void)drawRect:(CGRect)rect 91 | { 92 | [_color setFill]; 93 | if(_size == MBCheckmarkSizeVerySmall) 94 | [self drawVerySmall]; 95 | else if(_size == MBCheckmarkSizeSmall) 96 | [self drawSmall]; 97 | else if(_size == MBCheckmarkSizeMedium) 98 | [self drawMedium]; 99 | else if(_size == MBCheckmarkSizeLarge) 100 | [self drawLarge]; 101 | } 102 | 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/MBSpinningCircle.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSSpinningCircle.h 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/11/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum { 12 | NSSpinningCircleSizeDefault, 13 | NSSpinningCircleSizeLarge, 14 | NSSpinningCircleSizeSmall 15 | }NSSpinningCircleSize; 16 | 17 | @interface MBSpinningCircle : UIView 18 | 19 | @property (nonatomic, assign) BOOL isAnimating; 20 | @property (nonatomic, strong) UIColor *color; 21 | @property (nonatomic, assign) BOOL hasGlow; 22 | @property (nonatomic, assign) float speed; 23 | @property (nonatomic, assign) NSSpinningCircleSize circleSize; 24 | 25 | +(MBSpinningCircle*)circleWithSize:(NSSpinningCircleSize)size color:(UIColor*)color; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MBAlertView/Views/MBSpinningCircle.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSSpinningCircle.m 3 | // Notestand 4 | // 5 | // Created by M B. Bitar on 9/11/12. 6 | // Copyright (c) 2012 progenius, inc. All rights reserved. 7 | // 8 | 9 | #import "MBSpinningCircle.h" 10 | #import 11 | 12 | @implementation MBSpinningCircle 13 | { 14 | float progress; 15 | } 16 | 17 | +(MBSpinningCircle*)circleWithSize:(NSSpinningCircleSize)size color:(UIColor*)color 18 | { 19 | float width; 20 | switch (size) 21 | { 22 | case NSSpinningCircleSizeDefault: 23 | width = 40; 24 | break; 25 | case NSSpinningCircleSizeLarge: 26 | width = 50; 27 | break; 28 | case NSSpinningCircleSizeSmall: 29 | width = 10; 30 | break; 31 | } 32 | 33 | MBSpinningCircle *circle = [[MBSpinningCircle alloc] initWithFrame:CGRectMake(0, 0, width, width)]; 34 | circle.color = color; 35 | return circle; 36 | } 37 | 38 | - (id)initWithFrame:(CGRect)frame 39 | { 40 | self = [super initWithFrame:frame]; 41 | if (self) 42 | { 43 | self.opaque = NO; 44 | self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; 45 | } 46 | return self; 47 | } 48 | 49 | -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { 50 | for (UIView *view in self.subviews) 51 | { 52 | if ([view pointInside:[self convertPoint:point toView:view] withEvent:event]) 53 | return YES; 54 | } 55 | return NO; 56 | } 57 | 58 | -(void)setIsAnimating:(BOOL)animating 59 | { 60 | _isAnimating = animating; 61 | if(animating) 62 | { 63 | [UIView animateWithDuration:0.9 animations:^{ self.alpha = 1.0; }]; 64 | [self addRotationAnimation]; 65 | } 66 | else 67 | { 68 | [self hide]; 69 | } 70 | } 71 | 72 | -(void)hide 73 | { 74 | [UIView animateWithDuration:0.45 animations:^{ 75 | self.alpha = 0.0; 76 | } completion:^(BOOL fin) { 77 | [self.layer removeAllAnimations]; 78 | }]; 79 | } 80 | 81 | -(CGGradientRef)gradient 82 | { 83 | 84 | UIColor *sideColor = [UIColor redColor]; 85 | UIColor *midColor = [UIColor lightGrayColor]; 86 | NSArray* gradientColors = @[(id)sideColor.CGColor, 87 | (id)midColor.CGColor, 88 | (id)sideColor.CGColor]; 89 | CGFloat gradientLocations[] = {0, 0.5, 1}; 90 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 91 | return CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocations); 92 | } 93 | 94 | -(void)drawAnnular 95 | { 96 | progress += 0.05; 97 | if(progress > M_PI) progress = 0; 98 | CGFloat lineWidth = 3.25f; 99 | if(_circleSize == NSSpinningCircleSizeDefault) 100 | lineWidth = 2.0f; 101 | UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath]; 102 | processBackgroundPath.lineWidth = lineWidth; 103 | processBackgroundPath.lineCapStyle = kCGLineCapRound; 104 | 105 | CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); 106 | CGFloat radius = (self.bounds.size.width - 16 - lineWidth)/2; 107 | CGFloat startAngle = - ((float)M_PI / 2 - progress*2); 108 | 109 | [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.1] set]; 110 | 111 | UIBezierPath *processPath = [UIBezierPath bezierPath]; 112 | processPath.lineCapStyle = kCGLineCapSquare; 113 | processPath.lineWidth = lineWidth; 114 | CGFloat endAngle = ((float)M_PI + startAngle); 115 | [processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; 116 | 117 | CGContextRef context = UIGraphicsGetCurrentContext(); 118 | CGContextSaveGState(context); 119 | if(_hasGlow) 120 | CGContextSetShadowWithColor(UIGraphicsGetCurrentContext(), CGSizeMake(0, 0), 6, _color.CGColor); 121 | [_color set]; 122 | [processPath stroke]; 123 | CGContextRestoreGState(context); 124 | 125 | if(_isAnimating) 126 | [self addRotationAnimation]; 127 | } 128 | 129 | -(void)addRotationAnimation 130 | { 131 | CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 132 | rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI]; 133 | rotationAnimation.duration = _speed; 134 | rotationAnimation.repeatCount = MAXFLOAT; 135 | rotationAnimation.cumulative = YES; 136 | [self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation1"]; 137 | } 138 | 139 | -(void)drawRect:(CGRect)rect 140 | { 141 | [self drawAnnular]; 142 | } 143 | 144 | 145 | @end 146 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MTActivityIndicatorView/MTActivityIndicatorView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MTActivityIndicatorView.h 3 | // testAnimation 4 | // 5 | // Created by jesse on 12-7-5. 6 | // Copyright (c) 2012年 Jesse Xu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define kMTActivityIndicatorViewCycle -1 12 | 13 | @interface MTActivityIndicatorView : UIView 14 | 15 | @property (nonatomic, strong) UIColor *dotColor; 16 | 17 | @property (nonatomic, assign) CGFloat animationDuration; //animation duration default 4.0f 18 | @property (nonatomic, assign) CGFloat ratioOfMaxAndMinVelocity; //ratio of max velocity and min velocity default 10.0f 19 | @property (nonatomic, assign) CGFloat accelerateDistance; //accelerate distance ratio (between 0.0 - 1.0) default 0.375f 20 | @property (nonatomic, assign) CGFloat decelerateDistance; //decelerate distance ratio (between 0.0 - 1.0) accelerateDistance + decelerateDistance <= 1.0 defualt 0.375f 21 | @property (nonatomic, assign) CGFloat repeatInterval; //time interval between animations defualt 2.0f 22 | @property (nonatomic, assign) CGFloat dotInterval; //time interval between dots defualt 0.3f 23 | @property (nonatomic, assign) NSInteger dotCount; //number of dots default 5 24 | @property (nonatomic, assign) BOOL repeated; //need repeated defualt YES 25 | @property (nonatomic, assign) CGFloat dotRadius;//default 2.5 26 | 27 | 28 | - (void)startAnimating; 29 | - (void)stopAnimating; 30 | - (void)stopAnimatingNeedDelay:(NSTimeInterval)time; 31 | - (BOOL)isAnimating; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MessageStatusBar/MessageStatusBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomStatueBar.h 3 | // CustomStatueBar 4 | // 5 | // Created by 贺 坤 on 12-5-21. 6 | // Copyright (c) 2012年 深圳市瑞盈塞富科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "BBCyclingLabel.h" 11 | 12 | @interface MessageStatusBar : UIWindow 13 | @property (strong, nonatomic) BBCyclingLabel *messageLbl; 14 | 15 | + (MessageStatusBar *)sharedInstance; 16 | 17 | - (void)show; 18 | - (void)hideAfterDelay:(NSTimeInterval)delay; 19 | - (void)updateMessage:(NSString *)message; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/MessageStatusBar/MessageStatusBar.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomStatueBar.m 3 | // CustomStatueBar 4 | // 5 | // Created by 贺 坤 on 12-5-21. 6 | // Copyright (c) 2012年 深圳市瑞盈塞富科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "MessageStatusBar.h" 10 | 11 | @implementation MessageStatusBar 12 | 13 | + (MessageStatusBar *)sharedInstance 14 | { 15 | static MessageStatusBar *messageStatusBar = nil; 16 | if (!messageStatusBar) 17 | { 18 | messageStatusBar = [[MessageStatusBar alloc] init]; 19 | } 20 | return messageStatusBar; 21 | } 22 | 23 | - (id)initWithFrame:(CGRect)frame 24 | { 25 | CGRect rect = [UIApplication sharedApplication].statusBarFrame; 26 | self = [super initWithFrame:rect]; 27 | if (self) 28 | { 29 | self.windowLevel = UIWindowLevelStatusBar + 1.0f; 30 | self.backgroundColor = [UIColor blackColor]; 31 | 32 | self.messageLbl = [[BBCyclingLabel alloc]initWithFrame:rect 33 | andTransitionType:BBCyclingLabelTransitionEffectScrollUp]; 34 | self.messageLbl.backgroundColor = [UIColor clearColor]; 35 | self.messageLbl.clipsToBounds = YES; 36 | self.messageLbl.textAlignment = UITextAlignmentCenter; 37 | self.messageLbl.adjustsFontSizeToFitWidth = YES; 38 | [self.messageLbl setText:@"" animated:NO]; 39 | self.messageLbl.transitionDuration = 0.75; 40 | self.messageLbl.font = [UIFont systemFontOfSize:14]; 41 | self.messageLbl.textColor = [UIColor colorWithWhite:1 alpha:1]; 42 | [self addSubview:self.messageLbl]; 43 | } 44 | return self; 45 | } 46 | 47 | - (void)show 48 | { 49 | self.hidden = NO; 50 | [UIView animateWithDuration:0.5f 51 | animations:^ 52 | { 53 | self.alpha = 1.0; 54 | } 55 | completion:^(BOOL finished) 56 | { 57 | }]; 58 | } 59 | 60 | - (void)hideAfterDelay:(NSTimeInterval)delay 61 | { 62 | [self performSelector:@selector(hide) withObject:nil afterDelay:delay]; 63 | } 64 | 65 | - (void)hide 66 | { 67 | [UIView animateWithDuration:0.5f 68 | animations:^ 69 | { 70 | self.alpha = 0.0f; 71 | } 72 | completion:^(BOOL finished) 73 | { 74 | self.hidden = YES; 75 | }]; 76 | } 77 | 78 | - (void)updateMessage:(NSString *)message 79 | { 80 | [self show]; 81 | [self.messageLbl setText:message animated:YES]; 82 | } 83 | 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/PopoverView/PopoverView_Configuration.h: -------------------------------------------------------------------------------- 1 | // 2 | // PopoverView_Configuration.h 3 | // popover 4 | // 5 | // Created by Bas Pellis on 12/25/12. 6 | // Copyright (c) 2012 Oliver Rickard. All rights reserved. 7 | // 8 | 9 | #pragma mark Constants - Configure look/feel 10 | 11 | // BOX GEOMETRY 12 | 13 | //Height/width of the actual arrow 14 | #define kArrowHeight 12.f 15 | 16 | //padding within the box for the contentView 17 | #define kBoxPadding 10.f 18 | 19 | //control point offset for rounding corners of the main popover box 20 | #define kCPOffset 1.8f 21 | 22 | //radius for the rounded corners of the main popover box 23 | #define kBoxRadius 4.f 24 | 25 | //Curvature value for the arrow. Set to 0.f to make it linear. 26 | #define kArrowCurvature 6.f 27 | 28 | //Minimum distance from the side of the arrow to the beginning of curvature for the box 29 | #define kArrowHorizontalPadding 5.f 30 | 31 | //Alpha value for the shadow behind the PopoverView 32 | #define kShadowAlpha 0.4f 33 | 34 | //Blur for the shadow behind the PopoverView 35 | #define kShadowBlur 3.f; 36 | 37 | //Box gradient bg alpha 38 | #define kBoxAlpha 0.95f 39 | 40 | //Padding along top of screen to allow for any nav/status bars 41 | #define kTopMargin 50.f 42 | 43 | //margin along the left and right of the box 44 | #define kHorizontalMargin 10.f 45 | 46 | //padding along top of icons/images 47 | #define kImageTopPadding 3.f 48 | 49 | //padding along bottom of icons/images 50 | #define kImageBottomPadding 3.f 51 | 52 | 53 | // DIVIDERS BETWEEN VIEWS 54 | 55 | //Bool that turns off/on the dividers 56 | #define kShowDividersBetweenViews NO 57 | 58 | //color for the divider fill 59 | #define kDividerColor [UIColor colorWithRed:0.329 green:0.341 blue:0.353 alpha:0.15f] 60 | 61 | 62 | // BACKGROUND GRADIENT 63 | 64 | //bottom color white in gradient bg 65 | #define kGradientBottomColor [UIColor colorWithRed:0.98f green:0.98f blue:0.98f alpha:kBoxAlpha] 66 | 67 | //top color white value in gradient bg 68 | #define kGradientTopColor [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:kBoxAlpha] 69 | 70 | 71 | // TITLE GRADIENT 72 | 73 | //bool that turns off/on title gradient 74 | #define kDrawTitleGradient YES 75 | 76 | //bottom color white value in title gradient bg 77 | #define kGradientTitleBottomColor [UIColor colorWithRed:0.93f green:0.93f blue:0.93f alpha:kBoxAlpha] 78 | 79 | //top color white value in title gradient bg 80 | #define kGradientTitleTopColor [UIColor colorWithRed:1.f green:1.f blue:1.f alpha:kBoxAlpha] 81 | 82 | 83 | // FONTS 84 | 85 | //normal text font 86 | #define kTextFont [UIFont fontWithName:@"HelveticaNeue" size:16.f] 87 | 88 | //normal text color 89 | #define kTextColor [UIColor colorWithRed:0.329 green:0.341 blue:0.353 alpha:1] 90 | // highlighted text color 91 | #define kTextHighlightColor [UIColor colorWithRed:0.098 green:0.102 blue:0.106 alpha:1.000] 92 | 93 | //normal text alignment 94 | #define kTextAlignment UITextAlignmentCenter 95 | 96 | //title font 97 | //#define kTitleFont [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.f] 98 | 99 | //title text color 100 | #define kTitleColor [UIColor colorWithRed:0.329 green:0.341 blue:0.353 alpha:1] 101 | 102 | 103 | // BORDER 104 | 105 | //bool that turns off/on the border 106 | #define kDrawBorder NO 107 | 108 | //border color 109 | #define kBorderColor [UIColor blackColor] 110 | 111 | //border width 112 | #define kBorderWidth 1.f 113 | 114 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/PullTableView/PullTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // PullingRefreshTableView.h 3 | // PullingTableView 4 | // 5 | // Created by danal on 3/6/12.If you want use it,please leave my name here 6 | // Copyright (c) 2012 danal Luo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RefreshView.h" 11 | 12 | //刷新类型 13 | typedef enum 14 | { 15 | PRPullDownRefresh, //下拉刷新 16 | PRPullUpLoadMore, //上拉加载更多 17 | PRPullBoth 18 | }PRRefreshType; 19 | 20 | @protocol PullTableViewDelegate; 21 | 22 | @interface PullTableView : UITableView 23 | 24 | //刷新代理,必须实现 25 | @property (weak, nonatomic) IBOutlet id pullDelegate; 26 | 27 | //设置不同的刷新类型,默认为PRPullBoth。 28 | @property (assign, nonatomic) PRRefreshType refreshType; 29 | 30 | //如果为上拉加载更多,则headerView为nil; 31 | @property (strong, nonatomic, readonly) RefreshView *headerView; 32 | //如果为下拉刷新,则footerView为nil; 33 | @property (strong, nonatomic, readonly) RefreshView *footerView; 34 | 35 | 36 | //只需要实现这个初始化方法即可 37 | - (id)initWithFrame:(CGRect)frame; 38 | 39 | //在主类中通过ScrollView的两个代理调用这两个方法,必须实现。 40 | - (void)pullTableViewDidScroll:(UIScrollView *)scrollView; 41 | - (void)pullTableViewDidEndDragging:(UIScrollView *)scrollView; 42 | 43 | //加载完成后调用以取消菊花旋转 44 | - (void)stopPullTableViewRefresh; 45 | 46 | @end 47 | 48 | 49 | @protocol PullTableViewDelegate 50 | 51 | @optional 52 | 53 | /* 54 | 下拉刷新或上拉加载更多必须实现最少其中一个代理。 55 | */ 56 | 57 | //开始下拉刷新时调用 58 | - (void)pullTableViewDidStartPullDownRefresh:(PullTableView *)tableView; 59 | 60 | //开始上拉加载更多时调用 61 | - (void)pullTableViewDidStartPullUpLoadMore:(PullTableView *)tableView; 62 | 63 | 64 | /* 65 | 设置刷新时间,若不实现,默认为当前时间。 66 | */ 67 | //下拉刷新完成后的时间 68 | - (NSDate *)pullTableViewPullDownRefreshFinishedDate; 69 | 70 | //上拉加载更多完成后的时间 71 | - (NSDate *)pullTableViewPullUpLoadMoreFinishedDate; 72 | 73 | 74 | @end 75 | 76 | 77 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/PullTableView/RefreshView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadingView.h 3 | // ILovePostcardHD 4 | // 5 | // Created by 振东 何 on 12-7-18. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "QuartzCore/QuartzCore.h" 11 | 12 | 13 | #define kPROffsetY 55.f //上下拉触发距离 14 | #define kPRAnimationDuration 0.18f //动画时间 15 | 16 | typedef enum 17 | { 18 | kPRStateNormal = 0, 19 | kPRStatePulling, 20 | kPRStateLoading, 21 | kPRStateHitTheEnd 22 | } PRState; 23 | 24 | @interface RefreshView : UIView 25 | 26 | //默认显示刷新状态,可自行设定要显示的文字 27 | @property (nonatomic, strong) UILabel *textLabel; 28 | 29 | //显示在刷新状态下面,默认为日期,可自行设定 30 | @property (nonatomic, strong) UILabel *dateLabel; 31 | 32 | //刷新动画 33 | @property (nonatomic, strong) CALayer *arrowLayer; 34 | @property (nonatomic, strong) UIActivityIndicatorView *activityView; 35 | 36 | @property (nonatomic, getter = isLoading) BOOL loading; 37 | @property (nonatomic, getter = isAtTop) BOOL atTop; 38 | 39 | //刷新状态 40 | @property (nonatomic, assign) PRState state; 41 | 42 | 43 | - (id)initWithFrame:(CGRect)frame atTop:(BOOL)top; 44 | 45 | //默认状态下的刷新日期 46 | - (void)updateRefreshDate:(NSDate *)date; 47 | 48 | //设置刷新状态 49 | - (void)setState:(PRState)state animated:(BOOL)animated; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/PullTableView/arrowDown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/PullTableView/arrowDown.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/PullTableView/arrowUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/PullTableView/arrowUp.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/RadioButton/RadioButton-Selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/RadioButton/RadioButton-Selected.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/RadioButton/RadioButton-Unselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/RadioButton/RadioButton-Unselected.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/RadioButton/RadioButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // RadioButton.h 3 | // RadioButton 4 | // 5 | // Created by ohkawa on 11/03/23. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | 12 | @protocol RadioButtonDelegate 13 | @optional 14 | - (void)radioButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupId; 15 | 16 | @end 17 | 18 | 19 | @interface RadioButton : UIView 20 | //单选按钮 21 | @property (nonatomic, strong, readonly) UIButton *radioButton; 22 | 23 | //所在组标志位 24 | @property (nonatomic, strong, readonly) NSString *groupId; 25 | 26 | //按钮在所在组的索引号 27 | @property (nonatomic, assign, readonly) NSUInteger index; 28 | 29 | //显示在右边的内容Lable 30 | @property (nonatomic, strong, readonly) UILabel *textLbl; 31 | 32 | //是否选中状态 33 | @property (nonatomic, assign, readonly, getter = isSelected) BOOL selected; 34 | 35 | - (id)initWithFrame:(CGRect)frame groupId:(NSString *)groupId index:(NSUInteger)index; 36 | 37 | //设置默认选中项,默认未选中 38 | - (void)setSelected:(BOOL)selected; 39 | 40 | //设置显示在右边的文字 41 | - (void)setText:(NSString *)text; 42 | 43 | + (void)addObserver:(id)observer forGroupId:(NSString *)groupId; 44 | //移除分组观察者 45 | + (void)removeObserverForGroupId:(NSString *)groupId; 46 | //移除所有观察者 47 | + (void)removeAllObserver; 48 | 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/SEFilterControl/SEFilterControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // SEFilterControl.h 3 | // SEFilterControl_Test 4 | // 5 | // Created by Shady A. Elyaski on 6/13/12. 6 | // Copyright (c) 2012 mash, ltd. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | 15 | #import 16 | #import "SEFilterKnob.h" 17 | 18 | @interface SEFilterControl : UIControl 19 | @property(nonatomic, strong) UIColor *progressColor; 20 | @property(nonatomic, readonly) int selectedIndex; 21 | 22 | - (id)initWithFrame:(CGRect)frame titles:(NSArray *)titles; 23 | - (id)initWithFrame:(CGRect)frame titles:(NSArray *)titles labels:(NSArray *)labels; 24 | - (void)setSelectedIndex:(int)index; 25 | - (void)setTitlesColor:(UIColor *)color; 26 | - (void)setTitlesFont:(UIFont *)font; 27 | - (void)setHandlerColor:(UIColor *)color; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/SEFilterControl/SEFilterKnob.h: -------------------------------------------------------------------------------- 1 | // 2 | // SYFilterKnob.h 3 | // SEFilterControl_Test 4 | // 5 | // Created by Shady A. Elyaski on 6/15/12. 6 | // Copyright (c) 2012 mash, ltd. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | #import 15 | 16 | @interface SEFilterKnob : UIButton 17 | @property(nonatomic, strong) UIColor *handlerColor; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/SEFilterControl/SEFilterKnob.m: -------------------------------------------------------------------------------- 1 | // 2 | // SEFilterKnob.m 3 | // SEFilterControl_Test 4 | // 5 | // Created by Shady A. Elyaski on 6/15/12. 6 | // Copyright (c) 2012 mash, ltd. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | #import "SEFilterKnob.h" 15 | 16 | @implementation SEFilterKnob 17 | @synthesize handlerColor; 18 | 19 | - (id)initWithFrame:(CGRect)frame 20 | { 21 | self = [super initWithFrame:frame]; 22 | if (self) { 23 | // Initialization code 24 | [self setHandlerColor:[UIColor colorWithRed:230/255.f green:230/255.f blue:230/255.f alpha:1]]; 25 | } 26 | return self; 27 | } 28 | 29 | -(void) setHandlerColor:(UIColor *)hc{ 30 | handlerColor = nil; 31 | 32 | handlerColor = hc; 33 | [self setNeedsDisplay]; 34 | } 35 | 36 | // An empty implementation adversely affects performance during animation. 37 | - (void)drawRect:(CGRect)rect 38 | { 39 | // CGColorRef shadowColor = [UIColor colorWithRed:0 green:0 40 | // blue:0 alpha:.4f].CGColor; 41 | CGContextRef context = UIGraphicsGetCurrentContext(); 42 | //Draw Main Cirlce 43 | CGContextSaveGState(context); 44 | // CGContextSetShadowWithColor(context, CGSizeMake(0, 7), 10.f, shadowColor); 45 | CGContextSetStrokeColorWithColor(context, handlerColor.CGColor); 46 | CGContextSetLineWidth(context, 11); 47 | CGContextStrokeEllipseInRect(context, CGRectMake(6.5f, 6, 22, 22)); 48 | CGContextRestoreGState(context); 49 | 50 | //Draw Outer Outline 51 | CGContextSaveGState(context); 52 | // CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:.5 alpha:.6f].CGColor); 53 | CGContextSetLineWidth(context, 1); 54 | CGContextStrokeEllipseInRect(context, CGRectMake(rect.origin.x+1.5f, rect.origin.y+1.2f, 32, 32.f)); 55 | CGContextRestoreGState(context); 56 | 57 | //Draw Inner Outline 58 | CGContextSaveGState(context); 59 | 60 | // CGContextSetShadowWithColor(context, CGSizeMake(0, -4), 10.f, shadowColor); 61 | // CGContextSetStrokeColorWithColor(context, [UIColor colorWithWhite:.5 alpha:.6f].CGColor); 62 | CGContextSetLineWidth(context, 1); 63 | CGContextStrokeEllipseInRect(context, CGRectMake(rect.origin.x+12.5f, rect.origin.y+12, 10, 10)); 64 | 65 | CGContextRestoreGState(context); 66 | CGFloat colors[8] = { 0,0, 0, 0, 67 | 0, 0, 0, .6}; 68 | CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB(); 69 | CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2); 70 | 71 | CGContextSaveGState(context); 72 | CGContextAddEllipseInRect(context, CGRectMake(rect.origin.x+1.5f, rect.origin.y+1, 32, 32)); 73 | CGContextClip(context); 74 | CGContextDrawLinearGradient (context, gradient, CGPointMake(0, 0), CGPointMake(0,rect.size.height), 0); 75 | 76 | CGGradientRelease(gradient); 77 | CGColorSpaceRelease(baseSpace); 78 | CGContextRestoreGState(context); 79 | } 80 | 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/StatusBarLoading/StatusBarLoading.h: -------------------------------------------------------------------------------- 1 | // 2 | // StatusBarLoading.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-9. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MTActivityIndicatorView.h" 11 | 12 | // 13 | typedef enum LoadingStyle:NSInteger 14 | { 15 | kPageControlStyle, 16 | kCustomStyle 17 | }LoadingStyle; 18 | 19 | @interface StatusBarLoading : UIWindow 20 | //默认为kCustomStyle 21 | @property (assign, nonatomic) LoadingStyle loadingStyle; 22 | 23 | //默认为白色 24 | @property (strong, nonatomic) UIColor *dotColor; 25 | 26 | //默认为5 27 | @property (assign, nonatomic) NSUInteger dotCount; 28 | 29 | //LoadingStyle为kPageControlStyle有值,可自定义外观风格,否则返回nil 30 | @property (strong, nonatomic, readonly) UIPageControl *pageControl; 31 | 32 | //LoadingStyle为kCustomStyle有值,可自定义外观风格,否则返回nil 33 | @property (strong, nonatomic, readonly) MTActivityIndicatorView *customLoading; 34 | 35 | //LoadingStyle为kCustomStyle可设置,默认为2.5 36 | @property (assign, nonatomic) CGFloat dotRadius; 37 | 38 | + (id)sharedInstance; 39 | - (void)show; 40 | - (void)hideAfterDelay:(NSTimeInterval)delay; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/StatusBarLoading/StatusBarLoading.m: -------------------------------------------------------------------------------- 1 | // 2 | // StatusBarLoading.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-9. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "StatusBarLoading.h" 10 | 11 | @interface StatusBarLoading () 12 | @property (strong, nonatomic) UIPageControl *pageControl; 13 | @property (strong, nonatomic) MTActivityIndicatorView *customLoading; 14 | @property (strong, nonatomic) NSTimer *timer; 15 | 16 | @end 17 | 18 | @implementation StatusBarLoading 19 | 20 | kSingleton(StatusBarLoading) 21 | 22 | - (id)initWithFrame:(CGRect)frame 23 | { 24 | CGRect rect = [UIApplication sharedApplication].statusBarFrame; 25 | self = [super initWithFrame:rect]; 26 | if (self) 27 | { 28 | self.windowLevel = UIWindowLevelStatusBar + 1.0f; 29 | self.backgroundColor = [UIColor blackColor]; 30 | self.loadingStyle = kCustomStyle; 31 | self.dotColor = [UIColor whiteColor]; 32 | self.dotRadius = 2.5; 33 | self.dotCount = 3; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)setLoadingStyle:(LoadingStyle)loadingStyle 39 | { 40 | if (_loadingStyle != loadingStyle) 41 | { 42 | _loadingStyle = loadingStyle; 43 | if (_loadingStyle == kCustomStyle) 44 | { 45 | [self.pageControl removeFromSuperview]; 46 | [self addCustomLoading]; 47 | } 48 | else if (_loadingStyle == kPageControlStyle) 49 | { 50 | [self.customLoading removeFromSuperview]; 51 | [self addPageControl]; 52 | } 53 | } 54 | } 55 | 56 | - (void)setDotColor:(UIColor *)dotColor 57 | { 58 | _dotColor = dotColor; 59 | [self.customLoading setDotColor:dotColor]; 60 | if ([self.pageControl respondsToSelector:@selector(setCurrentPageIndicatorTintColor:)]) 61 | { 62 | [self.pageControl setCurrentPageIndicatorTintColor:dotColor]; 63 | } 64 | } 65 | 66 | - (void)setDotRadius:(CGFloat)dotRadius 67 | { 68 | _dotRadius = dotRadius; 69 | [self.customLoading setDotRadius:dotRadius]; 70 | } 71 | 72 | - (void)setDotCount:(NSUInteger)dotCount 73 | { 74 | _dotCount = dotCount; 75 | [self.pageControl setNumberOfPages:dotCount]; 76 | [self.customLoading setDotCount:dotCount]; 77 | } 78 | 79 | - (void)addCustomLoading 80 | { 81 | self.customLoading = [[MTActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)]; 82 | self.customLoading.animationDuration = 4.0f; 83 | [self addSubview:self.customLoading]; 84 | } 85 | 86 | - (void)addPageControl 87 | { 88 | self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; 89 | [self.pageControl setNumberOfPages:5]; 90 | [self addSubview:self.pageControl]; 91 | } 92 | 93 | - (void)pageControlValueChanged 94 | { 95 | NSInteger idx = self.pageControl.currentPage; 96 | if (idx == self.pageControl.numberOfPages - 1) 97 | { 98 | [self.pageControl setCurrentPage:0]; 99 | } 100 | else 101 | { 102 | [self.pageControl setCurrentPage:idx+1]; 103 | } 104 | } 105 | 106 | - (void)startPageControlAnimating 107 | { 108 | if (!self.timer) 109 | { 110 | self.timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(pageControlValueChanged) userInfo:nil repeats:YES]; 111 | } 112 | } 113 | 114 | - (void)stopPageControlAnimating 115 | { 116 | [self.timer invalidate]; 117 | self.timer = nil; 118 | } 119 | 120 | - (void)show 121 | { 122 | self.hidden = NO; 123 | 124 | if (self.loadingStyle == kPageControlStyle) 125 | { 126 | [self startPageControlAnimating]; 127 | } 128 | else if (self.loadingStyle == kCustomStyle) 129 | { 130 | [self.customLoading startAnimating]; 131 | } 132 | } 133 | 134 | - (void)hideAfterDelay:(NSTimeInterval)delay 135 | { 136 | [self performSelector:@selector(hide) withObject:nil afterDelay:delay]; 137 | } 138 | 139 | - (void)hide 140 | { 141 | if (self.loadingStyle == kPageControlStyle) 142 | { 143 | [self stopPageControlAnimating]; 144 | } 145 | else if (self.loadingStyle == kCustomStyle) 146 | { 147 | [self.customLoading stopAnimating]; 148 | } 149 | self.hidden = YES; 150 | } 151 | 152 | 153 | @end 154 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/THLabel/THLabel.h: -------------------------------------------------------------------------------- 1 | // 2 | // THLabel.h 3 | // 4 | // Version 1.0.3 5 | // 6 | // Created by Tobias Hagemann on 11/25/12. 7 | // Copyright (c) 2013 tobiha.de. All rights reserved. 8 | // 9 | // Original source and inspiration from: 10 | // FXLabel by Nick Lockwood, 11 | // https://github.com/nicklockwood/FXLabel 12 | // KSLabel by Kai Schweiger, 13 | // https://github.com/vigorouscoding/KSLabel 14 | // 15 | // Distributed under the permissive zlib license 16 | // Get the latest version from here: 17 | // 18 | // https://github.com/MuscleRumble/THLabel 19 | // 20 | // This software is provided 'as-is', without any express or implied 21 | // warranty. In no event will the authors be held liable for any damages 22 | // arising from the use of this software. 23 | // 24 | // Permission is granted to anyone to use this software for any purpose, 25 | // including commercial applications, and to alter it and redistribute it 26 | // freely, subject to the following restrictions: 27 | // 28 | // 1. The origin of this software must not be misrepresented; you must not 29 | // claim that you wrote the original software. If you use this software 30 | // in a product, an acknowledgment in the product documentation would be 31 | // appreciated but is not required. 32 | // 33 | // 2. Altered source versions must be plainly marked as such, and must not be 34 | // misrepresented as being the original software. 35 | // 36 | // 3. This notice may not be removed or altered from any source distribution. 37 | // 38 | 39 | #import 40 | 41 | typedef enum { 42 | THLabelStrokePositionOutside, 43 | THLabelStrokePositionCenter, 44 | THLabelStrokePositionInside 45 | } THLabelStrokePosition; 46 | 47 | @interface THLabel : UILabel 48 | 49 | @property (nonatomic, assign) CGFloat shadowBlur; 50 | 51 | @property (nonatomic, assign) CGFloat strokeSize; 52 | @property (nonatomic, strong) UIColor *strokeColor; 53 | @property (nonatomic, assign) THLabelStrokePosition strokePosition; 54 | 55 | @property (nonatomic, strong) UIColor *gradientStartColor; 56 | @property (nonatomic, strong) UIColor *gradientEndColor; 57 | @property (nonatomic, copy) NSArray *gradientColors; 58 | @property (nonatomic, assign) CGPoint gradientStartPoint; 59 | @property (nonatomic, assign) CGPoint gradientEndPoint; 60 | 61 | @property (nonatomic, assign) UIEdgeInsets textInsets; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Classes/TVSlider.h: -------------------------------------------------------------------------------- 1 | // 2 | // TVSlider.h 3 | // 4 | // Created by TavisacaIos on 9/4/12. 5 | // Copyright (c) 2012 Tavisca. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | /** 11 | TVSlider is subclass of UISlider. 12 | */ 13 | 14 | @interface TVSlider : UISlider 15 | 16 | /** 17 | @abstract Set the thumb image with a relative offset from the center of the track. 18 | @param image Slider thumb image. 19 | @param state State of the slider. 20 | @param offset Offset from the center of the track. 21 | */ 22 | - (void)setThumbImage:(UIImage *)thumbImage forState:(UIControlState)state withOffsetRelativeToCenterOfTrack:(CGPoint)offset; 23 | 24 | /** 25 | @abstract Set the text color on the highlighted thumb image. 26 | @param color Text color on the highlighted thumb image. 27 | */ 28 | - (void)setTextColorForHighlightedState:(UIColor*)color; 29 | 30 | /** 31 | @abstract Set the text font on the highlighted thumb image. 32 | @param font Text font on the highlighted thumb image. 33 | */ 34 | - (void)setTextFontForHighlightedState:(UIFont *)font; 35 | 36 | /** 37 | @abstract Set position of the text on the highlighted thumb image. 38 | @param position Text postion on the highlighted thumb image. 39 | */ 40 | - (void)setTextPositionForHighlightedStateRelativeToThumbImage:(CGPoint)position; 41 | @end 42 | -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Classes/TVSlider.m: -------------------------------------------------------------------------------- 1 | // 2 | // TVSlider.m 3 | // 4 | // Created by TavisacaIos on 9/4/12. 5 | // Copyright (c) 2012 Tavisca. All rights reserved. 6 | // 7 | 8 | #import "TVSlider.h" 9 | 10 | @interface TVSlider () { 11 | UIImage *_thumbImage; 12 | CGPoint _offset; 13 | UIColor *_highlightedStateTextColor; 14 | UIFont *_highlightedStateTextFont; 15 | CGPoint _highlightedStateTextPosition; 16 | BOOL _isHighlightedStateTextPositionCustom; 17 | } 18 | @end 19 | 20 | @implementation TVSlider 21 | 22 | - (id)initWithFrame:(CGRect)frame { 23 | self = [super initWithFrame:frame]; 24 | if (self) { 25 | self.backgroundColor = [UIColor clearColor]; 26 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 27 | _highlightedStateTextColor = [UIColor whiteColor]; 28 | _highlightedStateTextFont = [UIFont systemFontOfSize:16]; 29 | [self addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventTouchDragInside|UIControlEventTouchDown]; 30 | } 31 | return self; 32 | } 33 | 34 | - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value { 35 | CGRect rectForThumbImage = [super thumbRectForBounds:bounds trackRect:rect value:value]; 36 | if( self.state == UIControlStateHighlighted ) { 37 | rectForThumbImage = CGRectOffset(rectForThumbImage, _offset.x , _offset.y); 38 | } 39 | return rectForThumbImage; 40 | } 41 | 42 | - (void)setThumbImage:(UIImage *)thumbImage forState:(UIControlState)state withOffsetRelativeToCenterOfTrack:(CGPoint)offset { 43 | [super setThumbImage:thumbImage forState:state]; 44 | if(state == UIControlStateHighlighted) { 45 | _thumbImage = thumbImage; 46 | _offset = offset; 47 | } 48 | } 49 | 50 | - (void)setTextColorForHighlightedState:(UIColor *)color { 51 | _highlightedStateTextColor = color; 52 | } 53 | 54 | - (void)setTextPositionForHighlightedStateRelativeToThumbImage:(CGPoint)position { 55 | _isHighlightedStateTextPositionCustom = YES; 56 | _highlightedStateTextPosition = position; 57 | } 58 | 59 | -(void)setTextFontForHighlightedState:(UIFont *)font { 60 | _highlightedStateTextFont = font; 61 | } 62 | 63 | -(void)valueChanged { 64 | if(_thumbImage == nil){ 65 | return; 66 | } 67 | UIGraphicsBeginImageContextWithOptions(_thumbImage.size, NO, 0); 68 | [_thumbImage drawAtPoint:CGPointMake(0, 0)]; 69 | [_highlightedStateTextColor set]; 70 | NSString *value = [NSString stringWithFormat:@"%0.0f",self.value]; 71 | CGSize size = [value sizeWithFont:[UIFont systemFontOfSize:16]]; 72 | if(!_isHighlightedStateTextPositionCustom){ 73 | _highlightedStateTextPosition = CGPointMake(_thumbImage.size.width/2 - size.width/2, 0); 74 | } 75 | [value drawAtPoint:_highlightedStateTextPosition withFont:_highlightedStateTextFont]; 76 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 77 | [self setThumbImage:image forState:UIControlStateHighlighted]; 78 | UIGraphicsEndImageContext(); 79 | } 80 | @end -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/marker.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/marker@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/marker@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_blue.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_blue@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_blue@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_gray.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_gray@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_gray@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_hover.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_hover@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_hover@2x.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_normal.png -------------------------------------------------------------------------------- /TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_normal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/iOSApp/d2025d5f1cbe1c23889ed4013f17ba3086e646fd/TWApp/Lib/Views/TVCalibratedSlider/Resources/slider_normal@2x.png -------------------------------------------------------------------------------- /TWApp/TWApp-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | makeLaugh.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /TWApp/TWApp-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TWApp' target in the 'TWApp' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import 15 | 16 | #import "AppConfig.h" 17 | #import "MacroDefine.h" 18 | #import "NetworkAPI.h" 19 | #import "MKNetworkKit.h" 20 | #import "MessageStatusBar.h" 21 | #import "MBHUDView.h" 22 | #import "PullTableView.h" 23 | #import "TWTextField.h" 24 | #import "CategoryUtils.h" 25 | #import "UIImageView+WebCache.h" 26 | #import "UIButton+WebCache.h" 27 | #import "CheckBoxView.h" 28 | #import "PullTableView.h" 29 | #import "AttributedLabel.h" 30 | #import "RadioButton.h" 31 | #import "Singleton.h" 32 | #import "TWLabel.h" 33 | #import "VCModel.h" 34 | #import "TableDataSource.h" 35 | #import "TableDelegate.h" 36 | #import "TWCell.h" 37 | #import "TableModel.h" 38 | #import "TWViewController.h" 39 | #import "StatusBarLoading.h" 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /TWApp/TWApp/Test/TestCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestCell.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TWCell.h" 10 | 11 | @interface TestCell : TWCell 12 | @property (weak, nonatomic) IBOutlet UIImageView *thumbnail; 13 | @property (weak, nonatomic) IBOutlet UILabel *nicknameLbl; 14 | @property (weak, nonatomic) IBOutlet UILabel *contentLbl; 15 | 16 | + (CGFloat)cellHeightForCellDatas:(NSDictionary *)cellDatas; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /TWApp/TWApp/Test/TestCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestCell.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TestCell.h" 10 | 11 | @implementation TestCell 12 | 13 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 14 | { 15 | self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; 16 | if (self) 17 | { 18 | [self defaultInit]; 19 | } 20 | return self; 21 | } 22 | 23 | - (id)initWithCoder:(NSCoder *)aDecoder 24 | { 25 | self = [super initWithCoder:aDecoder]; 26 | if (self) 27 | { } 28 | return self; 29 | } 30 | 31 | - (void)awakeFromNib 32 | { 33 | [self defaultInit]; 34 | } 35 | 36 | - (void)defaultInit 37 | { 38 | self.selectionStyle = UITableViewCellSelectionStyleGray; 39 | [self.nicknameLbl setFont:kTitleFont1]; 40 | [self.nicknameLbl setTextColor:kContentHighlightColor]; 41 | [self.contentLbl setFont:kContentFont]; 42 | [self.thumbnail setBackgroundColor:[UIColor brownColor]]; 43 | } 44 | 45 | - (void)configureCellWithCellDatas:(id)cellDatas 46 | { 47 | [super configureCellWithCellDatas:cellDatas]; 48 | [self.nicknameLbl setText:cellDatas[@"nickname"]]; 49 | 50 | self.contentLbl.height = [[self class] heightForContent:cellDatas[@"content"]]; 51 | [self.contentLbl setText:cellDatas[@"content"]]; 52 | 53 | NSString *portraintUrl = [NSString stringWithFormat:@"%@%@", kImagePrex, cellDatas[@"avatar"]]; 54 | [self.thumbnail setImageWithURL:[NSURL URLWithString:portraintUrl]]; 55 | } 56 | 57 | + (CGFloat)heightForContent:(NSString *)content 58 | { 59 | CGSize contrainSize = CGSizeMake(200, 1500); 60 | UIFont *font = [UIFont systemFontOfSize:15]; 61 | CGSize size = [content sizeWithFont:font constrainedToSize:contrainSize]; 62 | return size.height; 63 | } 64 | 65 | + (CGFloat)cellHeightForCellDatas:(NSDictionary *)cellDatas 66 | { 67 | CGFloat contentHeight = [self.class heightForContent:cellDatas[@"content"]]; 68 | if (contentHeight < 40) 69 | return 90; 70 | 71 | return contentHeight + 30; 72 | } 73 | 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /TWApp/TWApp/Test/TestVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestViewController.h 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TWViewController.h" 10 | 11 | @interface TestVC : TWViewController 12 | @property (weak, nonatomic) IBOutlet PullTableView *tableView; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /TWApp/TWApp/Test/TestVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestViewController.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-8. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "TestVC.h" 10 | #import "TestCell.h" 11 | #import "TableModel.h" 12 | #import "StatusBarLoading.h" 13 | 14 | #define kTestCellIdentifier @"TestCellIdentifier" 15 | 16 | @interface TestVC () 17 | @property (strong, nonatomic) TableModel *testModel; 18 | @property (strong, nonatomic) TableDataSource *dataSource; 19 | @property (strong, nonatomic) TableDelegate *delegate; 20 | 21 | @end 22 | 23 | @implementation TestVC 24 | 25 | - (void)viewDidLoad 26 | { 27 | [super viewDidLoad]; 28 | 29 | [self setTableViewDataSource]; 30 | [self setTableViewDelegate]; 31 | [self setLoadMoreDataBlock]; 32 | [self setUpdateDataBlock]; 33 | 34 | self.testModel = [[TableModel alloc] init]; 35 | [self requestData]; 36 | } 37 | 38 | - (void)viewDidUnload 39 | { 40 | [self setTableView:nil]; 41 | [super viewDidUnload]; 42 | } 43 | 44 | 45 | #pragma mark - Table DataSource && Delegate 46 | 47 | - (void)setTableViewDataSource 48 | { 49 | CellConfigureBlock cellConfigure = ^(TWCell *cell, NSDictionary *cellDatas) 50 | { 51 | [cell configureCellWithCellDatas:cellDatas]; 52 | }; 53 | self.dataSource = [[TableDataSource alloc] initWithCellIdentifier:kTestCellIdentifier cellconfigureBlock:cellConfigure]; 54 | 55 | [self.tableView setDataSource:self.dataSource]; 56 | } 57 | 58 | - (void)setTableViewDelegate 59 | { 60 | self.delegate = [[TableDelegate alloc] init]; 61 | 62 | CellHeightBlock cellHeight = ^(NSIndexPath *indexPath) 63 | { 64 | NSDictionary *dict = self.delegate.tableItems[indexPath.row]; 65 | return [TestCell cellHeightForCellDatas:dict]; 66 | }; 67 | [self.delegate setCellHeight:cellHeight]; 68 | 69 | SelectCellBlock selecCell = ^(NSIndexPath *indexPath, id item) 70 | { 71 | NSLog(@"row:%d", indexPath.row); 72 | }; 73 | [self.delegate setSelectCell:selecCell]; 74 | 75 | [self.tableView setDelegate:self.delegate]; 76 | [self.tableView setPullDelegate:self.delegate]; 77 | } 78 | 79 | - (void)setLoadMoreDataBlock 80 | { 81 | TWLoadMoreDataBlock loadMoreData = ^(void) 82 | { 83 | [self.testModel setRefreshData:NO]; 84 | [self requestData]; 85 | }; 86 | [self.delegate setLoadMoreData:loadMoreData]; 87 | } 88 | 89 | - (void)setUpdateDataBlock 90 | { 91 | TWUpdateDataBlock updateData = ^(void) 92 | { 93 | [self.testModel resetRequestParams]; 94 | [self requestData]; 95 | }; 96 | [self.delegate setUpdateData:updateData]; 97 | } 98 | 99 | 100 | #pragma mark - Model Data Update 101 | 102 | - (void)requestData 103 | { 104 | [[StatusBarLoading sharedInstance] setDotColor:[UIColor orangeColor]]; 105 | [[StatusBarLoading sharedInstance] show]; 106 | 107 | NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:5]; 108 | [params setObject:@"32.00935" forKey:@"lat"]; 109 | [params setObject:@"118.7822" forKey:@"lon"]; 110 | [params setObject:@(self.testModel.toPage) forKey:@"pageindex"]; 111 | [params setObject:@"51d2b18e2acc93a82bd350191f68f34f" forKey:@"suid"]; 112 | [params setObject:@"3f65d5a0c3d8d344fc4f884513d9beb9" forKey:@"token"]; 113 | [params setObject:@"0" forKey:@"type"]; 114 | 115 | [self.testModel requestDataWithParams:params 116 | forPath:kHomeList 117 | finished:^(NSDictionary *data) 118 | { 119 | [self.testModel updateModelData:data]; 120 | 121 | self.dataSource.tableItems = self.testModel.tableItems; 122 | self.delegate.tableItems = self.testModel.tableItems; 123 | 124 | [self.tableView reloadData]; 125 | [self.tableView stopPullTableViewRefresh]; 126 | 127 | [[StatusBarLoading sharedInstance] hideAfterDelay:0]; 128 | } 129 | failed:^(NSString *error) 130 | { 131 | [self.tableView stopPullTableViewRefresh]; 132 | [[StatusBarLoading sharedInstance] hideAfterDelay:0]; 133 | }]; 134 | } 135 | 136 | 137 | 138 | @end 139 | -------------------------------------------------------------------------------- /TWApp/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /TWApp/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TWApp 4 | // 5 | // Created by line0 on 13-7-6. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------