Commit 74a48f81 authored by Sandy's avatar Sandy

框架完善/权限控制类/登录逻辑完善

parent b9c98cd0
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
......@@ -16,7 +20,18 @@
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="launchImg" translatesAutoresizingMaskIntoConstraints="NO" id="Iqp-lU-Gfn">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
</imageView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Iqp-lU-Gfn" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="biz-R8-vdA"/>
<constraint firstItem="Iqp-lU-Gfn" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="hau-bE-UoN"/>
<constraint firstItem="xb3-aO-Qok" firstAttribute="top" secondItem="Iqp-lU-Gfn" secondAttribute="bottom" id="nmR-xJ-kHm"/>
<constraint firstAttribute="trailing" secondItem="Iqp-lU-Gfn" secondAttribute="trailing" id="zI7-k6-o9W"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
......@@ -24,4 +39,7 @@
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<image name="launchImg" width="640" height="1136"/>
</resources>
</document>
This diff is collapsed.
#define LoginTypeTenant @"tenant"//商户
#define LoginTypeMall @"mall"//商场
@interface LoginRequest : ZJBaseModel
@property (nonatomic, strong) NSString <Optional> * password;
@property (nonatomic, strong) NSString <Optional> * type;
@property (nonatomic, strong) NSString <Optional> * principal;
@end
#import "LoginRequest.h"
@implementation LoginRequest
@end
#import "ZJBaseModel.h"
@protocol UserInfo_contracts
@end
@interface UserInfo_contracts : ZJBaseModel
@property (nonatomic, strong) NSString <Optional> * code;
@property (nonatomic, strong) NSString <Optional> * name;
@property (nonatomic, strong) NSString <Optional> * uuid;
@end
@interface UserInfo_tenant : ZJBaseModel
@property (nonatomic, strong) NSString <Optional> * code;
@property (nonatomic, strong) NSString <Optional> * name;
@property (nonatomic, strong) NSString <Optional> * uuid;
@end
@interface UserInfo_store : ZJBaseModel
@property (nonatomic, strong) NSString <Optional> * code;
@property (nonatomic, strong) NSString <Optional> * name;
@property (nonatomic, strong) NSString <Optional> * uuid;
@end
@interface UserInfo : ZJBaseModel
@property (nonatomic, strong) NSString <Optional> * uuid;
@property (nonatomic, strong) NSString <Optional> * code;
@property (nonatomic, strong) NSString <Optional> * name;
@property (nonatomic, strong) NSMutableArray <UserInfo_contracts,Optional> * contracts;
@property (nonatomic, strong) NSString <Optional> * telephone;
@property (nonatomic, strong) UserInfo_tenant <Optional> * tenant;
@property (nonatomic, strong) NSString <Optional> * type;
@property (nonatomic, strong) UserInfo_store <Optional> * store;
@property (nonatomic, strong) NSMutableArray < Optional> * permissions;
@end
#import "UserInfo.h"
@implementation UserInfo
@end
@implementation UserInfo_contracts
@end
@implementation UserInfo_tenant
@end
@implementation UserInfo_store
@end
//
// LoginViewController.h
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseViewController.h"
@interface LoginViewController : BaseViewController
@end
//
// LoginViewController.m
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "LoginViewController.h"
#import "IQUITextFieldView+Additions.h"
#import "LoginViewModel.h"
#import "RootNavigationController.h"
@interface LoginViewController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textFieldName;
@property (weak, nonatomic) IBOutlet UITextField *textFieldPWD;
@property (weak, nonatomic) IBOutlet UIButton *btnLogin;
@property (weak, nonatomic) IBOutlet UIButton *btnShop;
@property (weak, nonatomic) IBOutlet UIButton *btnMall;
@property (weak, nonatomic) IBOutlet UIImageView *imgBg;
@property (weak, nonatomic) IBOutlet UILabel *bottomInfo;
@property (strong, nonatomic) LoginViewModel *viewModel;
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self checkUpdate];
if (AppGlobal.isMall) {
self.btnMall.selected = YES;
} else {
self.btnShop.selected = YES;
}
self.textFieldName.keyboardDistanceFromTextField = 60;
self.textFieldPWD.keyboardDistanceFromTextField = 60;
self.bottomInfo.text = [NSString stringWithFormat:@"上海海鼎信息工程股份有限公司 V%@", APP_VERSION];
self.textFieldName.text = AppGlobal.savedName;
self.textFieldPWD.text = AppGlobal.savedPWD;
[self configUIWithTargetType];
}
/**
根据target的类型配置不同的界面样式
*/
- (void)configUIWithTargetType {
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)checkUpdate {
// WS(weakSelf);
// MBProgressHUD *hud = [MBProgressHUD j_loadingOnView:self.view text:@"检查版本更新中…"];
}
//登录
- (IBAction)ActionLogin:(UIButton *)sender {
[MBProgressHUD j_loading:@"登陆中…"];
self.viewModel.loginRequest.principal = self.textFieldName.text;
self.viewModel.loginRequest.password = self.textFieldPWD.text;
self.viewModel.loginRequest.type = AppGlobal.isMall ? LoginTypeMall : LoginTypeTenant;
WS(weakSelf);
[self.viewModel login:^(id responseObject, NSError *error) {
[MBProgressHUD j_hideLoadingView];
AppGlobal.savedPWD = weakSelf.textFieldPWD.text;
AppGlobal.savedName = weakSelf.textFieldName.text;
[AppGlobal saveBaseInfo];
}];
}
//tag 0 商户/ 1 内部
- (IBAction)actionSwitch:(UIButton *)sender {
AppGlobal.isMall = sender.tag == 1 ? YES : NO;
}
- (void)loginSuccessAction {
}
ZJLazy(LoginViewModel, viewModel);
@end
//
// LoginViewModel.h
// HDMall
//
// Created by Javen on 2017/7/27.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "LoginRequest.h"
@interface LoginViewModel : NSObject
@property (strong, nonatomic) LoginRequest *loginRequest;
- (void)login:(void (^)(id responseObject, NSError *error))complete;
- (void)open:(UIViewController *)viewController;
- (void)openLogin;
@end
//
// LoginViewModel.m
// HDMall
//
// Created by Javen on 2017/7/27.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "LoginViewModel.h"
#import "RootNavigationController.h"
#import "LoginViewController.h"
@implementation LoginViewModel
- (void)login:(void (^)(id responseObject, NSError *error))complete {
WS(weakSelf);
[ZJHttpManager POST:@"hdmall/authenticates/authen" parameters:self.loginRequest.toDictionary complete:^(id responseObject, NSError *error) {
if (kIsResponse) {
AppGlobal.user = [UserInfo modelWithDic:responseObject[@"data"]];
complete(responseObject, error);
[weakSelf openMain];
}else{
kFalseHttpTips;
}
}];
}
- (void)openMain {
RootNavigationController *main = [RootNavigationController viewControllerWithStoryBoardType:(STORYBOARD_TYPE_MAIN)];
[self open:main];
}
- (void)openLogin {
LoginViewController *login = [LoginViewController viewControllerWithStoryBoardType:(STORYBOARD_TYPE_MAIN)];
[self open:login];
}
- (void)open:(UIViewController *)viewController {
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[UIView transitionWithView:kWindow duration:0.7 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
kWindow.rootViewController = viewController;
[UIView setAnimationsEnabled:oldState];
} completion:nil];
}
ZJLazy(LoginRequest, loginRequest);
@end
//
// RootNavigationController.h
// HDMall
//
// Created by Javen on 2017/7/27.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RootNavigationController : UINavigationController
@end
//
// RootNavigationController.m
// HDMall
//
// Created by Javen on 2017/7/27.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "RootNavigationController.h"
@interface RootNavigationController ()
@end
@implementation RootNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
......@@ -7,12 +7,13 @@
//
#import "MineTableViewController.h"
#import "LoginViewModel.h"
@interface MineTableViewController () <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imgViewTopIcon;
@property (weak, nonatomic) IBOutlet UILabel *userName;
@property (weak, nonatomic) IBOutlet UILabel *userCode;
@property (weak, nonatomic) IBOutlet UILabel *tenant;
@property (strong, nonatomic) LoginViewModel *viewModel;
@end
@implementation MineTableViewController
......@@ -37,8 +38,7 @@
}
- (IBAction)loginOut:(id)sender {
// [[UserInfo shareInstance] loginOut];
// [self.navigationController dismissViewControllerAnimated:YES completion:nil];
[self.viewModel openLogin];
}
- (void)didReceiveMemoryWarning {
......@@ -46,58 +46,5 @@
// Dispose of any resources that can be recreated.
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
*/
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
ZJLazy(LoginViewModel, viewModel);
@end
......@@ -22,6 +22,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
......
//
// AppConfigs.h
// RealEstateManagement
//
// Created by Z on 16/6/29.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#ifndef AppConfigs_h
#define AppConfigs_h
#import <Foundation/Foundation.h>
//获取APP的icon
#define APP_ICON [UIImage imageNamed:[[[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject]]
//获取APP版本
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//获取APP名字
#define APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
//客服电话
static NSString *const APP_MOBILE = @"400-400-4000";
//版权信息
static NSString *const APP_COPYRIGHT = @"Copyright © 2017年 GomoreTech. All rights reserved.";
#endif /* AppConfigs_h */
{
"images" : [
{
"idiom" : "universal",
"filename" : "launchImg.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "login_btn_select.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "login_button_disable_bg.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "login_button_disable_bg@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "login_button_enable_bg.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "login_button_enable_bg@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "pwd_icon.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "pwd_icon@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "user_icon.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "user_icon@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
//
#ifndef Global_h
#define Global_h
#import <UIKit/UIKit.h>
#define kWindow [UIApplication sharedApplication].keyWindow
#define kBounds [UIScreen mainScreen].bounds
......@@ -35,12 +35,29 @@
#define CLog(format, ...)
#endif
#define ZJLazy(arr) \
-(NSMutableArray *) arr { \
if (!_##arr) { \
_##arr = [NSMutableArray array]; \
} \
return _##arr; \
#define ZJLazy(_type_, _ivar_) \
-(_type_ *) _ivar_ { \
if (!_##_ivar_) { \
_##_ivar_ = [[_type_ alloc] init]; \
} \
return _##_ivar_; \
}
#define ZJNSNumberString(string) string.length > 0 ? [NSDecimalNumber decimalNumberWithString:string] : nil;
/**
* colors
*/
#define kSysWhite [UIColor whiteColor]
//红 #ED1B23
#define kMainRedColor [UIColor colorWithRed:0.929 green:0.106 blue:0.137 alpha:1.000]
//蓝 #478FF1
#define kMainBlueColor [UIColor colorWithRed:0.278 green:0.561 blue:0.945 alpha:1.000]
//橙 #EA6402
#define kMainOrangeColor [UIColor colorWithRed:1.000 green:0.498 blue:0.000 alpha:1.000]
//紫 #5435AD
#define kMainPurpleColor [UIColor colorWithRed:0.329 green:0.208 blue:0.678 alpha:1.000]
//黑
#define kMainBlackColor [UIColor colorWithRed:0.13 green:0.15 blue:0.17 alpha:1.00]
#define kMainColor kMainBlueColor
#endif /* Global_h */
......@@ -10,6 +10,30 @@
#define PrefixHeader_pch
#import "Global.h"
#import "URL.h"
#import "AppConfigs.h"
#import "ZJAppInstance.h"
//BaseClass
#import "BaseViewController.h"
#import "ZJBaseModel.h"
#import "ZJBaseHttpManager.h"
//third
#import "MJRefresh.h"
//categories
#import "MBProgressHUD+Addtions.h"
#import "MBProgressHUD+Addtions.h"
#import "UIView+Category.h"
#import "UIImage+Helper.h"
#import "UIImageView+AFNetworking.h"
#import "UIViewController+Additions.h"
#import "NSNumber+Addtions.h"
#import "NSString+Additions.h"
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
......
//
// URL.h
// HDMall
//
// Created by Javen on 2017/7/27.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#ifndef URL_h
#define URL_h
#if defined(HDMall_TEST)
static NSString *const VERSION_NAME = @"商地开发版";
static NSString *const BASE_IP = @"http://gomoredev.natapp4.cc";
#elif defined(HDMall)
static NSString *const VERSION_NAME = @"商地开发版";
static NSString *const BASE_IP = @"http://gomoredev.natapp4.cc";
#else
static NSString *const VERSION_NAME = @" ";
static NSString *const BASE_IP = @"http://gomoredev.natapp4.cc";
#endif
#define REST_BASE_URL [NSString stringWithFormat:@"%@/palmmall-server/rest", BASE_IP] //常用
#endif /* URL_h */
//
// BaseAlertCardViewController.h
// patrol
//
// Created by Javen on 2017/3/3.
// Copyright © 2017年 上海勾芒科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
static NSInteger const shadowTag = 1111;
@interface BaseAlertCardViewController : UIViewController
@property (weak, nonatomic) UIViewController *superVC;
/**
弹出框
*/
@property (weak, nonatomic) IBOutlet UIView *alertCard;
- (void)show;
- (void)hide;
- (IBAction)actionHide:(id)sender;
- (void)actionTap:(UITapGestureRecognizer *)tap;
@end
//
// BaseAlertCardViewController.m
// patrol
//
// Created by Javen on 2017/3/3.
// Copyright © 2017年 上海勾芒科技有限公司. All rights reserved.
//
#import "BaseAlertCardViewController.h"
@interface BaseAlertCardViewController () <UIGestureRecognizerDelegate>
@end
@implementation BaseAlertCardViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.alertCard.transform = CGAffineTransformMakeScale(0.1, 0.1);
self.view.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0];
// Do any additional setup after loading the view.
self.view.tag = shadowTag;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap:)];
UIView *tapView = [[UIView alloc] initWithFrame:self.view.bounds];
tapView.backgroundColor = [UIColor colorWithWhite:0.01 alpha:0.01];
[self.view insertSubview:tapView belowSubview:self.alertCard];
[tapView addGestureRecognizer:tap];
}
- (void)actionTap:(UITapGestureRecognizer *)tap {
[self hide];
}
- (IBAction)actionHide:(id)sender {
[self hide];
HIDE_KEYBOARD;
}
- (void)setSuperVC:(UIViewController *)superVC {
_superVC = superVC;
[superVC addChildViewController:self];
}
/**
显示整个确认框
*/
- (void)show {
self.view.frame = self.superVC.view.bounds;
[self.superVC.view addSubview:self.view];
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.view.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.5];
self.alertCard.transform = CGAffineTransformMakeScale(1, 1);
}
completion:nil];
}
/**
隐藏整个确认框
*/
- (void)hide {
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.9
initialSpringVelocity:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.view.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.0];
self.alertCard.transform = CGAffineTransformMakeScale(0.01, 0.01);
}
completion:^(BOOL finished) {
[self.view removeFromSuperview];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// BaseChooseModel.h
// RealEstateManagement
//
// Created by Javen on 16/9/7.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface BaseChooseModel : NSObject
@property (nonatomic, copy) NSString *zj_displayName;
@end
//
// BaseChooseModel.m
// RealEstateManagement
//
// Created by Javen on 16/9/7.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseChooseModel.h"
@implementation BaseChooseModel
@end
//
// BaseChooseViewController.h
// RealEstateManagement
//
// Created by Javen on 16/9/7.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "BaseChooseModel.h"
@interface BaseChooseViewController : BaseViewController<UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
@property (nonatomic, copy) NSString *navTitle;
/**
* 分页加载时记录当前页数
*/
@property (nonatomic, assign) NSInteger page;
/**
* 每次加载的个数
*/
@property (nonatomic, assign) NSInteger pageSize;
/**
* 导航栏标题
*/
@property (weak, nonatomic) IBOutlet UILabel *navigationTitle;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *arrData;
@property (nonatomic, copy) void (^blockChoose)(id carrier);
@property (nonatomic, copy) NSString *searchText;
@property (nonatomic, strong) NSArray *displayDataArr;
@property (nonatomic, assign) BOOL isPageMode;
- (IBAction)actionBac:(id)sender;
/**
* 启用分页加载(同时需要重写searchBar:textDidChange:方法)
*/
- (void)paggingMode;
/**
* 请求数据要重写这个方法,在这个方法里面请求数据,获取数据后调用showData方法,展示获取到的数据
*/
- (void)httpRequest;
/**
* 结束刷新并获取到的数据
*/
- (void)showData;
/**
*
*/
- (void)disableRefresh;
/**
* 下拉刷新
*/
- (void)refresh;
@end
//
// BaseChooseViewController.m
// RealEstateManagement
//
// Created by Javen on 16/9/7.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseChooseViewController.h"
#import "UIScrollView+EmptyDataSet.h"
@interface BaseChooseViewController ()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@end
@implementation BaseChooseViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
self.tableView.tableFooterView = [UIView new];
self.navigationTitle.text = self.navTitle;
self.page = 0;
self.pageSize = 15;
// Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
/**
* 启用分页加载(最好在ViewDidLoad里面调用)
*/
- (void)paggingMode {
self.isPageMode = YES;
WS(weakSelf);
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.page = 0;
[weakSelf.arrData removeAllObjects];
[weakSelf httpRequest];
}];
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
weakSelf.page++;
[weakSelf httpRequest];
}];
// self.tableView.mj_footer.hidden = YES;
}
/**
* 请求数据要重写这个方法,在这个方法里面请求数据,获取数据后调用showData方法,展示获取到的数据
*/
- (void)httpRequest {
CLog(@"httpRequest 方法需要重写");
}
#pragma mark - searchbar delegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.showsCancelButton = YES;
return YES;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
searchBar.showsCancelButton = NO;
searchBar.text = nil;
[[UIApplication sharedApplication].keyWindow endEditing:YES];
self.displayDataArr = self.arrData;
self.tableView.mj_header.hidden = NO;
self.tableView.mj_footer.hidden = NO;
[self.tableView reloadData];
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
searchBar.showsCancelButton = NO;
self.displayDataArr = self.arrData;
[self.tableView reloadData];
return YES;
}
/**
* 如果不需要本地搜索,则重写这个方法
*/
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if (self.isPageMode) {
return;
}
NSPredicate *pred = [NSPredicate predicateWithFormat:@"zj_displayName contains [cd] %@", searchText];
self.displayDataArr = [self.arrData filteredArrayUsingPredicate:pred];
if (searchText.length < 1) {
self.displayDataArr = self.arrData;
}
[self.tableView reloadData];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[[UIApplication sharedApplication].keyWindow endEditing:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.displayDataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"chooseCell" forIndexPath:indexPath];
BaseChooseModel *model = self.displayDataArr[indexPath.row];
cell.textLabel.text = model.zj_displayName;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.displayDataArr[indexPath.row];
[self.navigationController popViewControllerAnimated:YES];
self.blockChoose(model);
}
- (void)showData{
self.displayDataArr = self.arrData;
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
[self.tableView reloadData];
//停止刷新的逻辑
if (self.tableView.mj_header.isRefreshing) {
//下拉刷新
[self.tableView.mj_header endRefreshing];
} else if (self.tableView.mj_footer.isRefreshing) {
[self.tableView.mj_footer endRefreshing];
}
if (self.arrData.count < self.pageSize * (self.page + 1)) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
} else {
[self.tableView.mj_footer resetNoMoreData];
}
if (self.arrData.count > 0 && self.page == 0) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
}
- (void)refresh {
[self.tableView.mj_header beginRefreshing];
}
#pragma mark - empty state
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
return [UIImage imageNamed:@"list_nodata"];
}
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
animation.duration = 1;
animation.cumulative = YES;
animation.repeatCount = MAXFLOAT;
return animation;
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView {
return [UIColor whiteColor];
}
- (void)disableRefresh {
self.tableView.mj_header.hidden = YES;
self.tableView.mj_footer.hidden = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionBac:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (NSMutableArray *)arrData {
if (!_arrData) {
_arrData = [NSMutableArray array];
}
return _arrData;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// BaseIQManagerView.h
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface BaseIQManagerView : UIView
@end
//
// BaseIQManagerView.m
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseIQManagerView.h"
@implementation BaseIQManagerView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
//
// BaseListViewController.h
// RealEstateManagement
//
// Created by Javen on 16/9/8.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseViewController.h"
#import "UINavigationController+XWTransition.h"
#import "UIViewController+XWTransition.h"
#import "XWCircleSpreadAnimator.h"
#import "UIScrollView+EmptyDataSet.h"
@interface BaseListViewController : BaseViewController<UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
/**
* 新建按钮
*/
@property (weak, nonatomic) IBOutlet UIButton *btnAdd;
@property (nonatomic, strong) NSMutableArray *arrData;
/**
* 分页加载时记录当前页数
*/
@property (nonatomic, assign) NSInteger page;
/**
* 分页加载一页大小
*/
@property (nonatomic, assign) NSInteger pageSize;
/**
* 启用分页加载模式,此时父类会自动调用网络请求的方法,不需要手动调用httpRequest
*/
- (void)paggingMode;
/**
* 请求数据要重写这个方法,在这个方法里面请求数据,获取数据后调用showData方法,展示获取到的数据
*/
- (void)httpRequest;
/**
* 选中列表cell之后
*/
- (void)listDidSelect:(id)model;
/**
* 点击添加按钮
*/
- (IBAction)actionAdd:(UIButton *)sender;
/**
* 自定义动画跳转添加界面
*/
- (void)listPushCustomAnimate:(UIViewController *)VC;
/**
* 刷新tableView
*/
- (void)listTableViewReloadData;
- (void)listTableViewReloadDataWithNewRecord:(NSArray *)newRecord;
/**
* 下拉刷新
*/
- (void)refresh;
@end
//
// BaseListViewController.m
// RealEstateManagement
//
// Created by Javen on 16/9/8.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseListViewController.h"
@interface BaseListViewController ()
@end
@implementation BaseListViewController
#pragma mark - life cycle
- (void)viewDidLoad {
[super viewDidLoad];
self.pageSize = 15;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.estimatedRowHeight = 159;
self.tableView.rowHeight = UITableViewAutomaticDimension;
if (!self.tableView.tableFooterView) {
self.tableView.tableFooterView = [UIView new];
}
[self paggingMode];
// Do any additional setup after loading the view.
}
- (void)httpRequest {
CLog(@"需要重写httpRequest方法");
}
- (void)listDidSelect:(id)model {
CLog(@"需要重写listDidSelect:方法");
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/**
* 启用分页加载(最好在ViewDidLoad里面调用)
*/
- (void)paggingMode {
WS(weakSelf);
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.page = 0;
[weakSelf.arrData removeAllObjects];
/**
* 子类里面要重写httpRequest方法
*/
[MBProgressHUD j_loading];
[weakSelf.tableView.mj_footer resetNoMoreData];
[weakSelf httpRequest];
}];
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
weakSelf.page++;
[weakSelf httpRequest];
}];
self.tableView.mj_footer.automaticallyHidden = YES;
}
- (void)refresh {
[self.tableView.mj_header beginRefreshing];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self listDidSelect:self.arrData[indexPath.row]];
}
#pragma mark - empty state
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
return [UIImage imageNamed:@"list_nodata"];
}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
[self.tableView.mj_header beginRefreshing];
}
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
animation.duration = 1;
animation.cumulative = YES;
animation.repeatCount = MAXFLOAT;
return animation;
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView {
return [UIColor whiteColor];
}
- (IBAction)actionAdd:(UIButton *)sender {
}
- (void)listPushCustomAnimate:(BaseViewController *)VC {
WS(weakSelf);
VC.commplete = ^{
[weakSelf.tableView.mj_header beginRefreshing];
};
CGPoint point = self.btnAdd.center;
XWCircleSpreadAnimator *animator = [XWCircleSpreadAnimator xw_animatorWithStartCenter:point radius:30];
[self.navigationController xw_pushViewController:VC withAnimator:animator];
}
- (void)listTableViewReloadData {
[MBProgressHUD j_hideLoadingView];
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
[self.tableView reloadData];
//停止刷新的逻辑
if (self.tableView.mj_header.isRefreshing) {
//下拉刷新
[self.tableView.mj_header endRefreshing];
} else if (self.tableView.mj_footer.isRefreshing) {
[self.tableView.mj_footer endRefreshing];
}
if (self.arrData.count < self.pageSize * (self.page + 1)) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
} else {
[self.tableView.mj_footer resetNoMoreData];
}
if (self.arrData.count > 0 && self.page == 0) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
}
- (void)judgeFooterNomoreDate {
}
- (void)listTableViewReloadDataWithNewRecord:(NSArray *)newRecord {
[self listTableViewReloadData];
CLog(@"newrecord count = %lu", newRecord.count);
if ([newRecord count] < self.pageSize) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
}
- (NSMutableArray *)arrData {
if (!_arrData) {
_arrData = [NSMutableArray array];
}
return _arrData;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// StateModel.h
// Car
//
// Created by Javen on 2017/2/10.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
// 用于切换状态
#import <Foundation/Foundation.h>
@interface BaseStateModel : NSObject
@property (nonatomic, strong) UIImage *img;
@property (nonatomic, copy) NSString *text;
@property (nonatomic, copy) NSString *code;
@property (strong, nonatomic) UIColor *color;
+ (instancetype)stateModel;
/**
此方法需要重写
@param state 状态文字
@return 状态model
*/
//+ (BaseStateModel *)stateFrom:(NSString *)state;
@end
//
// StateModel.m
// Car
//
// Created by Javen on 2017/2/10.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "BaseStateModel.h"
@implementation BaseStateModel
+ (instancetype)stateModel {
id model = [[self alloc] init];
return model;
}
@end
//
// BaseViewController.h
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <UIKit/UIKit.h>
#define kFalseHttpTips \
if (responseObject) { \
[MBProgressHUD j_error:responseObject[@"message"] complete:nil]; \
}
typedef NS_ENUM(NSInteger, promptType) { promptTypeNone,
promptTypeSuccess,
promptTypeError };
typedef void (^blockCommplete)(void);
@interface BaseViewController : UIViewController
/**
* 页面跳转之后的回调,手动调用,可选
*/
@property (nonatomic, copy) blockCommplete commplete;
- (void)baseActionBac;
@end
//
// BaseViewController.m
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BaseViewController.h"
#import "MBProgressHUD.h"
@interface BaseViewController ()
@property (nonatomic, copy) blockCommplete pushCommplete;
@end
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = kSysWhite;
self.navigationController.navigationBar.barTintColor = kMainColor;
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : kSysWhite}];
self.view.backgroundColor = [UIColor colorWithWhite:0.965 alpha:1.000];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
if (self.navigationController.viewControllers.count > 1) {
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_icon"] style:UIBarButtonItemStyleDone target:self action:@selector(baseActionBac)];
self.navigationItem.leftBarButtonItem = backItem;
}
// Do any additional setup after loading the view.
}
- (void)baseActionBac {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
if (self.pushCommplete) {
self.pushCommplete();
}
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)dealloc {
CLog(@"%@页面释放", NSStringFromClass([self class]));
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// ZJBaseFileModel.h
// RealEstateManagement
//
// Created by Javen on 2017/2/13.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "ZJBaseModel.h"
@interface ZJBaseFileModel : ZJBaseModel
@property (nonatomic, strong) NSNumber <Ignore> * size;
@property (nonatomic, strong) NSString <Optional> * idField;
@property (nonatomic, strong) NSString <Optional> * name;
@property (nonatomic, strong) NSString <Ignore> * localPath;
@property (strong, nonatomic) UIImage <Ignore> * image;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
/**
* 显示附件的图片
*
* @param imageView 需要被显示的imageView
*/
- (void)setImageView:(UIImageView *)imageView;
/**
* 获取文件的url
*
* @param fileUrl 返回的url
*/
- (void)getFileUrlComplelet:(void (^)(NSString *fileUrl))fileUrl;
@end
//
// ZJBaseFileModel.m
// RealEstateManagement
//
// Created by Javen on 2017/2/13.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "ZJBaseFileModel.h"
#import "UIImageView+WebCache.h"
@interface ZJBaseFileModel()
{
UIImage *_image;
NSString *_fileUrl;
}
@end
@implementation ZJBaseFileModel
- (instancetype)initWithDictionary:(NSDictionary *)dict {
return [[self class] modelWithDic:dict];
}
- (void)setImageView:(UIImageView *)imageView
{
if (_image != nil) {
imageView.image = _image;
}else{
[self getFileUrlComplelet:^(NSString *fileUrl) {
[imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:kPlaceHolderImage];
}];
}
}
- (void)getFileUrlComplelet:(void (^)(NSString *fileUrl))fileUrl
{
static NSCache *cache = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cache = [NSCache new];
});
NSString *url = [cache objectForKey:self.idField];
if (url) {
fileUrl(url);
}else {
// [kHttp getAttachmentWithId:self.idField
// complete:^(NSString *attachmentUrl) {
// _fileUrl = attachmentUrl;
// [cache setObject:attachmentUrl forKey:self.idField];
// fileUrl(attachmentUrl);
// }];
}
}
@end
//
// ZJBaseModel.h
// RealEstateManagement
//
// Created by Javen on 2017/2/9.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "JSONModel.h"
@interface ZJBaseModel : JSONModel
{
//搜索的时候显示的名字,可以按需要重写set、get方法
NSString *_zj_displayName;
}
- (NSString *)zj_displayName;
- (void)setZj_displayName:(NSString *)zj_displayName;
/**
字典转模型
@param dic 字典
@return 转换之后的模型类
*/
+ (instancetype)modelWithDic:(NSDictionary *)dic;
/**
模型转模型
@param model 要转换的模型类
@return 转换之后的模型类
*/
- (instancetype)modelWithModel:(id)model;
@end
//
// ZJBaseModel.m
// RealEstateManagement
//
// Created by Javen on 2017/2/9.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "ZJBaseModel.h"
@implementation ZJBaseModel
/**
字典转模型
@param dic 字典
@return 转换之后的模型类
*/
+ (instancetype)modelWithDic:(NSDictionary *)dic {
NSError *error;
id model = [[self alloc] initWithDictionary:dic error:&error];
return model;
}
+ (JSONKeyMapper *)keyMapper {
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{ @"idField" : @"id",
@"newField" : @"new" }];
}
/**
模型转模型
@param model 要转换的模型类
@return 转换之后的模型类
*/
- (instancetype)modelWithModel:(id)model {
id destinationModel = [[self class] modelWithDic:[model toDictionary]];
return destinationModel;
}
- (void)setZj_displayName:(NSString *)zj_displayName {
_zj_displayName = zj_displayName;
}
- (NSString *)zj_displayName {
return _zj_displayName;
}
@end
//
// CalculateHelper.h
// XFFruit
//
// Created by Z on 16/7/14.
// Copyright © 2016年 Xummer. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CalculateType) {
CalculateTypeAdd = 0, //加
CalculateTypeSub, //减
CalculateTypeMul, //乘
CalculateTypeDiv //除
};
@interface CalculateHelper : NSObject
/*
NSRoundPlain, // Round up on a tie //貌似取整
NSRoundDown, // Always down == truncate //只舍不入
NSRoundUp, // Always up // 只入不舍
NSRoundBankers // on a tie round so last digit is even 貌似四舍五入
*/
/**
* 计算
*
* @param num1 第一个数字
* @param num2 第二个数字
* @param type 计算类型(加减乘除)
* @param roundingType 四舍五入类型
* @param coutLenth 小数点后面保留几位
*
* @return 结算结果
*/
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type roundingType:(NSRoundingMode)roundingType cutLenth:(NSInteger)coutLenth;
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type;
/** add */
+ (NSDecimalNumber *)add:(id)num1 num2:(id)num2;
/** sub */
+ (NSDecimalNumber *)sub:(id)num1 num2:(id)num2;
/** mul */
+ (NSDecimalNumber *)mul:(id)num1 num2:(id)num2;
/** div */
+ (NSDecimalNumber *)div:(id)num1 num2:(id)num2;
/** 一百倍 */
+ (NSDecimalNumber *)oneHundredTimes:(id)num;
/** 计算百分比 */
+ (NSString *)getPercent:(id)num1 num:(id)num2;
/** 获取金额 保留两位小数*/
+ (NSString *)getMoneyStringFrom:(id)num;
/** 获取金额 */
+ (NSString *)getMoneyStringFrom:(id)num Lenth:(NSInteger)cutLenth isSeparate:(BOOL)isSeparate;
+ (NSString *)getMoneyStringFromString:(NSString *)originString;
//获得绝对值
+ (NSString *)getABSValue:(NSString *)string;
/** 每3位加逗号 */
+ (NSString *)separateMoney:(id)num;
/** 把非decimalNumber转化 */
+ (NSDecimalNumber *)decimalNumber:(id)number;
/**
* 判断数字是否在给定的范围内,num1和num2的顺序不影响判断
*
* @param num 需要判断的数字
* @param num1 范围区间
* @param num2 范围区间
*
* @return 是否在区间内
*/
+ (BOOL)number:(id)num isInNum1:(id)num1 num2:(id)num2;
@end
//
// CalculateHelper.m
// XFFruit
//
// Created by Z on 16/7/14.
// Copyright © 2016年 Xummer. All rights reserved.
//
#import "CalculateHelper.h"
@implementation CalculateHelper
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type roundingType:(NSRoundingMode)roundingType cutLenth:(NSInteger)coutLenth {
NSDecimalNumberHandler *roundUp = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:roundingType scale:coutLenth raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:YES];
NSDecimalNumber *decimalNum1 = [self changeType:num1];
NSDecimalNumber *decimalNum2 = [self changeType:num2];
if (decimalNum1 == nil || decimalNum2 == nil) {
return nil;
}
NSDecimalNumber *decimalResult;
NSString *result;
switch (type) {
case CalculateTypeAdd: {
decimalResult = [decimalNum1 decimalNumberByAdding:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
case CalculateTypeSub: {
decimalResult = [decimalNum1 decimalNumberBySubtracting:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
case CalculateTypeMul: {
decimalResult = [decimalNum1 decimalNumberByMultiplyingBy:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
break;
}
case CalculateTypeDiv: {
if ([decimalNum2 isEqualToNumber:@0]) {
decimalResult = [NSDecimalNumber decimalNumberWithString:@"0"];
} else {
decimalResult = [decimalNum1 decimalNumberByDividingBy:decimalNum2 withBehavior:roundUp];
result = [decimalResult stringValue];
}
break;
}
}
return decimalResult;
}
+ (NSDecimalNumber *)calculateNum1:(id)num1 num2:(id)num2 type:(CalculateType)type {
NSDecimalNumber *decimalNum1 = [self changeType:num1];
NSDecimalNumber *decimalNum2 = [self changeType:num2];
if (decimalNum1 == nil || decimalNum2 == nil) {
return nil;
}
NSDecimalNumber *decimalResult;
NSString *result;
switch (type) {
case CalculateTypeAdd: {
decimalResult = [decimalNum1 decimalNumberByAdding:decimalNum2];
result = [decimalResult stringValue];
break;
}
case CalculateTypeSub: {
decimalResult = [decimalNum1 decimalNumberBySubtracting:decimalNum2];
result = [decimalResult stringValue];
break;
}
case CalculateTypeMul: {
decimalResult = [decimalNum1 decimalNumberByMultiplyingBy:decimalNum2];
result = [decimalResult stringValue];
break;
}
case CalculateTypeDiv: {
if ([decimalNum2 isEqualToNumber:@0]) {
decimalResult = [NSDecimalNumber decimalNumberWithString:@"0"];
} else {
decimalResult = [decimalNum1 decimalNumberByDividingBy:decimalNum2];
result = [decimalResult stringValue];
}
break;
}
}
return decimalResult;
}
//把传入的类型变成NSDecimalNumber
+ (NSDecimalNumber *)changeType:(id)num1 {
NSDecimalNumber *decimalNum1;
if ([num1 isKindOfClass:[NSDecimalNumber class]]) {
decimalNum1 = num1;
} else if ([num1 isKindOfClass:[NSString class]]) {
if ([num1 isEqualToString:@""]) {
decimalNum1 = [NSDecimalNumber decimalNumberWithString:@"0"];
} else {
decimalNum1 = [NSDecimalNumber decimalNumberWithString:num1];
}
} else if ([num1 isKindOfClass:[NSNumber class]]) {
decimalNum1 = [NSDecimalNumber decimalNumberWithDecimal:[num1 decimalValue]];
} else if (num1 == nil) {
decimalNum1 = [NSDecimalNumber decimalNumberWithString:@"0"];
} else {
decimalNum1 = [NSDecimalNumber decimalNumberWithString:@"0"];
}
return decimalNum1;
}
+ (NSDecimalNumber *)decimalNumber:(id)number {
return [self changeType:number];
}
+ (NSDecimalNumber *)oneHundredTimes:(id)num {
return [self calculateNum1:num num2:@100 type:CalculateTypeMul roundingType:NSRoundPlain cutLenth:10];
}
+ (NSString *)getPercent:(id)num1 num:(id)num2 {
[self calculateNum1:num1 num2:num1 type:CalculateTypeDiv roundingType:NSRoundPlain cutLenth:4];
NSDecimalNumber *result = [self oneHundredTimes:[self calculateNum1:num1 num2:num2 type:CalculateTypeDiv roundingType:NSRoundPlain cutLenth:4]];
return [NSString stringWithFormat:@"%@%%", [self getMoneyStringFromString:result.stringValue]];
}
+ (NSString *)getMoneyStringFrom:(id)num Lenth:(NSInteger)cutLenth isSeparate:(BOOL)isSeparate {
NSDecimalNumberHandler *roundUp = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain
scale:cutLenth
raiseOnExactness:NO
raiseOnOverflow:NO
raiseOnUnderflow:NO
raiseOnDivideByZero:YES];
NSDecimalNumber *decimal = [self changeType:num];
NSDecimalNumber *result = [decimal decimalNumberByAdding:[NSDecimalNumber decimalNumberWithString:@"0"] withBehavior:roundUp];
if (isSeparate) {
return [self separateMoney:result];
} else {
return [result stringValue];
}
}
+ (NSString *)getMoneyStringFrom:(id)num {
NSString *originString = [self getMoneyStringFrom:num Lenth:2 isSeparate:NO];
return [self getMoneyStringFromString:originString];
}
+ (NSString *)getMoneyStringFromString:(NSString *)originString {
NSArray *array = [originString componentsSeparatedByString:@"."];
NSString *top = [array[0] stringByAppendingString:@"."];
NSString *result;
if (array.count == 1) {
result = [NSString stringWithFormat:@"%@00", top];
} else if (array.count == 2) {
NSString *bottom = array[1];
if (bottom.length == 2) {
result = originString;
}
for (NSInteger i = bottom.length; i < 2; i++) {
result = [originString stringByAppendingString:@"0"];
}
}
return result;
}
+ (NSString *)getABSValue:(NSString *)string {
if ([string hasPrefix:@"-"] && ![string hasPrefix:@"--"]) {
NSString *absString = [string substringWithRange:NSMakeRange(1, string.length - 1)];
return absString;
} else {
return string;
}
}
+ (NSString *)separateMoney:(id)num1 {
NSDecimalNumber *num = [self changeType:num1];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.locale = [NSLocale currentLocale]; // this ensure the right separator behavior
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
numberFormatter.usesGroupingSeparator = YES;
// example for writing the number object into a label
NSString *string = [numberFormatter stringFromNumber:num];
return string;
}
/** add */
+ (NSDecimalNumber *)add:(id)num1 num2:(id)num2 {
return [self calculateNum1:num1 num2:num2 type:CalculateTypeAdd];
}
/** sub */
+ (NSDecimalNumber *)sub:(id)num1 num2:(id)num2 {
return [self calculateNum1:num1 num2:num2 type:CalculateTypeSub];
}
/** mul */
+ (NSDecimalNumber *)mul:(id)num1 num2:(id)num2 {
return [self calculateNum1:num1 num2:num2 type:CalculateTypeMul];
}
/** div */
+ (NSDecimalNumber *)div:(id)num1 num2:(id)num2 {
return [self calculateNum1:num1 num2:num2 type:CalculateTypeDiv];
}
+ (BOOL)number:(id)num isInNum1:(id)num1 num2:(id)num2 {
NSDecimalNumber *decNum = [self decimalNumber:num];
NSDecimalNumber *minNumber;
NSDecimalNumber *maxNumber;
NSDecimalNumber *decNumber1 = [self decimalNumber:num1];
NSDecimalNumber *decNumber2 = [self decimalNumber:num2];
NSComparisonResult result = [decNumber1 compare:decNumber2];
if (result == NSOrderedAscending) {
minNumber = decNumber1;
maxNumber = decNumber2;
} else {
minNumber = decNumber2;
maxNumber = decNumber1;
}
if (([decNum compare:minNumber] == NSOrderedDescending && [decNum compare:maxNumber] == NSOrderedAscending) || [decNum compare:minNumber] == NSOrderedSame || [decNum compare:maxNumber] == NSOrderedSame) {
return YES;
} else {
return NO;
}
}
@end
//
// CALayer+Addtions.h
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
@interface CALayer (Addtions)
@end
//
// CALayer+Addtions.m
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "CALayer+Addtions.h"
#import <objc/runtime.h>
@implementation CALayer (Addtions)
- (void)setBorderColorFromUI:(UIColor *)color
{
self.borderColor = color.CGColor;
// NSLog(@"%@", color);
}
@end
//
// ChineseLogHelper.h
// RealEstateManagement
//
// Created by Javen on 2016/11/21.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSArray (Log)
@end
@interface NSDictionary (Log)
@end
//
// ChineseLogHelper.m
// RealEstateManagement
//
// Created by Javen on 2016/11/21.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "ChineseLogHelper.h"
@implementation NSArray (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *strM = [NSMutableString stringWithString:@"(\n"];
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[strM appendFormat:@"\t%@,\n", obj];
}];
[strM appendString:@")"];
return strM;
}
@end
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *strM = [NSMutableString stringWithString:@"{\n"];
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[strM appendFormat:@"\t%@ = %@;\n", key, obj];
}];
[strM appendString:@"}\n"];
return strM;
}
@end
//
// MBProgressHUD+Addtions.h
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <MBProgressHUD/MBProgressHUD.h>
@interface MBProgressHUD (Addtions)
/**
* 展示成功信息 自动消失
*
* @param success 显示文字
* @param complete 完成回调
*/
+ (void)j_success:(NSString *)success complete:(void (^)(void))complete;
/**
* 展示失败信息 自动消失
*
* @param error 提示文字
* @param complete 完成回调
*/
+ (void)j_error:(NSString *)error complete:(void (^)(void))complete;
/**
* 只有菊花
*/
+ (void)j_loading;
/**
* 只有菊花
*/
+ (MBProgressHUD *)j_loadingOnView:(UIView *)view;
/**
* 菊花+文字
*
* @param text 提示文字
*/
+ (void)j_loading:(NSString *)text;
/**
* 菊花+文字
*/
+ (MBProgressHUD *)j_loadingOnView:(UIView *)view text:(NSString *)text;
/**
* 文字提示 自动消失
*
* @param text 仅提示文字
*/
+ (void)j_textOnly:(NSString *)text;
/**
* 隐藏kwindow上面的所有hud
*/
+ (void)j_hideLoadingView;
+ (void)j_hideOnView:(UIView *)view;
@end
//
// MBProgressHUD+Addtions.m
// RealEstateManagement
//
// Created by Z on 16/6/24.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "MBProgressHUD+Addtions.h"
//hud 延迟多久消失
static CGFloat const delay = 1.2;
@implementation MBProgressHUD (Addtions)
//创建一个hud 配置hud样式
+ (MBProgressHUD *)j_hudWithView:(UIView *)view {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.animationType = MBProgressHUDAnimationZoomOut;
hud.contentColor = kMainBlueColor;
hud.label.font = [UIFont systemFontOfSize:18];
hud.detailsLabel.font = [UIFont systemFontOfSize:16];
hud.removeFromSuperViewOnHide = YES;
return hud;
}
//成功的hud
+ (void)j_success:(NSString *)success complete:(void (^)(void))complete {
[self j_customViewImageName:@"Checkmark" text:success complete:complete];
}
//失败的hud
+ (void)j_error:(NSString *)error complete:(void (^)(void))complete {
if ([error isEqualToString:@"A connection failure occurred"]) {
error = @"网络连接失败,请重试!";
}
[self j_customViewImageName:@"cross" text:error complete:complete];
}
//自定义hud图片
+ (MBProgressHUD *)j_customViewImageName:(NSString *)imageName text:(NSString *)text complete:(void (^)(void))complete{
[self j_removeAllHud];
MBProgressHUD *hud = [self j_hudWithView:kWindow];
hud.mode = MBProgressHUDModeCustomView;
UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.tintColor = kMainBlueColor;
hud.customView = imageView;
hud.detailsLabel.text = text;
[hud showAnimated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self j_hideLoadingView];
if (complete) {
complete();
}
});
return hud;
}
/**
* 只有菊花
*/
+ (void)j_loading {
[self j_removeAllHud];
MBProgressHUD *hud = [self j_hudWithView:kWindow];
[hud showAnimated:YES];
}
+ (MBProgressHUD *)j_loadingOnView:(UIView *)view {
[self j_removeAllHud];
MBProgressHUD *hud = [self j_hudWithView:view];
[hud showAnimated:YES];
return hud;
}
/**
* 菊花+文字
*
* @param text 提示文字
*/
+ (void)j_loading:(NSString *)text {
[self j_removeAllHud];
MBProgressHUD *hud = [self j_hudWithView:kWindow];
hud.label.text = text;
[hud showAnimated:YES];
}
/**
* 菊花+文字
*/
+ (MBProgressHUD *)j_loadingOnView:(UIView *)view text:(NSString *)text {
MBProgressHUD *hud = [self j_hudWithView:view];
hud.label.text = text;
return hud;
}
/**
* 仅文字提示 自动消失
*
* @param text 提示文字
*/
+ (void)j_textOnly:(NSString *)text {
[self j_removeAllHud];
MBProgressHUD *hud = [self j_hudWithView:kWindow];
hud.mode = MBProgressHUDModeText;
hud.label.text = text;
[hud showAnimated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self j_hideLoadingView];
});
}
/**
* 隐藏kwindow上面的所有hud
*/
+ (void)j_hideLoadingView {
[MBProgressHUD j_hideOnView:kWindow];
}
+ (void)j_hideOnView:(UIView *)view {
MBProgressHUD *hud;
for (id obj in view.subviews) {
if ([obj isKindOfClass:[MBProgressHUD class]]) {
hud = obj;
[hud hideAnimated:YES];
hud = nil;
}
}
}
/**
* 删除所有hud
*/
+ (void)j_removeAllHud {
for (id view in kWindow.subviews) {
if ([view isKindOfClass:[MBProgressHUD class]]) {
MBProgressHUD *hud = view;
[hud removeFromSuperview];
hud = nil;
}
}
}
@end
//
// NSData+EncodeAdditions.h
// Cruiser
//
// Created by Xummer on 15/4/13.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import <Foundation/Foundation.h>
void *NewBase64Decode(
const char *inputBuffer,
size_t length,
size_t *outputLength);
char *NewBase64Encode(
const void *inputBuffer,
size_t length,
bool separateLines,
size_t *outputLength);
@interface NSData (EncodeAdditions)
- (NSData *)md5Digest;
- (NSData *)sha1Digest;
- (NSString *)hexStringValue;
+ (NSData *)dataFromBase64String:(NSString *)aString;
- (NSString *)base64EncodedString;
- (NSData *)AES256EncryptWithKey:(NSString *)key;
- (NSData *)AES256DecryptWithKey:(NSString *)key;
- (NSString *)md5String;
@end
@interface NSData (FileExt)
- (BOOL)isImageType;
@end
This diff is collapsed.
//
// NSNumber+Addtions.h
// RealEstateManagement
//
// Created by Javen on 2017/7/13.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSNumber (Addtions)
- (NSString *)moneyValue;
@end
//
// NSNumber+Addtions.m
// RealEstateManagement
//
// Created by Javen on 2017/7/13.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "NSNumber+Addtions.h"
#import "CalculateHelper.h"
@implementation NSNumber (Addtions)
- (NSString *)moneyValue {
return [CalculateHelper getMoneyStringFrom:self];
}
@end
//
// NSString+Additions.h
// RealEstateManagement
//
// Created by Javen on 2016/10/17.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (Additions)
/**
* 判断输入的是否是金额(2位小数&正数&负数)
*/
- (BOOL)isValidMoneyInput;
/**
* 手机号有效性
*/
- (NSString *)isMobileNumber;
/**
* 是否纯数字
*/
- (NSString *)isNumber;
- (BOOL)isValidReg:(NSString *)reg;
- (NSString *)encodeUTF8;
@end
//
// NSString+Additions.m
// RealEstateManagement
//
// Created by Javen on 2016/10/17.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "NSString+Additions.h"
@implementation NSString (Additions)
- (BOOL)isValidMoneyInput {
//金额输入 小数点后面2位小数并且可以输入正负号
NSString *reg = @"^-?$|^-0$|^\\d?$|^-?[1-9]\\d*$|^-?0\\.\\d{0,2}$|^-?[1-9]\\d*\\.\\d{0,2}$";
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", reg];
return [numberPre evaluateWithObject:self];
}
- (BOOL)isValidReg:(NSString *)reg {
//金额输入 小数点后面2位小数并且可以输入正负号
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", reg];
return [numberPre evaluateWithObject:self];
}
//手机号有效性
- (NSString *)isMobileNumber{
if (self.length == 11 && [self hasPrefix:@"1"])
{
return @"正确";
}else{
// /**
// * 移动号段正则表达式
// */
// NSString *CM_NUM = @"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
// /**
// * 联通号段正则表达式
// */
// NSString *CU_NUM = @"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
// /**
// * 电信号段正则表达式
// */
// NSString *CT_NUM = @"^((133)|(153)|(177)|(173)|(18[0,1,9]))\\d{8}$";
// NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM_NUM];
// BOOL isMatch1 = [pred1 evaluateWithObject:self];
// NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU_NUM];
// BOOL isMatch2 = [pred2 evaluateWithObject:self];
// NSPredicate *pred3 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT_NUM];
// BOOL isMatch3 = [pred3 evaluateWithObject:self];
//
// if (isMatch1 || isMatch2 || isMatch3) {
// return @"正确";
// }else{
// return nil;
// }
return nil;
}
}
/**
* 是否纯数字
*/
- (NSString *)isNumber {
/**
* 移动号段正则表达式
*/
NSString *CM_NUM = @"^[0-9]+$";
NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM_NUM];
BOOL isMatch1 = [pred1 evaluateWithObject:self];
if (isMatch1) {
return @"正确";
}else{
return nil;
}
}
- (NSString *)encodeUTF8 {
return [self stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
}
@end
//
// UIImage+Helper.h
// CXA
//
// Created by Xummer on 14-3-3.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (Helper)
+ (UIImage *)getThumbnailImage:(UIImage *)image withMaxLen:(CGFloat)maxLen;
- (UIImage *)thumbnailWithMaxLen:(CGFloat)maxLen;
- (UIImage *)imageWithTintColor:(UIColor *)tintColor;
- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor;
- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode;
/**
* 图片压缩到指定大小(具体看图片大小,过大的图片无法压缩到指定大小)
*
* @param kb 压缩后图片大小
*
*/
- (NSData *)scaledToSpaceMaxSize:(NSInteger)kb;
/**
* 压缩图片到指定高宽
*
* @param newSize 新的图片尺寸
*
*/
- (UIImage *)scaledToSize:(CGSize)newSize;
/**
* 按比例压缩图片至指定宽度
*
* @param newWidth 指定宽度
*
*/
- (UIImage *)scaledToWidth:(NSInteger)newWidth;
/** 计算图片大小 */
- (CGFloat)dataSize;
@end
@interface UIImage (Color)
+ (UIImage *)imageWithColor:(UIColor *)color;
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size;
+ (UIImage *)imageWithColor:(UIColor *)color andRect:(CGRect)rect;
- (UIImage *)greyScaleImage;
@end
//
// UIImage+Helper.m
// CXA
//
// Created by Xummer on 14-3-3.
// Copyright (c) 2014年 Xummer. All rights reserved.
//
#import "UIImage+Helper.h"
@implementation UIImage (Helper)
// if newImage's width or heigth < 1, image will be cliped
+ (UIImage *)getThumbnailImage:(UIImage *)image withMaxLen:(CGFloat)maxLen
{
CGFloat imageMaxLen, imageMinLen;
BOOL widthIsLarger = image.size.width > image.size.height;
if (widthIsLarger) {
imageMaxLen = image.size.width;
imageMinLen = image.size.height;
}
else {
imageMaxLen = image.size.height;
imageMinLen = image.size.width;
}
if (imageMaxLen > maxLen) {
CGFloat scaleFloat = maxLen/imageMaxLen;
CGFloat newImgMinL = imageMinLen * scaleFloat;
CGSize size;
if (newImgMinL < 1) {
scaleFloat = 1/imageMinLen;
if (widthIsLarger) {
size = CGSizeMake(maxLen, image.size.height * scaleFloat);
}
else {
size = CGSizeMake(image.size.width * scaleFloat, maxLen);
}
}
else {
size = CGSizeMake(image.size.width * scaleFloat,
image.size.height * scaleFloat);
}
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformScale(transform, scaleFloat, scaleFloat);
CGContextConcatCTM(context, transform);
// Draw the image into the transformed context and return the image
[image drawAtPoint:CGPointMake(0.0f, 0.0f)];
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
else{
return image;
}
}
- (UIImage *)thumbnailWithMaxLen:(CGFloat)maxLen {
return [[self class] getThumbnailImage:self withMaxLen:maxLen];
}
- (UIImage *)imageWithTintColor:(UIColor *)tintColor {
return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn];
}
- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor {
return [self imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay];
}
- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode
{
//We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
[tintColor setFill];
CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
UIRectFill(bounds);
//Draw the tinted image in context
[self drawInRect:bounds blendMode:blendMode alpha:1.0f];
if (blendMode != kCGBlendModeDestinationIn) {
[self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
}
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tintedImage;
}
- (NSData *)scaledToSpaceMaxSize:(NSInteger)kb {
//压缩到指定大小以内
CGFloat compression = 0.5f;
CGFloat maxCompression = 0.1f;
NSUInteger maxlength = kb * 1024;
NSData *imgData = UIImageJPEGRepresentation(self, compression);
CLog(@"处理之前的大小--->%lukB",(unsigned long)imgData.length/1024);
while ([imgData length] > maxlength && compression > maxCompression) {
compression -= 0.1;
imgData = UIImageJPEGRepresentation(self, compression);
}
CLog(@"处理之后的大小--->%lukB",(unsigned long)imgData.length/1024);
return imgData;
}
- (UIImage *)scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, YES, 0);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
- (UIImage *)scaledToWidth:(NSInteger)newWidth {
CLog(@"旧尺寸%@", NSStringFromCGSize(self.size));
CGSize newSize = CGSizeMake(newWidth, newWidth / self.size.width * self.size.height);
UIGraphicsBeginImageContextWithOptions(newSize, YES, 0);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CLog(@"新尺寸%@", NSStringFromCGSize(scaledImage.size));
return scaledImage;
}
/** 计算图片大小 */
- (CGFloat)dataSize {
NSData *data = UIImageJPEGRepresentation(self, 1);
CGFloat size = data.length/1024;
CLog(@"data size=%.0f kB, size=%@", size, NSStringFromCGSize(self.size));
return size;
}
@end
@implementation UIImage (Color)
typedef enum {
ALPHA = 0,
BLUE = 1,
GREEN = 2,
RED = 3
} PIXELS;
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);
return [[self class] imageWithColor:color andRect:rect];
}
+ (UIImage *)imageWithColor:(UIColor *)color andRect:(CGRect)rect {
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,[color CGColor]);
CGContextFillRect(context, rect);
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size {
return [[self class] imageWithColor:color andRect:(CGRect){
.origin = CGPointZero,
.size = size
}];
}
- (UIImage *)greyScaleImage {
CGSize size = [self size];
int width = size.width;
int height = size.height;
// the pixels will be painted to this array
uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
// clear the pixels so any transparency is preserved
memset(pixels, 0, width * height * sizeof(uint32_t));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// create a context with RGBA pixels
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
// paint the bitmap to our context which will fill in the pixels array
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x];
// convert to grayscale using recommended method: http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE];
// set the pixels to gray
rgbaPixel[RED] = gray;
rgbaPixel[GREEN] = gray;
rgbaPixel[BLUE] = gray;
}
}
// create a new CGImageRef from our context with the modified pixels
CGImageRef image = CGBitmapContextCreateImage(context);
// we're done with the context, color space, and pixels
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(pixels);
// make a new UIImage to return
UIImage *resultUIImage = [UIImage imageWithCGImage:image];
// we're done with image now too
CGImageRelease(image);
return resultUIImage;
}
@end
//
// UILabel+Addtions.h
// RealEstateManagement
//
// Created by Javen on 2017/1/8.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UILabel (Addtions)
@end
@interface UILabel (ContentSize)
/**
计算UILabel的高宽
@return size
*/
- (CGSize)contentSize;
@end
//
// UILabel+Addtions.m
// RealEstateManagement
//
// Created by Javen on 2017/1/8.
// Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//
#import "UILabel+Addtions.h"
@implementation UILabel (Addtions)
@end
@implementation UILabel (ContentSize)
- (CGSize)contentSize {
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = self.lineBreakMode;
paragraphStyle.alignment = self.textAlignment;
NSDictionary * attributes = @{NSFontAttributeName : self.font,
NSParagraphStyleAttributeName : paragraphStyle};
CGSize contentSize = [self.text boundingRectWithSize:self.frame.size
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
attributes:attributes
context:nil].size;
return contentSize;
}
@end
//
// UIView+Category.h
// ALand
//
// Created by Z on 16/3/22.
// Copyright © 2016年 Z. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIView (Category)
/**
* 根据nib名字获取view
*/
+ (id)viewWithNibName:(NSString *)viewName;
/**
* 根据类名获取对应的xib
*
* @return view
*/
+ (id)viewFromNib;
/**
* 获取view父视图的控制器
*
* @return 控制器
*/
- (UIViewController *)viewController;
/**
* 控制底部弹出动画
*
* @param constraint 视图底部到父视图底部的距离约束
* @param toBottom 视图底部到父视图底部的距离
*/
- (void)constraint:(NSLayoutConstraint *)constraint toBottom:(NSInteger)toBottom;
@property (assign, nonatomic) CGFloat top;
@property (assign, nonatomic) CGFloat bottom;
@property (assign, nonatomic) CGFloat left;
@property (assign, nonatomic) CGFloat right;
@property (assign, nonatomic) CGPoint offset;
@property (assign, nonatomic) CGPoint position;
@property (assign, nonatomic) CGFloat x;
@property (assign, nonatomic) CGFloat y;
@property (assign, nonatomic) CGFloat w;
@property (assign, nonatomic) CGFloat h;
@property (assign, nonatomic) CGFloat width;
@property (assign, nonatomic) CGFloat height;
@property (assign, nonatomic) CGSize size;
@property (assign, nonatomic) CGFloat centerX;
@property (assign, nonatomic) CGFloat centerY;
@property (assign, nonatomic) CGPoint origin;
@property (readonly, nonatomic) CGPoint boundsCenter;
/**
* 圆角
*/
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;
/**
边框宽度
*/
@property (nonatomic, assign) IBInspectable CGFloat borderWidth;
/**
边框颜色
*/
@property (nonatomic, assign) IBInspectable UIColor *borderColor;
@end
//
// UIView+Category.m
// ALand
//
// Created by Z on 16/3/22.
// Copyright © 2016年 Z. All rights reserved.
//
#import "UIView+Category.h"
@implementation UIView (Category)
+ (id)viewWithNibName:(NSString *)viewName
{
NSArray *nibView = [[NSBundle mainBundle] loadNibNamed:viewName owner:nil options:nil];
return [nibView objectAtIndex:0];
}
+ (id)viewFromNib
{
NSString *className = NSStringFromClass([self class]);
NSArray *nibView = [[NSBundle mainBundle] loadNibNamed:className owner:nil options:nil];
return [nibView objectAtIndex:0];
}
- (UIViewController *)viewController
{
for (UIView *next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
/**
* 控制底部弹出动画
*
* @param constraint 视图底部到父视图底部的距离约束
* @param toBottom 视图底部到父视图底部的距离
*/
- (void)constraint:(NSLayoutConstraint *)constraint toBottom:(NSInteger)toBottom
{
HIDE_KEYBOARD;
constraint.constant = toBottom;
WS(weakSelf);
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
weakSelf.bottom = toBottom;
[weakSelf layoutIfNeeded];
}
completion:nil];
}
- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
}
- (void)setBorderWidth:(CGFloat)borderWidth {
self.layer.borderWidth = borderWidth;
}
- (CGFloat)borderWidth {
return self.layer.borderWidth;
}
- (void)setBorderColor:(UIColor *)borderColor {
self.layer.borderColor = borderColor.CGColor;
}
- (UIColor *)borderColor {
return [UIColor colorWithCGColor:self.layer.borderColor];
}
- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}
/**
添加阴影
@param color 颜色
@param offset 位置
*/
- (void)addShadowColor:(UIColor *)color withOffset:(CGSize)offset
{
self.layer.shadowColor = color.CGColor;
self.layer.shadowOffset = offset;
self.layer.shadowOpacity = 0.3;
}
@dynamic top;
@dynamic bottom;
@dynamic left;
@dynamic right;
@dynamic width;
@dynamic height;
@dynamic offset;
@dynamic position;
@dynamic size;
@dynamic x;
@dynamic y;
@dynamic w;
@dynamic h;
- (CGFloat)top
{
return self.frame.origin.y;
}
- (void)setTop:(CGFloat)top
{
CGRect frame = self.frame;
frame.origin.y = top;
self.frame = frame;
}
- (CGFloat)left
{
return self.frame.origin.x;
}
- (void)setLeft:(CGFloat)left
{
CGRect frame = self.frame;
frame.origin.x = left;
self.frame = frame;
}
- (CGFloat)width
{
return self.frame.size.width;
}
- (void)setWidth:(CGFloat)width
{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
- (CGFloat)height
{
return self.frame.size.height;
}
- (void)setHeight:(CGFloat)height
{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
- (CGFloat)bottom
{
return self.frame.size.height + self.frame.origin.y;
}
- (void)setBottom:(CGFloat)bottom
{
CGRect frame = self.frame;
frame.origin.y = bottom - frame.size.height;
self.frame = frame;
}
- (CGFloat)right
{
return self.frame.size.width + self.frame.origin.x;
}
- (void)setRight:(CGFloat)right
{
CGRect frame = self.frame;
frame.origin.x = right - frame.size.width;
self.frame = frame;
}
- (CGFloat)x
{
return self.frame.origin.x;
}
- (void)setX:(CGFloat)value
{
CGRect frame = self.frame;
frame.origin.x = value;
self.frame = frame;
}
- (CGFloat)y
{
return self.frame.origin.y;
}
- (void)setY:(CGFloat)value
{
CGRect frame = self.frame;
frame.origin.y = value;
self.frame = frame;
}
- (CGFloat)w
{
return self.frame.size.width;
}
- (void)setW:(CGFloat)width
{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
- (CGFloat)h
{
return self.frame.size.height;
}
- (void)setH:(CGFloat)height
{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
- (CGPoint)offset
{
CGPoint point = CGPointZero;
UIView *view = self;
while (view) {
point.x += view.frame.origin.x;
point.y += view.frame.origin.y;
view = view.superview;
}
return point;
}
- (void)setOffset:(CGPoint)offset
{
UIView *view = self;
if (nil == view) return;
CGPoint point = offset;
while (view) {
point.x += view.superview.frame.origin.x;
point.y += view.superview.frame.origin.y;
view = view.superview;
}
CGRect frame = self.frame;
frame.origin = point;
self.frame = frame;
}
- (CGPoint)position
{
return self.frame.origin;
}
- (void)setPosition:(CGPoint)pos
{
CGRect frame = self.frame;
frame.origin = pos;
self.frame = frame;
}
- (CGSize)size
{
return self.frame.size;
}
- (void)setSize:(CGSize)size
{
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}
- (CGFloat)centerX
{
return self.center.x;
}
- (void)setCenterX:(CGFloat)centerX
{
CGPoint center = self.center;
center.x = centerX;
self.center = center;
}
- (CGFloat)centerY
{
return self.center.y;
}
- (void)setCenterY:(CGFloat)centerY
{
CGPoint center = self.center;
center.y = centerY;
self.center = center;
}
- (CGPoint)origin
{
return self.frame.origin;
}
- (void)setOrigin:(CGPoint)origin
{
CGRect frame = self.frame;
frame.origin = origin;
self.frame = frame;
}
- (CGPoint)boundsCenter
{
return CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
}
@end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment