├── LICENSE ├── LXFHouseLoanCalculator ├── LXFHouseLoanCalculator.h └── LXFHouseLoanCalculator.m ├── LXFHouseLoanCalculatorDemo ├── LXFHouseLoanCalculatorDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── lxf.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── lxf.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── LXFHouseLoanCalculatorDemo.xcscheme │ │ └── xcschememanagement.plist └── LXFHouseLoanCalculatorDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Classes │ ├── Category │ │ ├── NSArray+LXF.h │ │ ├── NSArray+LXF.m │ │ ├── UITableViewCell+LXF.h │ │ ├── UITableViewCell+LXF.m │ │ ├── UIView+LXF.h │ │ └── UIView+LXF.m │ ├── Controller │ │ ├── Base │ │ │ ├── LXFCalculatorBaseViewController.h │ │ │ └── LXFCalculatorBaseViewController.m │ │ ├── LXFCalculatorBusinessViewController.h │ │ ├── LXFCalculatorBusinessViewController.m │ │ ├── LXFCalculatorFundViewController.h │ │ ├── LXFCalculatorFundViewController.m │ │ ├── LXFCalculatorGroupViewController.h │ │ ├── LXFCalculatorGroupViewController.m │ │ ├── LXFCalculatorViewController.h │ │ └── LXFCalculatorViewController.m │ ├── Lib │ │ ├── LCActionSheet │ │ │ ├── LCActionSheet.h │ │ │ ├── LCActionSheet.m │ │ │ ├── LCActionSheetCell.h │ │ │ ├── LCActionSheetCell.m │ │ │ ├── LCActionSheetConfig.h │ │ │ ├── LCActionSheetConfig.m │ │ │ ├── LCActionSheetViewController.h │ │ │ ├── LCActionSheetViewController.m │ │ │ ├── UIImage+LCActionSheet.h │ │ │ └── UIImage+LCActionSheet.m │ │ ├── Masonry │ │ │ ├── MASCompositeConstraint.h │ │ │ ├── MASCompositeConstraint.m │ │ │ ├── MASConstraint+Private.h │ │ │ ├── MASConstraint.h │ │ │ ├── MASConstraint.m │ │ │ ├── MASConstraintMaker.h │ │ │ ├── MASConstraintMaker.m │ │ │ ├── MASLayoutConstraint.h │ │ │ ├── MASLayoutConstraint.m │ │ │ ├── MASUtilities.h │ │ │ ├── MASViewAttribute.h │ │ │ ├── MASViewAttribute.m │ │ │ ├── MASViewConstraint.h │ │ │ ├── MASViewConstraint.m │ │ │ ├── Masonry.h │ │ │ ├── NSArray+MASAdditions.h │ │ │ ├── NSArray+MASAdditions.m │ │ │ ├── NSArray+MASShorthandAdditions.h │ │ │ ├── NSLayoutConstraint+MASDebugAdditions.h │ │ │ ├── NSLayoutConstraint+MASDebugAdditions.m │ │ │ ├── View+MASAdditions.h │ │ │ ├── View+MASAdditions.m │ │ │ ├── View+MASShorthandAdditions.h │ │ │ ├── ViewController+MASAdditions.h │ │ │ └── ViewController+MASAdditions.m │ │ └── XLBasePageController │ │ │ ├── XLBasePageController.h │ │ │ └── XLBasePageController.m │ ├── Model │ │ ├── LXFCalculateResultModel.h │ │ └── LXFCalculateResultModel.m │ └── View │ │ ├── LXFCalcInputCell.h │ │ ├── LXFCalcInputCell.m │ │ ├── LXFCalcInputCell.xib │ │ ├── LXFCalcSelectStrCell.h │ │ ├── LXFCalcSelectStrCell.m │ │ ├── LXFCalcSelectStrCell.xib │ │ ├── LXFCalculatorCalcBtnView.h │ │ ├── LXFCalculatorCalcBtnView.m │ │ ├── LXFCalculatorCalcBtnView.xib │ │ ├── LXFPopResultCell.h │ │ ├── LXFPopResultCell.m │ │ ├── LXFPopResultCell.xib │ │ ├── LXFPopResultView.h │ │ └── LXFPopResultView.m │ ├── Info.plist │ ├── LXFHouseLoanCalculator │ ├── LXFHouseLoanCalculator.h │ └── LXFHouseLoanCalculator.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── README.md └── Screenshots ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png └── 7.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 林洵锋 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculator/LXFHouseLoanCalculator.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFHouseLoanCalculator.h 3 | // 4 | // Created by LinXunFeng on 2017/8/25. 5 | // Copyright © 2017年 LinXunFeng. All rights reserved. 6 | // 7 | // GitHub: https://github.com/LinXunFeng 8 | // 简书: http://www.jianshu.com/users/31e85e7a22a2 9 | 10 | #import 11 | @class LXFHouseLoanCalcModel, LXFHouseLoanResultModel; 12 | 13 | @interface LXFHouseLoanCalculator : NSObject 14 | 15 | /** =================================== 商业贷款 =================================== */ 16 | 17 | #pragma mark 按商业贷款等额本息总价计算(总价) 18 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 19 | #pragma mark 按商业贷款等额本金总价计算(总价) 20 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 21 | #pragma mark 按商业贷款等额本息单价计算(单价和面积) 22 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsUnitPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 23 | #pragma mark 按商业贷款等额本金单价计算(单价和面积) 24 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsUnitPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 25 | 26 | /** =================================== 公积金贷款 =================================== */ 27 | 28 | #pragma mark 按公积金贷款等额本息总价计算(总价) 29 | + (LXFHouseLoanResultModel *)calculateFundLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 30 | #pragma mark 按公积金贷款等额本金总价计算(总价) 31 | + (LXFHouseLoanResultModel *)calculateFundLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 32 | #pragma mark 按公积金贷款等额本息单价计算(单价和面积) 33 | + (LXFHouseLoanResultModel *)calculateFundLoanAsUnitPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 34 | #pragma mark 按公积金贷款等额本金单价计算(单价和面积) 35 | + (LXFHouseLoanResultModel *)calculateFundLoanAsUnitPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 36 | 37 | /** =================================== 组合型贷款 =================================== */ 38 | #pragma mark 按组合型贷款等额本息总价计算(总价) 39 | + (LXFHouseLoanResultModel *)calculateCombinedLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 40 | #pragma mark 按组合型贷款等额本金总价计算(总价) 41 | + (LXFHouseLoanResultModel *)calculateCombinedLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 42 | 43 | @end 44 | 45 | @interface LXFHouseLoanCalcModel : NSObject 46 | 47 | /** 单价 */ 48 | @property (nonatomic, assign) double unitPrice; 49 | /** 面积 */ 50 | @property (nonatomic, assign) double area; 51 | /** 商业贷款总额 */ 52 | @property (nonatomic, assign) double businessTotalPrice; 53 | /** 公积金贷款总额 */ 54 | @property (nonatomic, assign) double fundTotalPrice; 55 | /** 按揭年数 */ 56 | @property (nonatomic, assign) int mortgageYear; 57 | /** 按揭成数 */ 58 | @property (nonatomic, assign) int mortgageMulti; 59 | /** 银行利率 */ 60 | @property (nonatomic, assign) double bankRate; 61 | /** 公积金利率 */ 62 | @property (nonatomic, assign) double fundRate; 63 | 64 | @end 65 | 66 | 67 | @interface LXFHouseLoanResultModel : NSObject 68 | // 房屋总价 69 | @property (nonatomic, assign) double houseTotalPrice; 70 | /** 贷款总额 */ 71 | @property (nonatomic, assign) double loanTotalPrice; 72 | /** 还款总额 */ 73 | @property (nonatomic, assign) double repayTotalPrice; 74 | /** 支付利息 */ 75 | @property (nonatomic, assign) double interestPayment; 76 | /** 按揭年数 */ 77 | @property (nonatomic, assign) double mortgageYear; 78 | /** 按揭月数 */ 79 | @property (nonatomic, assign) double mortgageMonth; 80 | /** 月均还款 */ 81 | @property (nonatomic, assign) double avgMonthRepayment; 82 | /** 首月还款 */ 83 | @property (nonatomic, assign) double firstMonthRepayment; 84 | /** 每月还款数组 */ 85 | @property (nonatomic, strong) NSMutableArray *monthRepaymentArr; 86 | 87 | @end 88 | 89 | 90 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo.xcodeproj/project.xcworkspace/xcuserdata/lxf.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo.xcodeproj/project.xcworkspace/xcuserdata/lxf.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo.xcodeproj/xcuserdata/lxf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo.xcodeproj/xcuserdata/lxf.xcuserdatad/xcschemes/LXFHouseLoanCalculatorDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo.xcodeproj/xcuserdata/lxf.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LXFHouseLoanCalculatorDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | FD97AF471F59C91100A50B2B 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "LXFCalculatorViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | 21 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 22 | self.window.backgroundColor = [UIColor lightGrayColor]; 23 | UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:[[LXFCalculatorViewController alloc] init]]; 24 | self.window.rootViewController = vc; 25 | [self.window makeKeyAndVisible]; 26 | 27 | return YES; 28 | } 29 | 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application { 32 | // 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. 33 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 34 | } 35 | 36 | 37 | - (void)applicationDidEnterBackground:(UIApplication *)application { 38 | // 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. 39 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 40 | } 41 | 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application { 44 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 45 | } 46 | 47 | 48 | - (void)applicationDidBecomeActive:(UIApplication *)application { 49 | // 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. 50 | } 51 | 52 | 53 | - (void)applicationWillTerminate:(UIApplication *)application { 54 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Category/NSArray+LXF.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+LXF.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (LXF) 12 | 13 | //以下写法均防止闪退 14 | + (instancetype)safeArrayWithObject:(id)object; 15 | 16 | - (id)safeObjectAtIndex:(NSUInteger)index; 17 | 18 | - (NSArray *)safeSubarrayWithRange:(NSRange)range; 19 | 20 | - (NSUInteger)safeIndexOfObject:(id)anObject; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Category/NSArray+LXF.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+LXF.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "NSArray+LXF.h" 10 | 11 | @implementation NSArray (LXF) 12 | 13 | - (id)safeObjectAtIndexedSubscript:(NSUInteger)index 14 | { 15 | if (index >= self.count) { 16 | return nil; 17 | } else { 18 | return [self objectAtIndex:index]; 19 | } 20 | } 21 | 22 | - (id)safeObjectAtIndex:(NSUInteger)index 23 | { 24 | if (index >= self.count) { 25 | return nil; 26 | } else { 27 | return [self objectAtIndex:index]; 28 | } 29 | } 30 | 31 | + (instancetype)safeArrayWithObject:(id)object 32 | { 33 | if (object == nil) { 34 | return [self array]; 35 | } else { 36 | return [self arrayWithObject:object]; 37 | } 38 | } 39 | 40 | - (NSArray *)safeSubarrayWithRange:(NSRange)range 41 | { 42 | NSUInteger location = range.location; 43 | NSUInteger length = range.length; 44 | if (location + length > self.count) { 45 | //超过了边界,就获取从loction开始所有的item 46 | if ((location + length) > self.count) { 47 | length = (self.count - location); 48 | return [self safeSubarrayWithRange:NSMakeRange(location, length)]; 49 | } 50 | 51 | return nil; 52 | } 53 | else { 54 | return [self subarrayWithRange:range]; 55 | } 56 | } 57 | 58 | - (NSUInteger)safeIndexOfObject:(id)anObject 59 | { 60 | if (anObject == nil) { 61 | return NSNotFound; 62 | } else { 63 | return [self indexOfObject:anObject]; 64 | } 65 | } 66 | 67 | // Log 68 | - (NSString *)descriptionWithLocale:(id)locale 69 | { 70 | NSMutableString *string = [NSMutableString string]; 71 | [string appendString:@"[\n"]; 72 | [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 73 | [string appendFormat:@"\t%@,\n", obj]; 74 | }]; 75 | [string appendString:@"]"]; 76 | NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch]; 77 | if (range.location != NSNotFound) 78 | [string deleteCharactersInRange:range]; 79 | 80 | return string; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Category/UITableViewCell+LXF.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableViewCell+LXF.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableViewCell (LXF) 12 | 13 | + (instancetype)loadCellFromNib:(UITableView *)tableView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Category/UITableViewCell+LXF.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableViewCell+LXF.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "UITableViewCell+LXF.h" 10 | #import "UIView+LXF.h" 11 | 12 | @implementation UITableViewCell (LXF) 13 | 14 | + (instancetype)loadCellFromNib:(UITableView *)tableView{ 15 | 16 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([self class])]; 17 | 18 | if (!cell) { 19 | cell = [self viewFromXib]; 20 | } 21 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 22 | return cell; 23 | } 24 | 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Category/UIView+LXF.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+LXF.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (LXF) 12 | 13 | + (instancetype)viewFromXib; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Category/UIView+LXF.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+LXF.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "UIView+LXF.h" 10 | 11 | @implementation UIView (LXF) 12 | 13 | + (instancetype)viewFromXib 14 | { 15 | return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject]; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/Base/LXFCalculatorBaseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorBaseViewController.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum : NSUInteger { 12 | HRCalculatorCalcTypeBusiness = 0, // 商业贷款 13 | HRCalculatorCalcTypeFund, // 公积金贷款 14 | HRCalculatorCalcTypeGroup, // 组合贷款 15 | } HRCalculatorCalcType; 16 | 17 | typedef enum : NSUInteger { 18 | HRCalculatorBaseCellTypeInput = 0, 19 | HRCalculatorBaseCellTypeSelectStr 20 | } HRCalculatorBaseCellType; 21 | 22 | // 还款方式 23 | #define kRepaymentMethods self.repaymentMethods 24 | // 计算方式 25 | #define kCalculateMethods self.calculateMethods 26 | // 按揭年数 27 | #define kMortgageYears self.mortgageYears 28 | // 按揭成数 29 | #define kMortgageMultis self.mortgageMultis 30 | 31 | @interface LXFCalculatorBaseViewController : UIViewController 32 | 33 | /** 计算方式是否为总价 */ 34 | @property (nonatomic, assign) BOOL isCalcMethodTotalPrice; 35 | /** 总价【TP】 */ 36 | @property (nonatomic, strong) NSArray *> *totalPriceArr; 37 | /** 单人和面积【UP】 */ 38 | @property (nonatomic, strong) NSArray *> *unitPriceArr; 39 | /** tpCellTypes */ 40 | @property (nonatomic, strong) NSArray *tpCellTypes; 41 | /** upCellTypes */ 42 | @property (nonatomic, strong) NSArray *upCellTypes; 43 | /** cell选项 */ 44 | @property (nonatomic, strong) NSMutableArray *> *tpSelectStrArr; 45 | /** cell选项 */ 46 | @property (nonatomic, strong) NSMutableArray *> *upSelectStrArr; 47 | /** 需要提交的值 */ 48 | @property (nonatomic, strong) NSMutableArray *> *tpValueArr; 49 | /** 需要提交的值 */ 50 | @property (nonatomic, strong) NSMutableArray *> *upValueArr; 51 | /** 单位数组 */ 52 | @property (nonatomic, strong) NSMutableArray *> *tpUnitArr; 53 | /** 单位数组 */ 54 | @property (nonatomic, strong) NSMutableArray *> *upUnitArr; 55 | 56 | /** tableView */ 57 | @property (nonatomic, strong) UITableView *tableView; 58 | 59 | /** 还款方式 */ 60 | @property (nonatomic, strong) NSArray *repaymentMethods; 61 | /** 计算方式 */ 62 | @property (nonatomic, strong) NSArray *calculateMethods; 63 | /** 按揭年数 */ 64 | @property (nonatomic, strong) NSArray *mortgageYears; 65 | /** 按揭成数 */ 66 | @property (nonatomic, strong) NSArray *mortgageMultis; 67 | 68 | #pragma mark 提交所需变量 69 | /** 还款方式 (0:等额本息 1:等额本金) */ 70 | @property (nonatomic, assign) int repayMethod; 71 | /** 单价 */ 72 | @property (nonatomic, assign) double unitPrice; 73 | /** 面积 */ 74 | @property (nonatomic, assign) double area; 75 | /** 商业贷款总额 */ 76 | @property (nonatomic, assign) double businessTotalPrice; 77 | /** 公积金贷款总额 */ 78 | @property (nonatomic, assign) double fundTotalPrice; 79 | /** 按揭年数 */ 80 | @property (nonatomic, assign) int mortgageYear; 81 | /** 按揭成数 */ 82 | @property (nonatomic, assign) int mortgageMulti; 83 | /** 银行利率 */ 84 | @property (nonatomic, assign) double bankRate; 85 | /** 公积金利率 */ 86 | @property (nonatomic, assign) double fundRate; 87 | 88 | #pragma mark - 待子类重写 89 | - (NSArray *> *)getTotalPriceArr; 90 | - (NSArray *> *)getUnitPriceArr; 91 | - (NSInteger)getHRCalculatorCalcType; 92 | // 处理选项数组数据专用 93 | - (void)handleSelectStr:(NSString *)selectStr indexPath:(NSIndexPath *)indexPath buttonIndex:(NSInteger)buttonIndex; 94 | // 处理输入数据专用 95 | - (void)handleInputStr:(NSString *)inputStr indexPath:(NSIndexPath *)indexPath; 96 | // 防止reloadData后textField变空 97 | - (double)getInputValueWithIndexPath:(NSIndexPath *)indexPath; 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorBusinessViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorBusinessViewController.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorBaseViewController.h" 10 | 11 | @interface LXFCalculatorBusinessViewController : LXFCalculatorBaseViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorBusinessViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorBusinessViewController.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorBusinessViewController.h" 10 | 11 | @interface LXFCalculatorBusinessViewController () 12 | 13 | @end 14 | 15 | @implementation LXFCalculatorBusinessViewController 16 | 17 | - (void)viewDidLoad { 18 | self.tpCellTypes = @[ 19 | @[@(HRCalculatorBaseCellTypeSelectStr)], 20 | @[ 21 | @(HRCalculatorBaseCellTypeSelectStr), 22 | @(HRCalculatorBaseCellTypeInput), 23 | @(HRCalculatorBaseCellTypeSelectStr), 24 | @(HRCalculatorBaseCellTypeInput) 25 | ] 26 | ]; 27 | 28 | self.upCellTypes = @[ 29 | @[@(HRCalculatorBaseCellTypeSelectStr)], 30 | @[ 31 | @(HRCalculatorBaseCellTypeSelectStr), 32 | @(HRCalculatorBaseCellTypeInput), 33 | @(HRCalculatorBaseCellTypeInput), 34 | @(HRCalculatorBaseCellTypeSelectStr), 35 | @(HRCalculatorBaseCellTypeSelectStr), 36 | @(HRCalculatorBaseCellTypeInput) 37 | ] 38 | ]; 39 | self.tpSelectStrArr[0][0] = kRepaymentMethods; 40 | self.tpSelectStrArr[1][0] = kCalculateMethods; 41 | self.tpSelectStrArr[1][2] = kMortgageYears; 42 | 43 | self.upSelectStrArr[0][0] = kRepaymentMethods; 44 | self.upSelectStrArr[1][0] = kCalculateMethods; 45 | self.upSelectStrArr[1][3] = kMortgageYears; 46 | self.upSelectStrArr[1][4] = kMortgageMultis; 47 | 48 | self.tpUnitArr[1][1] = @"元"; 49 | self.tpUnitArr[1][3] = @"%"; 50 | 51 | self.upUnitArr[1][1] = @"元"; 52 | self.upUnitArr[1][2] = @"㎡"; 53 | self.upUnitArr[1][5] = @"%"; 54 | 55 | self.tpValueArr[0][0] = kRepaymentMethods.firstObject; 56 | self.tpValueArr[1][0] = kCalculateMethods.firstObject; 57 | self.tpValueArr[1][2] = kMortgageYears.firstObject; 58 | 59 | self.upValueArr[0][0] = kRepaymentMethods.firstObject; 60 | self.upValueArr[1][0] = kCalculateMethods.firstObject; 61 | self.upValueArr[1][3] = kMortgageYears.firstObject; 62 | self.upValueArr[1][4] = kMortgageMultis.firstObject; 63 | 64 | [super viewDidLoad]; 65 | } 66 | 67 | - (NSInteger)getHRCalculatorCalcType { 68 | return HRCalculatorCalcTypeBusiness; 69 | } 70 | 71 | // 处理选项数组数据专用 72 | - (void)handleSelectStr:(NSString *)selectStr indexPath:(NSIndexPath *)indexPath buttonIndex:(NSInteger)buttonIndex { 73 | if (self.isCalcMethodTotalPrice) { 74 | if (indexPath.row == 2) { // 按揭年数 75 | self.mortgageYear = (int)(self.mortgageYears.count - buttonIndex + 1); 76 | } 77 | } else { 78 | if (indexPath.row == 3) { // 按揭年数 79 | self.mortgageYear = (int)(self.mortgageYears.count - buttonIndex + 1); 80 | } else if (indexPath.row == 4) { // 按揭成数 81 | self.mortgageMulti = (int)buttonIndex; 82 | } 83 | } 84 | } 85 | // 处理输入数据专用 86 | - (void)handleInputStr:(NSString *)inputStr indexPath:(NSIndexPath *)indexPath { 87 | double inputValue = [inputStr doubleValue]; 88 | if (self.isCalcMethodTotalPrice) { 89 | if (indexPath.row == 1) { // 商业贷款总额 90 | self.businessTotalPrice = inputValue; 91 | } else if (indexPath.row == 3) { // 银行利率 92 | self.bankRate = inputValue; 93 | } 94 | } else { 95 | if (indexPath.row == 1) { // 单价 96 | self.unitPrice = inputValue; 97 | } else if (indexPath.row == 2) { // 面积 98 | self.area = inputValue; 99 | } else if (indexPath.row == 5) { // 银行利率 100 | self.bankRate = inputValue; 101 | } 102 | } 103 | } 104 | 105 | // 防止reloadData后textField变空 106 | - (double)getInputValueWithIndexPath:(NSIndexPath *)indexPath { 107 | if (self.isCalcMethodTotalPrice) { 108 | if (indexPath.row == 1) { // 商业贷款总额 109 | return self.businessTotalPrice; 110 | } else if (indexPath.row == 3) { // 银行利率 111 | return self.bankRate; 112 | } 113 | } else { 114 | if (indexPath.row == 1) { // 单价 115 | return self.unitPrice; 116 | } else if (indexPath.row == 2) { // 面积 117 | return self.area; 118 | } else if (indexPath.row == 5) { // 银行利率 119 | return self.bankRate; 120 | } 121 | } 122 | return 0; 123 | } 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorFundViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorFundViewController.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorBaseViewController.h" 10 | 11 | @interface LXFCalculatorFundViewController : LXFCalculatorBaseViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorFundViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorFundViewController.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorFundViewController.h" 10 | 11 | @interface LXFCalculatorFundViewController () 12 | 13 | @end 14 | 15 | @implementation LXFCalculatorFundViewController 16 | 17 | - (void)viewDidLoad { 18 | self.tpCellTypes = @[ 19 | @[@(HRCalculatorBaseCellTypeSelectStr)], 20 | @[ 21 | @(HRCalculatorBaseCellTypeSelectStr), 22 | @(HRCalculatorBaseCellTypeInput), 23 | @(HRCalculatorBaseCellTypeSelectStr), 24 | @(HRCalculatorBaseCellTypeInput) 25 | ] 26 | ]; 27 | 28 | self.upCellTypes = @[ 29 | @[@(HRCalculatorBaseCellTypeSelectStr)], 30 | @[ 31 | @(HRCalculatorBaseCellTypeSelectStr), 32 | @(HRCalculatorBaseCellTypeInput), 33 | @(HRCalculatorBaseCellTypeInput), 34 | @(HRCalculatorBaseCellTypeSelectStr), 35 | @(HRCalculatorBaseCellTypeSelectStr), 36 | @(HRCalculatorBaseCellTypeInput) 37 | ] 38 | ]; 39 | self.tpSelectStrArr[0][0] = kRepaymentMethods; 40 | self.tpSelectStrArr[1][0] = kCalculateMethods; 41 | self.tpSelectStrArr[1][2] = kMortgageYears; 42 | 43 | self.upSelectStrArr[0][0] = kRepaymentMethods; 44 | self.upSelectStrArr[1][0] = kCalculateMethods; 45 | self.upSelectStrArr[1][3] = kMortgageYears; 46 | self.upSelectStrArr[1][4] = kMortgageMultis; 47 | 48 | self.tpUnitArr[1][1] = @"元"; 49 | self.tpUnitArr[1][3] = @"%"; 50 | 51 | self.upUnitArr[1][1] = @"元"; 52 | self.upUnitArr[1][2] = @"㎡"; 53 | self.upUnitArr[1][5] = @"%"; 54 | 55 | self.tpValueArr[0][0] = kRepaymentMethods.firstObject; 56 | self.tpValueArr[1][0] = kCalculateMethods.firstObject; 57 | self.tpValueArr[1][2] = kMortgageYears.firstObject; 58 | 59 | self.upValueArr[0][0] = kRepaymentMethods.firstObject; 60 | self.upValueArr[1][0] = kCalculateMethods.firstObject; 61 | self.upValueArr[1][3] = kMortgageYears.firstObject; 62 | self.upValueArr[1][4] = kMortgageMultis.firstObject; 63 | 64 | [super viewDidLoad]; 65 | } 66 | 67 | - (NSArray *> *)getTotalPriceArr { 68 | return @[ 69 | @[@"还款方式"], 70 | @[@"计算方式",@"贷款总额",@"按揭年数",@"公积金利率"] 71 | ]; 72 | } 73 | - (NSArray *> *)getUnitPriceArr { 74 | return @[ 75 | @[@"还款方式"], 76 | @[@"计算方式",@"单价",@"面积",@"按揭年数",@"按揭成数",@"公积金利率"] 77 | ]; 78 | } 79 | - (NSInteger)getHRCalculatorCalcType { 80 | return HRCalculatorCalcTypeFund; 81 | } 82 | 83 | // 处理选项数组数据专用 84 | - (void)handleSelectStr:(NSString *)selectStr indexPath:(NSIndexPath *)indexPath buttonIndex:(NSInteger)buttonIndex { 85 | if (self.isCalcMethodTotalPrice) { 86 | if (indexPath.row == 2) { // 按揭年数 87 | self.mortgageYear = (int)(self.mortgageYears.count - buttonIndex + 1); 88 | } 89 | } else { 90 | if (indexPath.row == 3) { // 按揭年数 91 | self.mortgageYear = (int)(self.mortgageYears.count - buttonIndex + 1); 92 | } else if (indexPath.row == 4) { // 按揭成数 93 | self.mortgageMulti = (int)buttonIndex; 94 | } 95 | } 96 | } 97 | // 处理输入数据专用 98 | - (void)handleInputStr:(NSString *)inputStr indexPath:(NSIndexPath *)indexPath { 99 | double inputValue = [inputStr doubleValue]; 100 | if (self.isCalcMethodTotalPrice) { 101 | if (indexPath.row == 1) { // 公积金贷款总额 102 | self.fundTotalPrice = inputValue; 103 | } else if (indexPath.row == 3) { // 公积金利率 104 | self.fundRate = inputValue; 105 | } 106 | } else { 107 | if (indexPath.row == 1) { // 单价 108 | self.unitPrice = inputValue; 109 | } else if (indexPath.row == 2) { // 面积 110 | self.area = inputValue; 111 | } else if (indexPath.row == 5) { // 公积金利率 112 | self.fundRate = inputValue; 113 | } 114 | } 115 | } 116 | 117 | // 防止reloadData后textField变空 118 | - (double)getInputValueWithIndexPath:(NSIndexPath *)indexPath { 119 | if (self.isCalcMethodTotalPrice) { 120 | if (indexPath.row == 1) { // 商业贷款总额 121 | return self.fundTotalPrice; 122 | } else if (indexPath.row == 3) { // 银行利率 123 | return self.fundRate; 124 | } 125 | } else { 126 | if (indexPath.row == 1) { // 单价 127 | return self.unitPrice; 128 | } else if (indexPath.row == 2) { // 面积 129 | return self.area; 130 | } else if (indexPath.row == 5) { // 公积金利率 131 | return self.fundRate; 132 | } 133 | } 134 | return 0; 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorGroupViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorGroupViewController.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorBaseViewController.h" 10 | 11 | @interface LXFCalculatorGroupViewController : LXFCalculatorBaseViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorGroupViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorGroupViewController.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorGroupViewController.h" 10 | 11 | @interface LXFCalculatorGroupViewController () 12 | 13 | @end 14 | 15 | @implementation LXFCalculatorGroupViewController 16 | 17 | - (void)viewDidLoad { 18 | self.tpCellTypes = @[ 19 | @[@(HRCalculatorBaseCellTypeSelectStr)], 20 | @[ 21 | @(HRCalculatorBaseCellTypeInput), 22 | @(HRCalculatorBaseCellTypeInput), 23 | @(HRCalculatorBaseCellTypeSelectStr), 24 | @(HRCalculatorBaseCellTypeInput), 25 | @(HRCalculatorBaseCellTypeInput) 26 | ] 27 | ]; 28 | 29 | self.tpSelectStrArr[0][0] = kRepaymentMethods; 30 | self.tpSelectStrArr[1][2] = kMortgageYears; 31 | 32 | self.tpUnitArr[1][0] = @"元"; 33 | self.tpUnitArr[1][1] = @"元"; 34 | self.tpUnitArr[1][3] = @"%"; 35 | self.tpUnitArr[1][4] = @"%"; 36 | 37 | 38 | self.tpValueArr[0][0] = kRepaymentMethods.firstObject; 39 | self.tpValueArr[1][2] = kMortgageYears.firstObject; 40 | 41 | [super viewDidLoad]; 42 | } 43 | 44 | - (NSArray *> *)getTotalPriceArr { 45 | return @[ 46 | @[@"还款方式"], 47 | @[@"商业贷款总额",@"公积金贷款总额",@"按揭年数",@"银行利率", @"公积金利率"] 48 | ]; 49 | } 50 | - (NSInteger)getHRCalculatorCalcType { 51 | return HRCalculatorCalcTypeGroup; 52 | } 53 | 54 | // 处理选项数组数据专用 55 | - (void)handleSelectStr:(NSString *)selectStr indexPath:(NSIndexPath *)indexPath buttonIndex:(NSInteger)buttonIndex { 56 | if (indexPath.row == 2) { // 按揭年数 57 | self.mortgageYear = (int)(self.mortgageYears.count - buttonIndex + 1); 58 | } 59 | } 60 | // 处理输入数据专用 61 | - (void)handleInputStr:(NSString *)inputStr indexPath:(NSIndexPath *)indexPath { 62 | double inputValue = [inputStr doubleValue]; 63 | 64 | if (indexPath.row == 0) { // 商业贷款总额 65 | self.businessTotalPrice = inputValue; 66 | } else if (indexPath.row == 1) { // 公积金贷款总额 67 | self.fundTotalPrice = inputValue; 68 | } else if (indexPath.row == 3) { // 银行利率 69 | self.bankRate = inputValue; 70 | } else if (indexPath.row == 4) { // 公积金利率 71 | self.fundRate = inputValue; 72 | } 73 | } 74 | 75 | // 防止reloadData后textField变空 76 | - (double)getInputValueWithIndexPath:(NSIndexPath *)indexPath { 77 | if (indexPath.row == 0) { // 商业贷款总额 78 | return self.businessTotalPrice; 79 | } else if (indexPath.row == 1) { // 公积金贷款总额 80 | return self.fundTotalPrice; 81 | } else if (indexPath.row == 3) { // 银行利率 82 | return self.bankRate; 83 | } else if (indexPath.row == 4) { // 公积金利率 84 | return self.fundRate; 85 | } 86 | return 0; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorViewController.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "XLBasePageController.h" 10 | 11 | @interface LXFCalculatorViewController : XLBasePageController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Controller/LXFCalculatorViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorViewController.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorViewController.h" 10 | 11 | #import "LXFCalculatorBusinessViewController.h" 12 | #import "LXFCalculatorFundViewController.h" 13 | #import "LXFCalculatorGroupViewController.h" 14 | 15 | @interface LXFCalculatorViewController () 16 | 17 | @property (nonatomic,strong) NSArray *titleArray; 18 | 19 | @end 20 | 21 | @implementation LXFCalculatorViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | 26 | self.titleArray = @[@"商业贷款",@"公积金贷款",@"组合贷款"]; 27 | self.delegate = self; 28 | self.dataSource = self; 29 | 30 | //self.lineWidth = 2.0;//选中下划线宽度 31 | self.titleFont = [UIFont systemFontOfSize:16.0]; 32 | self.defaultColor = [UIColor blackColor];//默认字体颜色 33 | self.chooseColor = [UIColor redColor];//选中字体颜色 34 | self.selectIndex = 0;//默认选中第几页 35 | 36 | [self reloadScrollPage]; 37 | 38 | self.navigationItem.title = @"房贷计算器"; 39 | } 40 | 41 | -(NSInteger)numberViewControllersInViewPager:(XLBasePageController *)viewPager 42 | { 43 | return _titleArray.count; 44 | } 45 | 46 | - (UIViewController *)viewPager:(XLBasePageController *)viewPager indexViewControllers:(NSInteger)index 47 | { 48 | if (index == 0) { 49 | LXFCalculatorBusinessViewController *businessVC = [[LXFCalculatorBusinessViewController alloc] init]; 50 | return businessVC; 51 | }if (index == 1) { 52 | LXFCalculatorFundViewController *fundVC = [[LXFCalculatorFundViewController alloc] init]; 53 | return fundVC; 54 | } 55 | else{ 56 | LXFCalculatorGroupViewController *groupVC = [[LXFCalculatorGroupViewController alloc] init]; 57 | return groupVC; 58 | } 59 | } 60 | 61 | -(CGFloat)heightForTitleViewPager:(XLBasePageController *)viewPager 62 | { 63 | return 50; 64 | } 65 | 66 | -(NSString *)viewPager:(XLBasePageController *)viewPager titleWithIndexViewControllers:(NSInteger)index 67 | { 68 | return self.titleArray[index]; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/LCActionSheetCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // LCActionSheetCell.h 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 2016/7/15. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import 29 | 30 | 31 | #define LC_ACTION_SHEET_CELL_NO_HIDDE_LINE_TAG 100 32 | #define LC_ACTION_SHEET_CELL_HIDDE_LINE_TAG 101 33 | 34 | NS_ASSUME_NONNULL_BEGIN 35 | 36 | @interface LCActionSheetCell : UITableViewCell 37 | 38 | /** 39 | Title label. 40 | */ 41 | @property (nonatomic, weak) UILabel *titleLabel; 42 | 43 | /** 44 | Line. 45 | */ 46 | @property (nonatomic, weak) UIView *lineView; 47 | 48 | /** 49 | Cell's separator color. 50 | */ 51 | @property (nonatomic, strong) UIColor *cellSeparatorColor; 52 | 53 | @end 54 | 55 | NS_ASSUME_NONNULL_END 56 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/LCActionSheetCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // LCActionSheetCell.m 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 2016/7/15. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import "LCActionSheetCell.h" 29 | #import "Masonry.h" 30 | #import "LCActionSheetConfig.h" 31 | 32 | @interface LCActionSheetCell () 33 | 34 | /** 35 | * Highlighted View. 36 | */ 37 | @property (nonatomic, weak) UIView *highlightedView; 38 | 39 | @end 40 | 41 | @implementation LCActionSheetCell 42 | 43 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 44 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 45 | self.clipsToBounds = YES; 46 | self.backgroundColor = [UIColor clearColor]; 47 | 48 | UIView *highlightedView = [[UIView alloc] init]; 49 | highlightedView.backgroundColor = self.cellSeparatorColor; 50 | highlightedView.clipsToBounds = YES; 51 | highlightedView.hidden = YES; 52 | [self.contentView addSubview:highlightedView]; 53 | self.highlightedView = highlightedView; 54 | [highlightedView mas_makeConstraints:^(MASConstraintMaker *make) { 55 | make.edges.equalTo(self.contentView); 56 | }]; 57 | 58 | UILabel *titleLabel = [[UILabel alloc] init]; 59 | titleLabel.textAlignment = NSTextAlignmentCenter; 60 | titleLabel.adjustsFontSizeToFitWidth = YES; 61 | [self.contentView addSubview:titleLabel]; 62 | self.titleLabel = titleLabel; 63 | [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { 64 | make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 10.0f, 0, 10.0f)); 65 | }]; 66 | 67 | UIView *lineView = [[UIView alloc] init]; 68 | lineView.backgroundColor = self.cellSeparatorColor; 69 | lineView.contentMode = UIViewContentModeBottom; 70 | lineView.clipsToBounds = YES; 71 | [self.contentView addSubview:lineView]; 72 | self.lineView = lineView; 73 | [lineView mas_makeConstraints:^(MASConstraintMaker *make) { 74 | make.left.right.bottom.equalTo(self.contentView); 75 | make.height.equalTo(@0.5f); 76 | }]; 77 | } 78 | return self; 79 | } 80 | 81 | - (void)setCellSeparatorColor:(UIColor *)cellSeparatorColor { 82 | _cellSeparatorColor = cellSeparatorColor; 83 | 84 | self.highlightedView.backgroundColor = cellSeparatorColor; 85 | self.lineView.backgroundColor = cellSeparatorColor; 86 | } 87 | 88 | - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 89 | if (self.tag == LC_ACTION_SHEET_CELL_HIDDE_LINE_TAG) { 90 | self.lineView.hidden = YES; 91 | } else { 92 | self.lineView.hidden = highlighted; 93 | } 94 | 95 | self.highlightedView.hidden = !highlighted; 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/LCActionSheetConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // LCActionSheetConfig.h 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 2016/11/29. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import 29 | 30 | 31 | #define LC_ACTION_SHEET_COLOR(r, g, b) LC_ACTION_SHEET_COLOR_A(r, g, b, 1.0f) 32 | #define LC_ACTION_SHEET_COLOR_A(r, g, b, a) [UIColor colorWithRed:(r)/255.0f\ 33 | green:(g)/255.0f\ 34 | blue:(b)/255.0f\ 35 | alpha:a] 36 | 37 | 38 | NS_ASSUME_NONNULL_BEGIN 39 | 40 | @interface LCActionSheetConfig : NSObject 41 | 42 | /** 43 | Title. 44 | */ 45 | @property (nullable, nonatomic, copy) NSString *title; 46 | 47 | /** 48 | Cancel button's title. 49 | */ 50 | @property (nullable, nonatomic, copy) NSString *cancelButtonTitle; 51 | 52 | /** 53 | Cancel button's index. 54 | */ 55 | @property (nonatomic, assign, readonly) NSInteger cancelButtonIndex; 56 | 57 | /** 58 | All destructive buttons' set. You should give it the `NSNumber` type items. 59 | */ 60 | @property (nullable, nonatomic, strong) NSIndexSet *destructiveButtonIndexSet; 61 | 62 | /** 63 | Destructive button's color. Default is RGB(254, 67, 37). 64 | */ 65 | @property (nonatomic, strong) UIColor *destructiveButtonColor; 66 | 67 | /** 68 | Title's color. Default is `[UIColor blackColor]`. 69 | */ 70 | @property (nonatomic, strong) UIColor *titleColor; 71 | /** 72 | Buttons' color, without destructive buttons. Default is `[UIColor blackColor]`. 73 | */ 74 | @property (nonatomic, strong) UIColor *buttonColor; 75 | /** 76 | Title's font. Default is `[UIFont systemFontOfSize:14.0f]`. 77 | */ 78 | @property (nonatomic, strong) UIFont *titleFont; 79 | /** 80 | All buttons' font. Default is `[UIFont systemFontOfSize:18.0f]`. 81 | */ 82 | @property (nonatomic, strong) UIFont *buttonFont; 83 | /** 84 | All buttons' height. Default is 49.0f; 85 | */ 86 | @property (nonatomic, assign) CGFloat buttonHeight; 87 | 88 | /** 89 | If buttons' bottom view can scrolling. Default is NO. 90 | */ 91 | @property (nonatomic, assign, getter=canScrolling) BOOL scrolling; 92 | 93 | /** 94 | Visible buttons' count. You have to set `scrolling = YES` if you want to set it. 95 | */ 96 | @property (nonatomic, assign) CGFloat visibleButtonCount; 97 | 98 | /** 99 | Animation duration. Default is 0.3 seconds. 100 | */ 101 | @property (nonatomic, assign) CGFloat animationDuration; 102 | 103 | /** 104 | Opacity of dark background. Default is 0.3f. 105 | */ 106 | @property (nonatomic, assign) CGFloat darkOpacity; 107 | 108 | /** 109 | If you can tap darkView to dismiss. Defalut is NO, you can tap dardView to dismiss. 110 | */ 111 | @property (nonatomic, assign) BOOL darkViewNoTaped; 112 | 113 | /** 114 | Clear blur effect. Default is NO, don't clear blur effect. 115 | */ 116 | @property (nonatomic, assign) BOOL unBlur; 117 | 118 | /** 119 | Style of blur effect. Default is `UIBlurEffectStyleExtraLight`. iOS 8.0 + 120 | */ 121 | @property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle; 122 | 123 | /** 124 | Title's edge insets. Default is `UIEdgeInsetsMake(15.0f, 15.0f, 15.0f, 15.0f)`. 125 | */ 126 | @property (nonatomic, assign) UIEdgeInsets titleEdgeInsets; 127 | 128 | /** 129 | Cell's separator color. Default is `RGBA(170/255.0f, 170/255.0f, 170/255.0f, 0.5f)`. 130 | */ 131 | @property (nonatomic, strong) UIColor *separatorColor; 132 | 133 | /** 134 | Title can be limit in titleLinesNumber. Default is 0. 135 | */ 136 | @property (nonatomic, assign) NSInteger titleLinesNumber; 137 | 138 | /** 139 | Auto hide when the device rotated. Default is NO, won't auto hide. 140 | */ 141 | @property (nonatomic, assign) BOOL autoHideWhenDeviceRotated; 142 | 143 | /** 144 | LCActionSheetConfig shared instance. 145 | */ 146 | @property (class, nonatomic, strong, readonly) LCActionSheetConfig *config; 147 | 148 | /** 149 | LCActionSheetConfig shared instance. 150 | */ 151 | + (instancetype)shared __deprecated_msg("Method deprecated. Use property `config` instead."); 152 | 153 | @end 154 | 155 | NS_ASSUME_NONNULL_END 156 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/LCActionSheetConfig.m: -------------------------------------------------------------------------------- 1 | // 2 | // LCActionSheetConfig.m 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 2016/11/29. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import "LCActionSheetConfig.h" 29 | 30 | 31 | #define LC_ACTION_SHEET_BUTTON_HEIGHT 49.0f 32 | 33 | #define LC_ACTION_SHEET_RED_COLOR LC_ACTION_SHEET_COLOR(254, 67, 37) 34 | 35 | #define LC_ACTION_SHEET_TITLE_FONT [UIFont systemFontOfSize:14.0f] 36 | 37 | #define LC_ACTION_SHEET_BUTTON_FONT [UIFont systemFontOfSize:18.0f] 38 | 39 | #define LC_ACTION_SHEET_ANIMATION_DURATION 0.3f 40 | 41 | #define LC_ACTION_SHEET_DARK_OPACITY 0.3f 42 | 43 | 44 | @implementation LCActionSheetConfig 45 | 46 | + (LCActionSheetConfig *)config { 47 | static id _config = nil; 48 | static dispatch_once_t onceToken; 49 | dispatch_once(&onceToken, ^{ 50 | _config = [[self alloc] initSharedInstance]; 51 | }); 52 | return _config; 53 | } 54 | 55 | + (instancetype)shared { 56 | return self.config; 57 | } 58 | 59 | - (instancetype)initSharedInstance { 60 | if (self = [super init]) { 61 | self.titleFont = LC_ACTION_SHEET_TITLE_FONT; 62 | self.buttonFont = LC_ACTION_SHEET_BUTTON_FONT; 63 | self.destructiveButtonColor = LC_ACTION_SHEET_RED_COLOR; 64 | self.titleColor = LC_ACTION_SHEET_COLOR(111, 111, 111); 65 | self.buttonColor = [UIColor blackColor]; 66 | 67 | self.buttonHeight = LC_ACTION_SHEET_BUTTON_HEIGHT; 68 | self.animationDuration = LC_ACTION_SHEET_ANIMATION_DURATION; 69 | self.darkOpacity = LC_ACTION_SHEET_DARK_OPACITY; 70 | 71 | self.titleEdgeInsets = UIEdgeInsetsMake(15.0f, 15.0f, 15.0f, 15.0f); 72 | 73 | self.separatorColor = LC_ACTION_SHEET_COLOR_A(150, 150, 150, 0.3f); 74 | } 75 | return self; 76 | } 77 | 78 | - (instancetype)init { 79 | return LCActionSheetConfig.config; 80 | } 81 | 82 | - (NSInteger)cancelButtonIndex { 83 | return 0; 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/LCActionSheetViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LCActionSheetViewController.h 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 12/05/2017. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import 29 | 30 | 31 | NS_ASSUME_NONNULL_BEGIN 32 | 33 | @interface LCActionSheetViewController : UIViewController 34 | 35 | /** 36 | Status bar hidden. Same as the original. 37 | */ 38 | @property (nonatomic, assign) BOOL statusBarHidden; 39 | 40 | /** 41 | Status bar style. Same as the original. 42 | */ 43 | @property (nonatomic, assign) UIStatusBarStyle statusBarStyle; 44 | 45 | @end 46 | 47 | NS_ASSUME_NONNULL_END 48 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/LCActionSheetViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LCActionSheetViewController.m 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 12/05/2017. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import "LCActionSheetViewController.h" 29 | 30 | @implementation LCActionSheetViewController 31 | 32 | - (BOOL)prefersStatusBarHidden { 33 | return self.statusBarHidden; 34 | } 35 | 36 | - (UIStatusBarStyle)preferredStatusBarStyle { 37 | return self.statusBarStyle; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/UIImage+LCActionSheet.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+LCActionSheet.h 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 2016/11/29. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import 29 | 30 | 31 | NS_ASSUME_NONNULL_BEGIN 32 | 33 | @interface UIImage (LCActionSheet) 34 | 35 | /** 36 | Create a image with the color. 37 | */ 38 | + (nullable instancetype)lc_imageWithColor:(UIColor *)color; 39 | 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/LCActionSheet/UIImage+LCActionSheet.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+LCActionSheet.m 3 | // LCActionSheet 4 | // 5 | // Created by Leo on 2016/11/29. 6 | // 7 | // Copyright (c) 2015-2017 Leo 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 all 17 | // 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 THE 25 | // SOFTWARE. 26 | 27 | 28 | #import "UIImage+LCActionSheet.h" 29 | 30 | @implementation UIImage (LCActionSheet) 31 | 32 | + (instancetype)lc_imageWithColor:(UIColor *)color { 33 | CGRect rect = CGRectMake(0.0f, 0.0f, 2.0f, 2.0f); 34 | 35 | UIGraphicsBeginImageContext(rect.size); 36 | CGContextRef context = UIGraphicsGetCurrentContext(); 37 | CGContextSetFillColorWithColor(context, [color CGColor]); 38 | CGContextFillRect(context, rect); 39 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 40 | UIGraphicsEndImageContext(); 41 | 42 | return image; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASCompositeConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | /** 13 | * A group of MASConstraint objects 14 | */ 15 | @interface MASCompositeConstraint : MASConstraint 16 | 17 | /** 18 | * Creates a composite with a predefined array of children 19 | * 20 | * @param children child MASConstraints 21 | * 22 | * @return a composite constraint 23 | */ 24 | - (id)initWithChildren:(NSArray *)children; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASCompositeConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASCompositeConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASCompositeConstraint.h" 10 | #import "MASConstraint+Private.h" 11 | 12 | @interface MASCompositeConstraint () 13 | 14 | @property (nonatomic, strong) id mas_key; 15 | @property (nonatomic, strong) NSMutableArray *childConstraints; 16 | 17 | @end 18 | 19 | @implementation MASCompositeConstraint 20 | 21 | - (id)initWithChildren:(NSArray *)children { 22 | self = [super init]; 23 | if (!self) return nil; 24 | 25 | _childConstraints = [children mutableCopy]; 26 | for (MASConstraint *constraint in _childConstraints) { 27 | constraint.delegate = self; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | #pragma mark - MASConstraintDelegate 34 | 35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 36 | NSUInteger index = [self.childConstraints indexOfObject:constraint]; 37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint]; 39 | } 40 | 41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 42 | id strongDelegate = self.delegate; 43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 44 | newConstraint.delegate = self; 45 | [self.childConstraints addObject:newConstraint]; 46 | return newConstraint; 47 | } 48 | 49 | #pragma mark - NSLayoutConstraint multiplier proxies 50 | 51 | - (MASConstraint * (^)(CGFloat))multipliedBy { 52 | return ^id(CGFloat multiplier) { 53 | for (MASConstraint *constraint in self.childConstraints) { 54 | constraint.multipliedBy(multiplier); 55 | } 56 | return self; 57 | }; 58 | } 59 | 60 | - (MASConstraint * (^)(CGFloat))dividedBy { 61 | return ^id(CGFloat divider) { 62 | for (MASConstraint *constraint in self.childConstraints) { 63 | constraint.dividedBy(divider); 64 | } 65 | return self; 66 | }; 67 | } 68 | 69 | #pragma mark - MASLayoutPriority proxy 70 | 71 | - (MASConstraint * (^)(MASLayoutPriority))priority { 72 | return ^id(MASLayoutPriority priority) { 73 | for (MASConstraint *constraint in self.childConstraints) { 74 | constraint.priority(priority); 75 | } 76 | return self; 77 | }; 78 | } 79 | 80 | #pragma mark - NSLayoutRelation proxy 81 | 82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { 83 | return ^id(id attr, NSLayoutRelation relation) { 84 | for (MASConstraint *constraint in self.childConstraints.copy) { 85 | constraint.equalToWithRelation(attr, relation); 86 | } 87 | return self; 88 | }; 89 | } 90 | 91 | #pragma mark - attribute chaining 92 | 93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; 95 | return self; 96 | } 97 | 98 | #pragma mark - Animator proxy 99 | 100 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 101 | 102 | - (MASConstraint *)animator { 103 | for (MASConstraint *constraint in self.childConstraints) { 104 | [constraint animator]; 105 | } 106 | return self; 107 | } 108 | 109 | #endif 110 | 111 | #pragma mark - debug helpers 112 | 113 | - (MASConstraint * (^)(id))key { 114 | return ^id(id key) { 115 | self.mas_key = key; 116 | int i = 0; 117 | for (MASConstraint *constraint in self.childConstraints) { 118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]); 119 | } 120 | return self; 121 | }; 122 | } 123 | 124 | #pragma mark - NSLayoutConstraint constant setters 125 | 126 | - (void)setInsets:(MASEdgeInsets)insets { 127 | for (MASConstraint *constraint in self.childConstraints) { 128 | constraint.insets = insets; 129 | } 130 | } 131 | 132 | - (void)setOffset:(CGFloat)offset { 133 | for (MASConstraint *constraint in self.childConstraints) { 134 | constraint.offset = offset; 135 | } 136 | } 137 | 138 | - (void)setSizeOffset:(CGSize)sizeOffset { 139 | for (MASConstraint *constraint in self.childConstraints) { 140 | constraint.sizeOffset = sizeOffset; 141 | } 142 | } 143 | 144 | - (void)setCenterOffset:(CGPoint)centerOffset { 145 | for (MASConstraint *constraint in self.childConstraints) { 146 | constraint.centerOffset = centerOffset; 147 | } 148 | } 149 | 150 | #pragma mark - MASConstraint 151 | 152 | - (void)activate { 153 | for (MASConstraint *constraint in self.childConstraints) { 154 | [constraint activate]; 155 | } 156 | } 157 | 158 | - (void)deactivate { 159 | for (MASConstraint *constraint in self.childConstraints) { 160 | [constraint deactivate]; 161 | } 162 | } 163 | 164 | - (void)install { 165 | for (MASConstraint *constraint in self.childConstraints) { 166 | constraint.updateExisting = self.updateExisting; 167 | [constraint install]; 168 | } 169 | } 170 | 171 | - (void)uninstall { 172 | for (MASConstraint *constraint in self.childConstraints) { 173 | [constraint uninstall]; 174 | } 175 | } 176 | 177 | @end 178 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASConstraint+Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint+Private.h 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 29/04/14. 6 | // Copyright (c) 2014 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | 11 | @protocol MASConstraintDelegate; 12 | 13 | 14 | @interface MASConstraint () 15 | 16 | /** 17 | * Whether or not to check for an existing constraint instead of adding constraint 18 | */ 19 | @property (nonatomic, assign) BOOL updateExisting; 20 | 21 | /** 22 | * Usually MASConstraintMaker but could be a parent MASConstraint 23 | */ 24 | @property (nonatomic, weak) id delegate; 25 | 26 | /** 27 | * Based on a provided value type, is equal to calling: 28 | * NSNumber - setOffset: 29 | * NSValue with CGPoint - setPointOffset: 30 | * NSValue with CGSize - setSizeOffset: 31 | * NSValue with MASEdgeInsets - setInsets: 32 | */ 33 | - (void)setLayoutConstantWithValue:(NSValue *)value; 34 | 35 | @end 36 | 37 | 38 | @interface MASConstraint (Abstract) 39 | 40 | /** 41 | * Sets the constraint relation to given NSLayoutRelation 42 | * returns a block which accepts one of the following: 43 | * MASViewAttribute, UIView, NSValue, NSArray 44 | * see readme for more details. 45 | */ 46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation; 47 | 48 | /** 49 | * Override to set a custom chaining behaviour 50 | */ 51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 52 | 53 | @end 54 | 55 | 56 | @protocol MASConstraintDelegate 57 | 58 | /** 59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example 60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks 61 | */ 62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint; 63 | 64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * Enables Constraints to be created with chainable syntax 13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint) 14 | * or a group of NSLayoutConstraints (MASComposisteConstraint) 15 | */ 16 | @interface MASConstraint : NSObject 17 | 18 | // Chaining Support 19 | 20 | /** 21 | * Modifies the NSLayoutConstraint constant, 22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 24 | */ 25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets; 26 | 27 | /** 28 | * Modifies the NSLayoutConstraint constant, 29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 31 | */ 32 | - (MASConstraint * (^)(CGSize offset))sizeOffset; 33 | 34 | /** 35 | * Modifies the NSLayoutConstraint constant, 36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 38 | */ 39 | - (MASConstraint * (^)(CGPoint offset))centerOffset; 40 | 41 | /** 42 | * Modifies the NSLayoutConstraint constant 43 | */ 44 | - (MASConstraint * (^)(CGFloat offset))offset; 45 | 46 | /** 47 | * Modifies the NSLayoutConstraint constant based on a value type 48 | */ 49 | - (MASConstraint * (^)(NSValue *value))valueOffset; 50 | 51 | /** 52 | * Sets the NSLayoutConstraint multiplier property 53 | */ 54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy; 55 | 56 | /** 57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy 58 | */ 59 | - (MASConstraint * (^)(CGFloat divider))dividedBy; 60 | 61 | /** 62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority 63 | */ 64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority; 65 | 66 | /** 67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow 68 | */ 69 | - (MASConstraint * (^)())priorityLow; 70 | 71 | /** 72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium 73 | */ 74 | - (MASConstraint * (^)())priorityMedium; 75 | 76 | /** 77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh 78 | */ 79 | - (MASConstraint * (^)())priorityHigh; 80 | 81 | /** 82 | * Sets the constraint relation to NSLayoutRelationEqual 83 | * returns a block which accepts one of the following: 84 | * MASViewAttribute, UIView, NSValue, NSArray 85 | * see readme for more details. 86 | */ 87 | - (MASConstraint * (^)(id attr))equalTo; 88 | 89 | /** 90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual 91 | * returns a block which accepts one of the following: 92 | * MASViewAttribute, UIView, NSValue, NSArray 93 | * see readme for more details. 94 | */ 95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo; 96 | 97 | /** 98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual 99 | * returns a block which accepts one of the following: 100 | * MASViewAttribute, UIView, NSValue, NSArray 101 | * see readme for more details. 102 | */ 103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo; 104 | 105 | /** 106 | * Optional semantic property which has no effect but improves the readability of constraint 107 | */ 108 | - (MASConstraint *)with; 109 | 110 | /** 111 | * Optional semantic property which has no effect but improves the readability of constraint 112 | */ 113 | - (MASConstraint *)and; 114 | 115 | /** 116 | * Creates a new MASCompositeConstraint with the called attribute and reciever 117 | */ 118 | - (MASConstraint *)left; 119 | - (MASConstraint *)top; 120 | - (MASConstraint *)right; 121 | - (MASConstraint *)bottom; 122 | - (MASConstraint *)leading; 123 | - (MASConstraint *)trailing; 124 | - (MASConstraint *)width; 125 | - (MASConstraint *)height; 126 | - (MASConstraint *)centerX; 127 | - (MASConstraint *)centerY; 128 | - (MASConstraint *)baseline; 129 | 130 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 131 | 132 | - (MASConstraint *)firstBaseline; 133 | - (MASConstraint *)lastBaseline; 134 | 135 | #endif 136 | 137 | #if TARGET_OS_IPHONE || TARGET_OS_TV 138 | 139 | - (MASConstraint *)leftMargin; 140 | - (MASConstraint *)rightMargin; 141 | - (MASConstraint *)topMargin; 142 | - (MASConstraint *)bottomMargin; 143 | - (MASConstraint *)leadingMargin; 144 | - (MASConstraint *)trailingMargin; 145 | - (MASConstraint *)centerXWithinMargins; 146 | - (MASConstraint *)centerYWithinMargins; 147 | 148 | #endif 149 | 150 | 151 | /** 152 | * Sets the constraint debug name 153 | */ 154 | - (MASConstraint * (^)(id key))key; 155 | 156 | // NSLayoutConstraint constant Setters 157 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks 158 | 159 | /** 160 | * Modifies the NSLayoutConstraint constant, 161 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 162 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight 163 | */ 164 | - (void)setInsets:(MASEdgeInsets)insets; 165 | 166 | /** 167 | * Modifies the NSLayoutConstraint constant, 168 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 169 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight 170 | */ 171 | - (void)setSizeOffset:(CGSize)sizeOffset; 172 | 173 | /** 174 | * Modifies the NSLayoutConstraint constant, 175 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 176 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY 177 | */ 178 | - (void)setCenterOffset:(CGPoint)centerOffset; 179 | 180 | /** 181 | * Modifies the NSLayoutConstraint constant 182 | */ 183 | - (void)setOffset:(CGFloat)offset; 184 | 185 | 186 | // NSLayoutConstraint Installation support 187 | 188 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 189 | /** 190 | * Whether or not to go through the animator proxy when modifying the constraint 191 | */ 192 | @property (nonatomic, copy, readonly) MASConstraint *animator; 193 | #endif 194 | 195 | /** 196 | * Activates an NSLayoutConstraint if it's supported by an OS. 197 | * Invokes install otherwise. 198 | */ 199 | - (void)activate; 200 | 201 | /** 202 | * Deactivates previously installed/activated NSLayoutConstraint. 203 | */ 204 | - (void)deactivate; 205 | 206 | /** 207 | * Creates a NSLayoutConstraint and adds it to the appropriate view. 208 | */ 209 | - (void)install; 210 | 211 | /** 212 | * Removes previously installed NSLayoutConstraint 213 | */ 214 | - (void)uninstall; 215 | 216 | @end 217 | 218 | 219 | /** 220 | * Convenience auto-boxing macros for MASConstraint methods. 221 | * 222 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax. 223 | * A potential drawback of this is that the unprefixed macros will appear in global scope. 224 | */ 225 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__))) 226 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 227 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__))) 228 | 229 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__))) 230 | 231 | 232 | #ifdef MAS_SHORTHAND_GLOBALS 233 | 234 | #define equalTo(...) mas_equalTo(__VA_ARGS__) 235 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__) 236 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__) 237 | 238 | #define offset(...) mas_offset(__VA_ARGS__) 239 | 240 | #endif 241 | 242 | 243 | @interface MASConstraint (AutoboxingSupport) 244 | 245 | /** 246 | * Aliases to corresponding relation methods (for shorthand macros) 247 | * Also needed to aid autocompletion 248 | */ 249 | - (MASConstraint * (^)(id attr))mas_equalTo; 250 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo; 251 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo; 252 | 253 | /** 254 | * A dummy method to aid autocompletion 255 | */ 256 | - (MASConstraint * (^)(id offset))mas_offset; 257 | 258 | @end 259 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.m 3 | // Masonry 4 | // 5 | // Created by Nick Tymchenko on 1/20/14. 6 | // 7 | 8 | #import "MASConstraint.h" 9 | #import "MASConstraint+Private.h" 10 | 11 | #define MASMethodNotImplemented() \ 12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \ 13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \ 14 | userInfo:nil] 15 | 16 | @implementation MASConstraint 17 | 18 | #pragma mark - Init 19 | 20 | - (id)init { 21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly."); 22 | return [super init]; 23 | } 24 | 25 | #pragma mark - NSLayoutRelation proxies 26 | 27 | - (MASConstraint * (^)(id))equalTo { 28 | return ^id(id attribute) { 29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 30 | }; 31 | } 32 | 33 | - (MASConstraint * (^)(id))mas_equalTo { 34 | return ^id(id attribute) { 35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual); 36 | }; 37 | } 38 | 39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo { 40 | return ^id(id attribute) { 41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 42 | }; 43 | } 44 | 45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo { 46 | return ^id(id attribute) { 47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); 48 | }; 49 | } 50 | 51 | - (MASConstraint * (^)(id))lessThanOrEqualTo { 52 | return ^id(id attribute) { 53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 54 | }; 55 | } 56 | 57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo { 58 | return ^id(id attribute) { 59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); 60 | }; 61 | } 62 | 63 | #pragma mark - MASLayoutPriority proxies 64 | 65 | - (MASConstraint * (^)())priorityLow { 66 | return ^id{ 67 | self.priority(MASLayoutPriorityDefaultLow); 68 | return self; 69 | }; 70 | } 71 | 72 | - (MASConstraint * (^)())priorityMedium { 73 | return ^id{ 74 | self.priority(MASLayoutPriorityDefaultMedium); 75 | return self; 76 | }; 77 | } 78 | 79 | - (MASConstraint * (^)())priorityHigh { 80 | return ^id{ 81 | self.priority(MASLayoutPriorityDefaultHigh); 82 | return self; 83 | }; 84 | } 85 | 86 | #pragma mark - NSLayoutConstraint constant proxies 87 | 88 | - (MASConstraint * (^)(MASEdgeInsets))insets { 89 | return ^id(MASEdgeInsets insets){ 90 | self.insets = insets; 91 | return self; 92 | }; 93 | } 94 | 95 | - (MASConstraint * (^)(CGSize))sizeOffset { 96 | return ^id(CGSize offset) { 97 | self.sizeOffset = offset; 98 | return self; 99 | }; 100 | } 101 | 102 | - (MASConstraint * (^)(CGPoint))centerOffset { 103 | return ^id(CGPoint offset) { 104 | self.centerOffset = offset; 105 | return self; 106 | }; 107 | } 108 | 109 | - (MASConstraint * (^)(CGFloat))offset { 110 | return ^id(CGFloat offset){ 111 | self.offset = offset; 112 | return self; 113 | }; 114 | } 115 | 116 | - (MASConstraint * (^)(NSValue *value))valueOffset { 117 | return ^id(NSValue *offset) { 118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset); 119 | [self setLayoutConstantWithValue:offset]; 120 | return self; 121 | }; 122 | } 123 | 124 | - (MASConstraint * (^)(id offset))mas_offset { 125 | // Will never be called due to macro 126 | return nil; 127 | } 128 | 129 | #pragma mark - NSLayoutConstraint constant setter 130 | 131 | - (void)setLayoutConstantWithValue:(NSValue *)value { 132 | if ([value isKindOfClass:NSNumber.class]) { 133 | self.offset = [(NSNumber *)value doubleValue]; 134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) { 135 | CGPoint point; 136 | [value getValue:&point]; 137 | self.centerOffset = point; 138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) { 139 | CGSize size; 140 | [value getValue:&size]; 141 | self.sizeOffset = size; 142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) { 143 | MASEdgeInsets insets; 144 | [value getValue:&insets]; 145 | self.insets = insets; 146 | } else { 147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value); 148 | } 149 | } 150 | 151 | #pragma mark - Semantic properties 152 | 153 | - (MASConstraint *)with { 154 | return self; 155 | } 156 | 157 | - (MASConstraint *)and { 158 | return self; 159 | } 160 | 161 | #pragma mark - Chaining 162 | 163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute { 164 | MASMethodNotImplemented(); 165 | } 166 | 167 | - (MASConstraint *)left { 168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 169 | } 170 | 171 | - (MASConstraint *)top { 172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 173 | } 174 | 175 | - (MASConstraint *)right { 176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 177 | } 178 | 179 | - (MASConstraint *)bottom { 180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 181 | } 182 | 183 | - (MASConstraint *)leading { 184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 185 | } 186 | 187 | - (MASConstraint *)trailing { 188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 189 | } 190 | 191 | - (MASConstraint *)width { 192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 193 | } 194 | 195 | - (MASConstraint *)height { 196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 197 | } 198 | 199 | - (MASConstraint *)centerX { 200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 201 | } 202 | 203 | - (MASConstraint *)centerY { 204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 205 | } 206 | 207 | - (MASConstraint *)baseline { 208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 209 | } 210 | 211 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 212 | 213 | - (MASConstraint *)firstBaseline { 214 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; 215 | } 216 | - (MASConstraint *)lastBaseline { 217 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; 218 | } 219 | 220 | #endif 221 | 222 | #if TARGET_OS_IPHONE || TARGET_OS_TV 223 | 224 | - (MASConstraint *)leftMargin { 225 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; 226 | } 227 | 228 | - (MASConstraint *)rightMargin { 229 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; 230 | } 231 | 232 | - (MASConstraint *)topMargin { 233 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; 234 | } 235 | 236 | - (MASConstraint *)bottomMargin { 237 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; 238 | } 239 | 240 | - (MASConstraint *)leadingMargin { 241 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; 242 | } 243 | 244 | - (MASConstraint *)trailingMargin { 245 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; 246 | } 247 | 248 | - (MASConstraint *)centerXWithinMargins { 249 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 250 | } 251 | 252 | - (MASConstraint *)centerYWithinMargins { 253 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 254 | } 255 | 256 | #endif 257 | 258 | #pragma mark - Abstract 259 | 260 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); } 261 | 262 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); } 263 | 264 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); } 265 | 266 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); } 267 | 268 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); } 269 | 270 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } 271 | 272 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } 273 | 274 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } 275 | 276 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); } 277 | 278 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV) 279 | 280 | - (MASConstraint *)animator { MASMethodNotImplemented(); } 281 | 282 | #endif 283 | 284 | - (void)activate { MASMethodNotImplemented(); } 285 | 286 | - (void)deactivate { MASMethodNotImplemented(); } 287 | 288 | - (void)install { MASMethodNotImplemented(); } 289 | 290 | - (void)uninstall { MASMethodNotImplemented(); } 291 | 292 | @end 293 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASConstraintMaker.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraint.h" 10 | #import "MASUtilities.h" 11 | 12 | typedef NS_OPTIONS(NSInteger, MASAttribute) { 13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft, 14 | MASAttributeRight = 1 << NSLayoutAttributeRight, 15 | MASAttributeTop = 1 << NSLayoutAttributeTop, 16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom, 17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading, 18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing, 19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth, 20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight, 21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX, 22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, 23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, 24 | 25 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 26 | 27 | MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline, 28 | MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline, 29 | 30 | #endif 31 | 32 | #if TARGET_OS_IPHONE || TARGET_OS_TV 33 | 34 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin, 35 | MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin, 36 | MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin, 37 | MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin, 38 | MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin, 39 | MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin, 40 | MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins, 41 | MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins, 42 | 43 | #endif 44 | 45 | }; 46 | 47 | /** 48 | * Provides factory methods for creating MASConstraints. 49 | * Constraints are collected until they are ready to be installed 50 | * 51 | */ 52 | @interface MASConstraintMaker : NSObject 53 | 54 | /** 55 | * The following properties return a new MASViewConstraint 56 | * with the first item set to the makers associated view and the appropriate MASViewAttribute 57 | */ 58 | @property (nonatomic, strong, readonly) MASConstraint *left; 59 | @property (nonatomic, strong, readonly) MASConstraint *top; 60 | @property (nonatomic, strong, readonly) MASConstraint *right; 61 | @property (nonatomic, strong, readonly) MASConstraint *bottom; 62 | @property (nonatomic, strong, readonly) MASConstraint *leading; 63 | @property (nonatomic, strong, readonly) MASConstraint *trailing; 64 | @property (nonatomic, strong, readonly) MASConstraint *width; 65 | @property (nonatomic, strong, readonly) MASConstraint *height; 66 | @property (nonatomic, strong, readonly) MASConstraint *centerX; 67 | @property (nonatomic, strong, readonly) MASConstraint *centerY; 68 | @property (nonatomic, strong, readonly) MASConstraint *baseline; 69 | 70 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 71 | 72 | @property (nonatomic, strong, readonly) MASConstraint *firstBaseline; 73 | @property (nonatomic, strong, readonly) MASConstraint *lastBaseline; 74 | 75 | #endif 76 | 77 | #if TARGET_OS_IPHONE || TARGET_OS_TV 78 | 79 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin; 80 | @property (nonatomic, strong, readonly) MASConstraint *rightMargin; 81 | @property (nonatomic, strong, readonly) MASConstraint *topMargin; 82 | @property (nonatomic, strong, readonly) MASConstraint *bottomMargin; 83 | @property (nonatomic, strong, readonly) MASConstraint *leadingMargin; 84 | @property (nonatomic, strong, readonly) MASConstraint *trailingMargin; 85 | @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins; 86 | @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins; 87 | 88 | #endif 89 | 90 | /** 91 | * Returns a block which creates a new MASCompositeConstraint with the first item set 92 | * to the makers associated view and children corresponding to the set bits in the 93 | * MASAttribute parameter. Combine multiple attributes via binary-or. 94 | */ 95 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs); 96 | 97 | /** 98 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges 99 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right) 100 | * with the first item set to the makers associated view 101 | */ 102 | @property (nonatomic, strong, readonly) MASConstraint *edges; 103 | 104 | /** 105 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize 106 | * which generates the appropriate MASViewConstraint children (width, height) 107 | * with the first item set to the makers associated view 108 | */ 109 | @property (nonatomic, strong, readonly) MASConstraint *size; 110 | 111 | /** 112 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter 113 | * which generates the appropriate MASViewConstraint children (centerX, centerY) 114 | * with the first item set to the makers associated view 115 | */ 116 | @property (nonatomic, strong, readonly) MASConstraint *center; 117 | 118 | /** 119 | * Whether or not to check for an existing constraint instead of adding constraint 120 | */ 121 | @property (nonatomic, assign) BOOL updateExisting; 122 | 123 | /** 124 | * Whether or not to remove existing constraints prior to installing 125 | */ 126 | @property (nonatomic, assign) BOOL removeExisting; 127 | 128 | /** 129 | * initialises the maker with a default view 130 | * 131 | * @param view any MASConstrait are created with this view as the first item 132 | * 133 | * @return a new MASConstraintMaker 134 | */ 135 | - (id)initWithView:(MAS_VIEW *)view; 136 | 137 | /** 138 | * Calls install method on any MASConstraints which have been created by this maker 139 | * 140 | * @return an array of all the installed MASConstraints 141 | */ 142 | - (NSArray *)install; 143 | 144 | - (MASConstraint * (^)(dispatch_block_t))group; 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASConstraintMaker.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraintBuilder.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASConstraintMaker.h" 10 | #import "MASViewConstraint.h" 11 | #import "MASCompositeConstraint.h" 12 | #import "MASConstraint+Private.h" 13 | #import "MASViewAttribute.h" 14 | #import "View+MASAdditions.h" 15 | 16 | @interface MASConstraintMaker () 17 | 18 | @property (nonatomic, weak) MAS_VIEW *view; 19 | @property (nonatomic, strong) NSMutableArray *constraints; 20 | 21 | @end 22 | 23 | @implementation MASConstraintMaker 24 | 25 | - (id)initWithView:(MAS_VIEW *)view { 26 | self = [super init]; 27 | if (!self) return nil; 28 | 29 | self.view = view; 30 | self.constraints = NSMutableArray.new; 31 | 32 | return self; 33 | } 34 | 35 | - (NSArray *)install { 36 | if (self.removeExisting) { 37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view]; 38 | for (MASConstraint *constraint in installedConstraints) { 39 | [constraint uninstall]; 40 | } 41 | } 42 | NSArray *constraints = self.constraints.copy; 43 | for (MASConstraint *constraint in constraints) { 44 | constraint.updateExisting = self.updateExisting; 45 | [constraint install]; 46 | } 47 | [self.constraints removeAllObjects]; 48 | return constraints; 49 | } 50 | 51 | #pragma mark - MASConstraintDelegate 52 | 53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { 54 | NSUInteger index = [self.constraints indexOfObject:constraint]; 55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); 56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint]; 57 | } 58 | 59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute]; 61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute]; 62 | if ([constraint isKindOfClass:MASViewConstraint.class]) { 63 | //replace with composite constraint 64 | NSArray *children = @[constraint, newConstraint]; 65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 66 | compositeConstraint.delegate = self; 67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint]; 68 | return compositeConstraint; 69 | } 70 | if (!constraint) { 71 | newConstraint.delegate = self; 72 | [self.constraints addObject:newConstraint]; 73 | } 74 | return newConstraint; 75 | } 76 | 77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs { 78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading 79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX 80 | | MASAttributeCenterY | MASAttributeBaseline 81 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 82 | | MASAttributeFirstBaseline | MASAttributeLastBaseline 83 | #endif 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV 85 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin 86 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins 87 | | MASAttributeCenterYWithinMargins 88 | #endif 89 | ); 90 | 91 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)"); 92 | 93 | NSMutableArray *attributes = [NSMutableArray array]; 94 | 95 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left]; 96 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right]; 97 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top]; 98 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom]; 99 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading]; 100 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing]; 101 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width]; 102 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height]; 103 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX]; 104 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; 105 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; 106 | 107 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 108 | 109 | if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline]; 110 | if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline]; 111 | 112 | #endif 113 | 114 | #if TARGET_OS_IPHONE || TARGET_OS_TV 115 | 116 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin]; 117 | if (attrs & MASAttributeRightMargin) [attributes addObject:self.view.mas_rightMargin]; 118 | if (attrs & MASAttributeTopMargin) [attributes addObject:self.view.mas_topMargin]; 119 | if (attrs & MASAttributeBottomMargin) [attributes addObject:self.view.mas_bottomMargin]; 120 | if (attrs & MASAttributeLeadingMargin) [attributes addObject:self.view.mas_leadingMargin]; 121 | if (attrs & MASAttributeTrailingMargin) [attributes addObject:self.view.mas_trailingMargin]; 122 | if (attrs & MASAttributeCenterXWithinMargins) [attributes addObject:self.view.mas_centerXWithinMargins]; 123 | if (attrs & MASAttributeCenterYWithinMargins) [attributes addObject:self.view.mas_centerYWithinMargins]; 124 | 125 | #endif 126 | 127 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count]; 128 | 129 | for (MASViewAttribute *a in attributes) { 130 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]]; 131 | } 132 | 133 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 134 | constraint.delegate = self; 135 | [self.constraints addObject:constraint]; 136 | return constraint; 137 | } 138 | 139 | #pragma mark - standard Attributes 140 | 141 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { 142 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute]; 143 | } 144 | 145 | - (MASConstraint *)left { 146 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; 147 | } 148 | 149 | - (MASConstraint *)top { 150 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; 151 | } 152 | 153 | - (MASConstraint *)right { 154 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; 155 | } 156 | 157 | - (MASConstraint *)bottom { 158 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; 159 | } 160 | 161 | - (MASConstraint *)leading { 162 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; 163 | } 164 | 165 | - (MASConstraint *)trailing { 166 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; 167 | } 168 | 169 | - (MASConstraint *)width { 170 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; 171 | } 172 | 173 | - (MASConstraint *)height { 174 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; 175 | } 176 | 177 | - (MASConstraint *)centerX { 178 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; 179 | } 180 | 181 | - (MASConstraint *)centerY { 182 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; 183 | } 184 | 185 | - (MASConstraint *)baseline { 186 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; 187 | } 188 | 189 | - (MASConstraint *(^)(MASAttribute))attributes { 190 | return ^(MASAttribute attrs){ 191 | return [self addConstraintWithAttributes:attrs]; 192 | }; 193 | } 194 | 195 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 196 | 197 | - (MASConstraint *)firstBaseline { 198 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline]; 199 | } 200 | 201 | - (MASConstraint *)lastBaseline { 202 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline]; 203 | } 204 | 205 | #endif 206 | 207 | 208 | #if TARGET_OS_IPHONE || TARGET_OS_TV 209 | 210 | - (MASConstraint *)leftMargin { 211 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; 212 | } 213 | 214 | - (MASConstraint *)rightMargin { 215 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; 216 | } 217 | 218 | - (MASConstraint *)topMargin { 219 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; 220 | } 221 | 222 | - (MASConstraint *)bottomMargin { 223 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; 224 | } 225 | 226 | - (MASConstraint *)leadingMargin { 227 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; 228 | } 229 | 230 | - (MASConstraint *)trailingMargin { 231 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; 232 | } 233 | 234 | - (MASConstraint *)centerXWithinMargins { 235 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 236 | } 237 | 238 | - (MASConstraint *)centerYWithinMargins { 239 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 240 | } 241 | 242 | #endif 243 | 244 | 245 | #pragma mark - composite Attributes 246 | 247 | - (MASConstraint *)edges { 248 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom]; 249 | } 250 | 251 | - (MASConstraint *)size { 252 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight]; 253 | } 254 | 255 | - (MASConstraint *)center { 256 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY]; 257 | } 258 | 259 | #pragma mark - grouping 260 | 261 | - (MASConstraint *(^)(dispatch_block_t group))group { 262 | return ^id(dispatch_block_t group) { 263 | NSInteger previousCount = self.constraints.count; 264 | group(); 265 | 266 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)]; 267 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; 268 | constraint.delegate = self; 269 | return constraint; 270 | }; 271 | } 272 | 273 | @end 274 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASLayoutConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * When you are debugging or printing the constraints attached to a view this subclass 13 | * makes it easier to identify which constraints have been created via Masonry 14 | */ 15 | @interface MASLayoutConstraint : NSLayoutConstraint 16 | 17 | /** 18 | * a key to associate with this constraint 19 | */ 20 | @property (nonatomic, strong) id mas_key; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASLayoutConstraint.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASLayoutConstraint.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASLayoutConstraint.h" 10 | 11 | @implementation MASLayoutConstraint 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASUtilities.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 19/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | 13 | #if TARGET_OS_IPHONE || TARGET_OS_TV 14 | 15 | #import 16 | #define MAS_VIEW UIView 17 | #define MAS_VIEW_CONTROLLER UIViewController 18 | #define MASEdgeInsets UIEdgeInsets 19 | 20 | typedef UILayoutPriority MASLayoutPriority; 21 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired; 22 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh; 23 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500; 24 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow; 25 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel; 26 | 27 | #elif TARGET_OS_MAC 28 | 29 | #import 30 | #define MAS_VIEW NSView 31 | #define MASEdgeInsets NSEdgeInsets 32 | 33 | typedef NSLayoutPriority MASLayoutPriority; 34 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired; 35 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh; 36 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow; 37 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501; 38 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut; 39 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow; 40 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow; 41 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression; 42 | 43 | #endif 44 | 45 | /** 46 | * Allows you to attach keys to objects matching the variable names passed. 47 | * 48 | * view1.mas_key = @"view1", view2.mas_key = @"view2"; 49 | * 50 | * is equivalent to: 51 | * 52 | * MASAttachKeys(view1, view2); 53 | */ 54 | #define MASAttachKeys(...) \ 55 | { \ 56 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \ 57 | for (id key in keyPairs.allKeys) { \ 58 | id obj = keyPairs[key]; \ 59 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \ 60 | @"Cannot attach mas_key to %@", obj); \ 61 | [obj setMas_key:key]; \ 62 | } \ 63 | } 64 | 65 | /** 66 | * Used to create object hashes 67 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html 68 | */ 69 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger)) 70 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch))) 71 | 72 | /** 73 | * Given a scalar or struct value, wraps it in NSValue 74 | * Based on EXPObjectify: https://github.com/specta/expecta 75 | */ 76 | static inline id _MASBoxValue(const char *type, ...) { 77 | va_list v; 78 | va_start(v, type); 79 | id obj = nil; 80 | if (strcmp(type, @encode(id)) == 0) { 81 | id actual = va_arg(v, id); 82 | obj = actual; 83 | } else if (strcmp(type, @encode(CGPoint)) == 0) { 84 | CGPoint actual = (CGPoint)va_arg(v, CGPoint); 85 | obj = [NSValue value:&actual withObjCType:type]; 86 | } else if (strcmp(type, @encode(CGSize)) == 0) { 87 | CGSize actual = (CGSize)va_arg(v, CGSize); 88 | obj = [NSValue value:&actual withObjCType:type]; 89 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { 90 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); 91 | obj = [NSValue value:&actual withObjCType:type]; 92 | } else if (strcmp(type, @encode(double)) == 0) { 93 | double actual = (double)va_arg(v, double); 94 | obj = [NSNumber numberWithDouble:actual]; 95 | } else if (strcmp(type, @encode(float)) == 0) { 96 | float actual = (float)va_arg(v, double); 97 | obj = [NSNumber numberWithFloat:actual]; 98 | } else if (strcmp(type, @encode(int)) == 0) { 99 | int actual = (int)va_arg(v, int); 100 | obj = [NSNumber numberWithInt:actual]; 101 | } else if (strcmp(type, @encode(long)) == 0) { 102 | long actual = (long)va_arg(v, long); 103 | obj = [NSNumber numberWithLong:actual]; 104 | } else if (strcmp(type, @encode(long long)) == 0) { 105 | long long actual = (long long)va_arg(v, long long); 106 | obj = [NSNumber numberWithLongLong:actual]; 107 | } else if (strcmp(type, @encode(short)) == 0) { 108 | short actual = (short)va_arg(v, int); 109 | obj = [NSNumber numberWithShort:actual]; 110 | } else if (strcmp(type, @encode(char)) == 0) { 111 | char actual = (char)va_arg(v, int); 112 | obj = [NSNumber numberWithChar:actual]; 113 | } else if (strcmp(type, @encode(bool)) == 0) { 114 | bool actual = (bool)va_arg(v, int); 115 | obj = [NSNumber numberWithBool:actual]; 116 | } else if (strcmp(type, @encode(unsigned char)) == 0) { 117 | unsigned char actual = (unsigned char)va_arg(v, unsigned int); 118 | obj = [NSNumber numberWithUnsignedChar:actual]; 119 | } else if (strcmp(type, @encode(unsigned int)) == 0) { 120 | unsigned int actual = (unsigned int)va_arg(v, unsigned int); 121 | obj = [NSNumber numberWithUnsignedInt:actual]; 122 | } else if (strcmp(type, @encode(unsigned long)) == 0) { 123 | unsigned long actual = (unsigned long)va_arg(v, unsigned long); 124 | obj = [NSNumber numberWithUnsignedLong:actual]; 125 | } else if (strcmp(type, @encode(unsigned long long)) == 0) { 126 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); 127 | obj = [NSNumber numberWithUnsignedLongLong:actual]; 128 | } else if (strcmp(type, @encode(unsigned short)) == 0) { 129 | unsigned short actual = (unsigned short)va_arg(v, unsigned int); 130 | obj = [NSNumber numberWithUnsignedShort:actual]; 131 | } 132 | va_end(v); 133 | return obj; 134 | } 135 | 136 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) 137 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASViewAttribute.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * An immutable tuple which stores the view and the related NSLayoutAttribute. 13 | * Describes part of either the left or right hand side of a constraint equation 14 | */ 15 | @interface MASViewAttribute : NSObject 16 | 17 | /** 18 | * The view which the reciever relates to. Can be nil if item is not a view. 19 | */ 20 | @property (nonatomic, weak, readonly) MAS_VIEW *view; 21 | 22 | /** 23 | * The item which the reciever relates to. 24 | */ 25 | @property (nonatomic, weak, readonly) id item; 26 | 27 | /** 28 | * The attribute which the reciever relates to 29 | */ 30 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute; 31 | 32 | /** 33 | * Convenience initializer. 34 | */ 35 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute; 36 | 37 | /** 38 | * The designated initializer. 39 | */ 40 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute; 41 | 42 | /** 43 | * Determine whether the layoutAttribute is a size attribute 44 | * 45 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight 46 | */ 47 | - (BOOL)isSizeAttribute; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASViewAttribute.m: -------------------------------------------------------------------------------- 1 | // 2 | // MASAttribute.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 21/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | 11 | @implementation MASViewAttribute 12 | 13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute { 14 | self = [self initWithView:view item:view layoutAttribute:layoutAttribute]; 15 | return self; 16 | } 17 | 18 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute { 19 | self = [super init]; 20 | if (!self) return nil; 21 | 22 | _view = view; 23 | _item = item; 24 | _layoutAttribute = layoutAttribute; 25 | 26 | return self; 27 | } 28 | 29 | - (BOOL)isSizeAttribute { 30 | return self.layoutAttribute == NSLayoutAttributeWidth 31 | || self.layoutAttribute == NSLayoutAttributeHeight; 32 | } 33 | 34 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute { 35 | if ([viewAttribute isKindOfClass:self.class]) { 36 | return self.view == viewAttribute.view 37 | && self.layoutAttribute == viewAttribute.layoutAttribute; 38 | } 39 | return [super isEqual:viewAttribute]; 40 | } 41 | 42 | - (NSUInteger)hash { 43 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/MASViewConstraint.h: -------------------------------------------------------------------------------- 1 | // 2 | // MASConstraint.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASViewAttribute.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | #import "MASUtilities.h" 13 | 14 | /** 15 | * A single constraint. 16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view 17 | */ 18 | @interface MASViewConstraint : MASConstraint 19 | 20 | /** 21 | * First item/view and first attribute of the NSLayoutConstraint 22 | */ 23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute; 24 | 25 | /** 26 | * Second item/view and second attribute of the NSLayoutConstraint 27 | */ 28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute; 29 | 30 | /** 31 | * initialises the MASViewConstraint with the first part of the equation 32 | * 33 | * @param firstViewAttribute view.mas_left, view.mas_width etc. 34 | * 35 | * @return a new view constraint 36 | */ 37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute; 38 | 39 | /** 40 | * Returns all MASViewConstraints installed with this view as a first item. 41 | * 42 | * @param view A view to retrieve constraints for. 43 | * 44 | * @return An array of MASViewConstraints. 45 | */ 46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/Masonry.h: -------------------------------------------------------------------------------- 1 | // 2 | // Masonry.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Masonry. 12 | FOUNDATION_EXPORT double MasonryVersionNumber; 13 | 14 | //! Project version string for Masonry. 15 | FOUNDATION_EXPORT const unsigned char MasonryVersionString[]; 16 | 17 | #import "MASUtilities.h" 18 | #import "View+MASAdditions.h" 19 | #import "View+MASShorthandAdditions.h" 20 | #import "ViewController+MASAdditions.h" 21 | #import "NSArray+MASAdditions.h" 22 | #import "NSArray+MASShorthandAdditions.h" 23 | #import "MASConstraint.h" 24 | #import "MASCompositeConstraint.h" 25 | #import "MASViewAttribute.h" 26 | #import "MASViewConstraint.h" 27 | #import "MASConstraintMaker.h" 28 | #import "MASLayoutConstraint.h" 29 | #import "NSLayoutConstraint+MASDebugAdditions.h" 30 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/NSArray+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.h 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | typedef NS_ENUM(NSUInteger, MASAxisType) { 14 | MASAxisTypeHorizontal, 15 | MASAxisTypeVertical 16 | }; 17 | 18 | @interface NSArray (MASAdditions) 19 | 20 | /** 21 | * Creates a MASConstraintMaker with each view in the callee. 22 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view 23 | * 24 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 25 | * 26 | * @return Array of created MASConstraints 27 | */ 28 | - (NSArray *)mas_makeConstraints:(void (^)(MASConstraintMaker *make))block; 29 | 30 | /** 31 | * Creates a MASConstraintMaker with each view in the callee. 32 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 33 | * If an existing constraint exists then it will be updated instead. 34 | * 35 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 36 | * 37 | * @return Array of created/updated MASConstraints 38 | */ 39 | - (NSArray *)mas_updateConstraints:(void (^)(MASConstraintMaker *make))block; 40 | 41 | /** 42 | * Creates a MASConstraintMaker with each view in the callee. 43 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. 44 | * All constraints previously installed for the views will be removed. 45 | * 46 | * @param block scope within which you can build up the constraints which you wish to apply to each view. 47 | * 48 | * @return Array of created/updated MASConstraints 49 | */ 50 | - (NSArray *)mas_remakeConstraints:(void (^)(MASConstraintMaker *make))block; 51 | 52 | /** 53 | * distribute with fixed spacing 54 | * 55 | * @param axisType which axis to distribute items along 56 | * @param fixedSpacing the spacing between each item 57 | * @param leadSpacing the spacing before the first item and the container 58 | * @param tailSpacing the spacing after the last item and the container 59 | */ 60 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; 61 | 62 | /** 63 | * distribute with fixed item size 64 | * 65 | * @param axisType which axis to distribute items along 66 | * @param fixedItemLength the fixed length of each item 67 | * @param leadSpacing the spacing before the first item and the container 68 | * @param tailSpacing the spacing after the last item and the container 69 | */ 70 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/NSArray+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASAdditions.m 3 | // 4 | // 5 | // Created by Daniel Hammond on 11/26/13. 6 | // 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | #import "View+MASAdditions.h" 11 | 12 | @implementation NSArray (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { 15 | NSMutableArray *constraints = [NSMutableArray array]; 16 | for (MAS_VIEW *view in self) { 17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]]; 19 | } 20 | return constraints; 21 | } 22 | 23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { 24 | NSMutableArray *constraints = [NSMutableArray array]; 25 | for (MAS_VIEW *view in self) { 26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]]; 28 | } 29 | return constraints; 30 | } 31 | 32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 33 | NSMutableArray *constraints = [NSMutableArray array]; 34 | for (MAS_VIEW *view in self) { 35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); 36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]]; 37 | } 38 | return constraints; 39 | } 40 | 41 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing { 42 | if (self.count < 2) { 43 | NSAssert(self.count>1,@"views to distribute need to bigger than one"); 44 | return; 45 | } 46 | 47 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews]; 48 | if (axisType == MASAxisTypeHorizontal) { 49 | MAS_VIEW *prev; 50 | for (int i = 0; i < self.count; i++) { 51 | MAS_VIEW *v = self[i]; 52 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 53 | if (prev) { 54 | make.width.equalTo(prev); 55 | make.left.equalTo(prev.mas_right).offset(fixedSpacing); 56 | if (i == self.count - 1) {//last one 57 | make.right.equalTo(tempSuperView).offset(-tailSpacing); 58 | } 59 | } 60 | else {//first one 61 | make.left.equalTo(tempSuperView).offset(leadSpacing); 62 | } 63 | 64 | }]; 65 | prev = v; 66 | } 67 | } 68 | else { 69 | MAS_VIEW *prev; 70 | for (int i = 0; i < self.count; i++) { 71 | MAS_VIEW *v = self[i]; 72 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 73 | if (prev) { 74 | make.height.equalTo(prev); 75 | make.top.equalTo(prev.mas_bottom).offset(fixedSpacing); 76 | if (i == self.count - 1) {//last one 77 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); 78 | } 79 | } 80 | else {//first one 81 | make.top.equalTo(tempSuperView).offset(leadSpacing); 82 | } 83 | 84 | }]; 85 | prev = v; 86 | } 87 | } 88 | } 89 | 90 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing { 91 | if (self.count < 2) { 92 | NSAssert(self.count>1,@"views to distribute need to bigger than one"); 93 | return; 94 | } 95 | 96 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews]; 97 | if (axisType == MASAxisTypeHorizontal) { 98 | MAS_VIEW *prev; 99 | for (int i = 0; i < self.count; i++) { 100 | MAS_VIEW *v = self[i]; 101 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 102 | make.width.equalTo(@(fixedItemLength)); 103 | if (prev) { 104 | if (i == self.count - 1) {//last one 105 | make.right.equalTo(tempSuperView).offset(-tailSpacing); 106 | } 107 | else { 108 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); 109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); 110 | } 111 | } 112 | else {//first one 113 | make.left.equalTo(tempSuperView).offset(leadSpacing); 114 | } 115 | }]; 116 | prev = v; 117 | } 118 | } 119 | else { 120 | MAS_VIEW *prev; 121 | for (int i = 0; i < self.count; i++) { 122 | MAS_VIEW *v = self[i]; 123 | [v mas_makeConstraints:^(MASConstraintMaker *make) { 124 | make.height.equalTo(@(fixedItemLength)); 125 | if (prev) { 126 | if (i == self.count - 1) {//last one 127 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing); 128 | } 129 | else { 130 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1)); 131 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset); 132 | } 133 | } 134 | else {//first one 135 | make.top.equalTo(tempSuperView).offset(leadSpacing); 136 | } 137 | }]; 138 | prev = v; 139 | } 140 | } 141 | } 142 | 143 | - (MAS_VIEW *)mas_commonSuperviewOfViews 144 | { 145 | MAS_VIEW *commonSuperview = nil; 146 | MAS_VIEW *previousView = nil; 147 | for (id object in self) { 148 | if ([object isKindOfClass:[MAS_VIEW class]]) { 149 | MAS_VIEW *view = (MAS_VIEW *)object; 150 | if (previousView) { 151 | commonSuperview = [view mas_closestCommonSuperview:commonSuperview]; 152 | } else { 153 | commonSuperview = view; 154 | } 155 | previousView = view; 156 | } 157 | } 158 | NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); 159 | return commonSuperview; 160 | } 161 | 162 | @end 163 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/NSArray+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSArray+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand array additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface NSArray (MASShorthandAdditions) 18 | 19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 22 | 23 | @end 24 | 25 | @implementation NSArray (MASShorthandAdditions) 26 | 27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 28 | return [self mas_makeConstraints:block]; 29 | } 30 | 31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 32 | return [self mas_updateConstraints:block]; 33 | } 34 | 35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 36 | return [self mas_remakeConstraints:block]; 37 | } 38 | 39 | @end 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/NSLayoutConstraint+MASDebugAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | 11 | /** 12 | * makes debug and log output of NSLayoutConstraints more readable 13 | */ 14 | @interface NSLayoutConstraint (MASDebugAdditions) 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/NSLayoutConstraint+MASDebugAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSLayoutConstraint+MASDebugAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 3/08/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "NSLayoutConstraint+MASDebugAdditions.h" 10 | #import "MASConstraint.h" 11 | #import "MASLayoutConstraint.h" 12 | 13 | @implementation NSLayoutConstraint (MASDebugAdditions) 14 | 15 | #pragma mark - description maps 16 | 17 | + (NSDictionary *)layoutRelationDescriptionsByValue { 18 | static dispatch_once_t once; 19 | static NSDictionary *descriptionMap; 20 | dispatch_once(&once, ^{ 21 | descriptionMap = @{ 22 | @(NSLayoutRelationEqual) : @"==", 23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=", 24 | @(NSLayoutRelationLessThanOrEqual) : @"<=", 25 | }; 26 | }); 27 | return descriptionMap; 28 | } 29 | 30 | + (NSDictionary *)layoutAttributeDescriptionsByValue { 31 | static dispatch_once_t once; 32 | static NSDictionary *descriptionMap; 33 | dispatch_once(&once, ^{ 34 | descriptionMap = @{ 35 | @(NSLayoutAttributeTop) : @"top", 36 | @(NSLayoutAttributeLeft) : @"left", 37 | @(NSLayoutAttributeBottom) : @"bottom", 38 | @(NSLayoutAttributeRight) : @"right", 39 | @(NSLayoutAttributeLeading) : @"leading", 40 | @(NSLayoutAttributeTrailing) : @"trailing", 41 | @(NSLayoutAttributeWidth) : @"width", 42 | @(NSLayoutAttributeHeight) : @"height", 43 | @(NSLayoutAttributeCenterX) : @"centerX", 44 | @(NSLayoutAttributeCenterY) : @"centerY", 45 | @(NSLayoutAttributeBaseline) : @"baseline", 46 | 47 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 48 | @(NSLayoutAttributeFirstBaseline) : @"firstBaseline", 49 | @(NSLayoutAttributeLastBaseline) : @"lastBaseline", 50 | #endif 51 | 52 | #if TARGET_OS_IPHONE || TARGET_OS_TV 53 | @(NSLayoutAttributeLeftMargin) : @"leftMargin", 54 | @(NSLayoutAttributeRightMargin) : @"rightMargin", 55 | @(NSLayoutAttributeTopMargin) : @"topMargin", 56 | @(NSLayoutAttributeBottomMargin) : @"bottomMargin", 57 | @(NSLayoutAttributeLeadingMargin) : @"leadingMargin", 58 | @(NSLayoutAttributeTrailingMargin) : @"trailingMargin", 59 | @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins", 60 | @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins", 61 | #endif 62 | 63 | }; 64 | 65 | }); 66 | return descriptionMap; 67 | } 68 | 69 | 70 | + (NSDictionary *)layoutPriorityDescriptionsByValue { 71 | static dispatch_once_t once; 72 | static NSDictionary *descriptionMap; 73 | dispatch_once(&once, ^{ 74 | #if TARGET_OS_IPHONE || TARGET_OS_TV 75 | descriptionMap = @{ 76 | @(MASLayoutPriorityDefaultHigh) : @"high", 77 | @(MASLayoutPriorityDefaultLow) : @"low", 78 | @(MASLayoutPriorityDefaultMedium) : @"medium", 79 | @(MASLayoutPriorityRequired) : @"required", 80 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size", 81 | }; 82 | #elif TARGET_OS_MAC 83 | descriptionMap = @{ 84 | @(MASLayoutPriorityDefaultHigh) : @"high", 85 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window", 86 | @(MASLayoutPriorityDefaultMedium) : @"medium", 87 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put", 88 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window", 89 | @(MASLayoutPriorityDefaultLow) : @"low", 90 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size", 91 | @(MASLayoutPriorityRequired) : @"required", 92 | }; 93 | #endif 94 | }); 95 | return descriptionMap; 96 | } 97 | 98 | #pragma mark - description override 99 | 100 | + (NSString *)descriptionForObject:(id)obj { 101 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) { 102 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]]; 103 | } 104 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj]; 105 | } 106 | 107 | - (NSString *)description { 108 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"]; 109 | 110 | [description appendString:[self.class descriptionForObject:self]]; 111 | 112 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]]; 113 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) { 114 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.firstAttribute)]]; 115 | } 116 | 117 | [description appendFormat:@" %@", self.class.layoutRelationDescriptionsByValue[@(self.relation)]]; 118 | 119 | if (self.secondItem) { 120 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]]; 121 | } 122 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) { 123 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.secondAttribute)]]; 124 | } 125 | 126 | if (self.multiplier != 1) { 127 | [description appendFormat:@" * %g", self.multiplier]; 128 | } 129 | 130 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) { 131 | [description appendFormat:@" %g", self.constant]; 132 | } else { 133 | if (self.constant) { 134 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)]; 135 | } 136 | } 137 | 138 | if (self.priority != MASLayoutPriorityRequired) { 139 | [description appendFormat:@" ^%@", self.class.layoutPriorityDescriptionsByValue[@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]]; 140 | } 141 | 142 | [description appendString:@">"]; 143 | return description; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/View+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | /** 14 | * Provides constraint maker block 15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs 16 | */ 17 | @interface MAS_VIEW (MASAdditions) 18 | 19 | /** 20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute 21 | */ 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX; 31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; 32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; 33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); 34 | 35 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 36 | 37 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline; 38 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline; 39 | 40 | #endif 41 | 42 | #if TARGET_OS_IPHONE || TARGET_OS_TV 43 | 44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin; 45 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin; 46 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin; 47 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin; 48 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin; 49 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin; 50 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins; 51 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins; 52 | 53 | #endif 54 | 55 | /** 56 | * a key to associate with this view 57 | */ 58 | @property (nonatomic, strong) id mas_key; 59 | 60 | /** 61 | * Finds the closest common superview between this view and another view 62 | * 63 | * @param view other view 64 | * 65 | * @return returns nil if common superview could not be found 66 | */ 67 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view; 68 | 69 | /** 70 | * Creates a MASConstraintMaker with the callee view. 71 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing 72 | * 73 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 74 | * 75 | * @return Array of created MASConstraints 76 | */ 77 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; 78 | 79 | /** 80 | * Creates a MASConstraintMaker with the callee view. 81 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 82 | * If an existing constraint exists then it will be updated instead. 83 | * 84 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 85 | * 86 | * @return Array of created/updated MASConstraints 87 | */ 88 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; 89 | 90 | /** 91 | * Creates a MASConstraintMaker with the callee view. 92 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. 93 | * All constraints previously installed for the view will be removed. 94 | * 95 | * @param block scope within which you can build up the constraints which you wish to apply to the view. 96 | * 97 | * @return Array of created/updated MASConstraints 98 | */ 99 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/View+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 20/07/13. 6 | // Copyright (c) 2013 cloudling. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | #import 11 | 12 | @implementation MAS_VIEW (MASAdditions) 13 | 14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block { 15 | self.translatesAutoresizingMaskIntoConstraints = NO; 16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 17 | block(constraintMaker); 18 | return [constraintMaker install]; 19 | } 20 | 21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { 22 | self.translatesAutoresizingMaskIntoConstraints = NO; 23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 24 | constraintMaker.updateExisting = YES; 25 | block(constraintMaker); 26 | return [constraintMaker install]; 27 | } 28 | 29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { 30 | self.translatesAutoresizingMaskIntoConstraints = NO; 31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; 32 | constraintMaker.removeExisting = YES; 33 | block(constraintMaker); 34 | return [constraintMaker install]; 35 | } 36 | 37 | #pragma mark - NSLayoutAttribute properties 38 | 39 | - (MASViewAttribute *)mas_left { 40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft]; 41 | } 42 | 43 | - (MASViewAttribute *)mas_top { 44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop]; 45 | } 46 | 47 | - (MASViewAttribute *)mas_right { 48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight]; 49 | } 50 | 51 | - (MASViewAttribute *)mas_bottom { 52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom]; 53 | } 54 | 55 | - (MASViewAttribute *)mas_leading { 56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading]; 57 | } 58 | 59 | - (MASViewAttribute *)mas_trailing { 60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing]; 61 | } 62 | 63 | - (MASViewAttribute *)mas_width { 64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth]; 65 | } 66 | 67 | - (MASViewAttribute *)mas_height { 68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight]; 69 | } 70 | 71 | - (MASViewAttribute *)mas_centerX { 72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX]; 73 | } 74 | 75 | - (MASViewAttribute *)mas_centerY { 76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY]; 77 | } 78 | 79 | - (MASViewAttribute *)mas_baseline { 80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline]; 81 | } 82 | 83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute 84 | { 85 | return ^(NSLayoutAttribute attr) { 86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr]; 87 | }; 88 | } 89 | 90 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 91 | 92 | - (MASViewAttribute *)mas_firstBaseline { 93 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeFirstBaseline]; 94 | } 95 | - (MASViewAttribute *)mas_lastBaseline { 96 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline]; 97 | } 98 | 99 | #endif 100 | 101 | #if TARGET_OS_IPHONE || TARGET_OS_TV 102 | 103 | - (MASViewAttribute *)mas_leftMargin { 104 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin]; 105 | } 106 | 107 | - (MASViewAttribute *)mas_rightMargin { 108 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin]; 109 | } 110 | 111 | - (MASViewAttribute *)mas_topMargin { 112 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin]; 113 | } 114 | 115 | - (MASViewAttribute *)mas_bottomMargin { 116 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin]; 117 | } 118 | 119 | - (MASViewAttribute *)mas_leadingMargin { 120 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin]; 121 | } 122 | 123 | - (MASViewAttribute *)mas_trailingMargin { 124 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin]; 125 | } 126 | 127 | - (MASViewAttribute *)mas_centerXWithinMargins { 128 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins]; 129 | } 130 | 131 | - (MASViewAttribute *)mas_centerYWithinMargins { 132 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins]; 133 | } 134 | 135 | #endif 136 | 137 | #pragma mark - associated properties 138 | 139 | - (id)mas_key { 140 | return objc_getAssociatedObject(self, @selector(mas_key)); 141 | } 142 | 143 | - (void)setMas_key:(id)key { 144 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 145 | } 146 | 147 | #pragma mark - heirachy 148 | 149 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view { 150 | MAS_VIEW *closestCommonSuperview = nil; 151 | 152 | MAS_VIEW *secondViewSuperview = view; 153 | while (!closestCommonSuperview && secondViewSuperview) { 154 | MAS_VIEW *firstViewSuperview = self; 155 | while (!closestCommonSuperview && firstViewSuperview) { 156 | if (secondViewSuperview == firstViewSuperview) { 157 | closestCommonSuperview = secondViewSuperview; 158 | } 159 | firstViewSuperview = firstViewSuperview.superview; 160 | } 161 | secondViewSuperview = secondViewSuperview.superview; 162 | } 163 | return closestCommonSuperview; 164 | } 165 | 166 | @end 167 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/View+MASShorthandAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MASShorthandAdditions.h 3 | // Masonry 4 | // 5 | // Created by Jonas Budelmann on 22/07/13. 6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved. 7 | // 8 | 9 | #import "View+MASAdditions.h" 10 | 11 | #ifdef MAS_SHORTHAND 12 | 13 | /** 14 | * Shorthand view additions without the 'mas_' prefixes, 15 | * only enabled if MAS_SHORTHAND is defined 16 | */ 17 | @interface MAS_VIEW (MASShorthandAdditions) 18 | 19 | @property (nonatomic, strong, readonly) MASViewAttribute *left; 20 | @property (nonatomic, strong, readonly) MASViewAttribute *top; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *right; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *width; 26 | @property (nonatomic, strong, readonly) MASViewAttribute *height; 27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX; 28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY; 29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline; 30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); 31 | 32 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 33 | 34 | @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline; 35 | @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline; 36 | 37 | #endif 38 | 39 | #if TARGET_OS_IPHONE || TARGET_OS_TV 40 | 41 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin; 42 | @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin; 43 | @property (nonatomic, strong, readonly) MASViewAttribute *topMargin; 44 | @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin; 45 | @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin; 46 | @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin; 47 | @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins; 48 | @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins; 49 | 50 | #endif 51 | 52 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; 53 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; 54 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; 55 | 56 | @end 57 | 58 | #define MAS_ATTR_FORWARD(attr) \ 59 | - (MASViewAttribute *)attr { \ 60 | return [self mas_##attr]; \ 61 | } 62 | 63 | @implementation MAS_VIEW (MASShorthandAdditions) 64 | 65 | MAS_ATTR_FORWARD(top); 66 | MAS_ATTR_FORWARD(left); 67 | MAS_ATTR_FORWARD(bottom); 68 | MAS_ATTR_FORWARD(right); 69 | MAS_ATTR_FORWARD(leading); 70 | MAS_ATTR_FORWARD(trailing); 71 | MAS_ATTR_FORWARD(width); 72 | MAS_ATTR_FORWARD(height); 73 | MAS_ATTR_FORWARD(centerX); 74 | MAS_ATTR_FORWARD(centerY); 75 | MAS_ATTR_FORWARD(baseline); 76 | 77 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100) 78 | 79 | MAS_ATTR_FORWARD(firstBaseline); 80 | MAS_ATTR_FORWARD(lastBaseline); 81 | 82 | #endif 83 | 84 | #if TARGET_OS_IPHONE || TARGET_OS_TV 85 | 86 | MAS_ATTR_FORWARD(leftMargin); 87 | MAS_ATTR_FORWARD(rightMargin); 88 | MAS_ATTR_FORWARD(topMargin); 89 | MAS_ATTR_FORWARD(bottomMargin); 90 | MAS_ATTR_FORWARD(leadingMargin); 91 | MAS_ATTR_FORWARD(trailingMargin); 92 | MAS_ATTR_FORWARD(centerXWithinMargins); 93 | MAS_ATTR_FORWARD(centerYWithinMargins); 94 | 95 | #endif 96 | 97 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute { 98 | return [self mas_attribute]; 99 | } 100 | 101 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { 102 | return [self mas_makeConstraints:block]; 103 | } 104 | 105 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { 106 | return [self mas_updateConstraints:block]; 107 | } 108 | 109 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { 110 | return [self mas_remakeConstraints:block]; 111 | } 112 | 113 | @end 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/ViewController+MASAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+MASAdditions.h 3 | // Masonry 4 | // 5 | // Created by Craig Siemens on 2015-06-23. 6 | // 7 | // 8 | 9 | #import "MASUtilities.h" 10 | #import "MASConstraintMaker.h" 11 | #import "MASViewAttribute.h" 12 | 13 | #ifdef MAS_VIEW_CONTROLLER 14 | 15 | @interface MAS_VIEW_CONTROLLER (MASAdditions) 16 | 17 | /** 18 | * following properties return a new MASViewAttribute with appropriate UILayoutGuide and NSLayoutAttribute 19 | */ 20 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide; 21 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide; 22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop; 23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom; 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop; 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom; 26 | 27 | 28 | @end 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/Masonry/ViewController+MASAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+MASAdditions.m 3 | // Masonry 4 | // 5 | // Created by Craig Siemens on 2015-06-23. 6 | // 7 | // 8 | 9 | #import "ViewController+MASAdditions.h" 10 | 11 | #ifdef MAS_VIEW_CONTROLLER 12 | 13 | @implementation MAS_VIEW_CONTROLLER (MASAdditions) 14 | 15 | - (MASViewAttribute *)mas_topLayoutGuide { 16 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 17 | } 18 | - (MASViewAttribute *)mas_topLayoutGuideTop { 19 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 20 | } 21 | - (MASViewAttribute *)mas_topLayoutGuideBottom { 22 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 23 | } 24 | 25 | - (MASViewAttribute *)mas_bottomLayoutGuide { 26 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 27 | } 28 | - (MASViewAttribute *)mas_bottomLayoutGuideTop { 29 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop]; 30 | } 31 | - (MASViewAttribute *)mas_bottomLayoutGuideBottom { 32 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeBottom]; 33 | } 34 | 35 | 36 | 37 | @end 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/XLBasePageController/XLBasePageController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XLBasePageController.h 3 | // XLBasePage 4 | // 5 | // Created by apple on 17/3/24. 6 | // Copyright © 2017年 ZXL. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class XLBasePageController; 12 | 13 | #pragma mark View Pager Delegate 14 | @protocol XLBasePageControllerDelegate 15 | @optional 16 | ///返回当前显示的视图控制器 17 | -(void)viewPagerViewController:(XLBasePageController *)viewPager didFinishScrollWithCurrentViewController:(UIViewController *)viewController; 18 | ///返回当前将要滑动的视图控制器 19 | -(void)viewPagerViewController:(XLBasePageController *)viewPager willScrollerWithCurrentViewController:(UIViewController *)ViewController; 20 | @end 21 | 22 | #pragma mark View Pager DataSource 23 | @protocol XLBasePageControllerDataSource 24 | @required 25 | -(NSInteger)numberViewControllersInViewPager:(XLBasePageController *)viewPager; 26 | -(UIViewController *)viewPager:(XLBasePageController *)viewPager indexViewControllers:(NSInteger)index; 27 | -(NSString *)viewPager:(XLBasePageController *)viewPager titleWithIndexViewControllers:(NSInteger)index; 28 | @optional 29 | ///设置控制器标题按钮的样式,不设置为默认 30 | -(UIButton *)viewPager:(XLBasePageController *)viewPager titleButtonStyle:(NSInteger)index; 31 | -(CGFloat)heightForTitleViewPager:(XLBasePageController *)viewPager; 32 | 33 | ///预留数据源 34 | -(UIView *)headerViewForInViewPager:(XLBasePageController *)viewPager; 35 | -(CGFloat)heightForHeaderViewPager:(XLBasePageController *)viewPager; 36 | @end 37 | 38 | @interface XLBasePageController : UIViewController 39 | @property (nonatomic,weak) id dataSource; 40 | @property (nonatomic,weak) id delegate; 41 | ///刷新 42 | -(void)reloadScrollPage; 43 | 44 | ///默认选中 45 | @property(nonatomic,assign) NSInteger selectIndex; 46 | 47 | ///按钮下划线的高度 字体大小 默认颜色 选中颜色 48 | @property (nonatomic,assign) CGFloat lineWidth; 49 | @property (nonatomic,strong) UIFont *titleFont; 50 | @property (nonatomic,strong) UIColor *defaultColor; 51 | @property (nonatomic,strong) UIColor *chooseColor; 52 | 53 | @end 54 | 55 | #pragma mark 标题按钮 56 | @interface XLBasePageTitleButton : UIButton 57 | 58 | @property (nonatomic,assign) CGFloat buttonlineWidth; 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Lib/XLBasePageController/XLBasePageController.m: -------------------------------------------------------------------------------- 1 | // 2 | // XLBasePageController.h 3 | // HeRuiLand 4 | // 5 | // Created by xiaozikeji on 2017/7/25. 6 | // Copyright © 2017年 xiaozikeji. All rights reserved. 7 | // 8 | 9 | #import "XLBasePageController.h" 10 | 11 | @interface XLBasePageController () 12 | { 13 | NSInteger totalVC; //VC的总数量 14 | NSArray *VCArray; //存放VC的数组 15 | NSArray *buttonArray; //存放VC Button的数组 16 | UIView *headerView; //头部视图 17 | CGRect oldRect; //用来保存title布局的Rect 18 | XLBasePageTitleButton *oldButton; 19 | NSInteger currentVCIndex; //当前VC索引 20 | 21 | } 22 | @property (nonatomic,strong) UIPageViewController *pageViewController; 23 | @property (nonatomic,strong) UIScrollView *titleBGScroll; 24 | @end 25 | 26 | @implementation XLBasePageController 27 | 28 | - (void)viewDidLoad { 29 | [super viewDidLoad]; 30 | 31 | self.lineWidth = self.lineWidth>0?self.lineWidth:1.5; 32 | self.titleFont = self.titleFont?self.titleFont:[UIFont systemFontOfSize:14.0]; 33 | self.defaultColor = self.defaultColor?self.defaultColor:[UIColor blackColor]; 34 | self.chooseColor = self.chooseColor?self.chooseColor:[UIColor redColor]; 35 | 36 | [self addChildViewController:self.pageViewController]; 37 | [self.view addSubview:self.pageViewController.view]; 38 | [self.view addSubview:self.titleBackground]; 39 | 40 | } 41 | 42 | -(UIPageViewController *)pageViewController 43 | { 44 | if (!_pageViewController) { 45 | _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; 46 | _pageViewController.delegate = self; 47 | _pageViewController.dataSource = self; 48 | } 49 | return _pageViewController; 50 | } 51 | 52 | -(UIScrollView *)titleBackground 53 | { 54 | if (!_titleBGScroll) { 55 | _titleBGScroll = [[UIScrollView alloc] init]; 56 | _titleBGScroll.backgroundColor = [UIColor whiteColor]; 57 | _titleBGScroll.showsHorizontalScrollIndicator = NO; 58 | _titleBGScroll.showsVerticalScrollIndicator = NO; 59 | } 60 | return _titleBGScroll; 61 | } 62 | 63 | -(void)setDataSource:(id)dataSource 64 | { 65 | _dataSource = dataSource; 66 | //[self reloadScrollPage]; 67 | } 68 | 69 | -(void)reloadScrollPage 70 | { 71 | if ([self.dataSource respondsToSelector:@selector(numberViewControllersInViewPager:)]) { 72 | oldRect = CGRectZero; 73 | totalVC = [self.dataSource numberViewControllersInViewPager:self]; 74 | NSMutableArray *VCList = [NSMutableArray array]; 75 | NSMutableArray *buttonList = [NSMutableArray array]; 76 | for (int i = 0; i i) { 88 | [[buttonArray objectAtIndex:i] removeFromSuperview]; 89 | } 90 | UIButton *button; 91 | if ([self.dataSource respondsToSelector:@selector(viewPager:titleButtonStyle:)]) 92 | { 93 | if ([[self.dataSource viewPager:self titleButtonStyle:i] isKindOfClass:[UIButton class]]) { 94 | button = [self.dataSource viewPager:self titleButtonStyle:i]; 95 | } 96 | }else{ 97 | 98 | XLBasePageTitleButton *autoButton = [[XLBasePageTitleButton alloc] init]; 99 | 100 | //autoButton.buttonlineWidth = self.lineWidth; 101 | autoButton.tag = i; 102 | [autoButton.titleLabel setFont:self.titleFont]; 103 | [autoButton setTitleColor:self.defaultColor forState:UIControlStateNormal]; 104 | [autoButton setTitleColor:self.chooseColor forState:UIControlStateSelected]; 105 | 106 | button = autoButton; 107 | 108 | } 109 | [button addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 110 | 111 | 112 | button.frame = CGRectMake(oldRect.origin.x+oldRect.size.width, 0, [self textString:buttonTitle withFontHeight:20], [self.dataSource respondsToSelector:@selector(heightForTitleViewPager:)]?[self.dataSource heightForTitleViewPager:self]:0); 113 | oldRect = button.frame; 114 | [button setTitle:buttonTitle forState:UIControlStateNormal]; 115 | [buttonList addObject:button]; 116 | [_titleBGScroll addSubview:button]; 117 | if (i == self.selectIndex) { 118 | oldButton = [buttonList objectAtIndex:self.selectIndex]; 119 | oldButton.selected = YES; 120 | } 121 | } 122 | } 123 | //当所有按钮尺寸小于屏幕宽度的时候要重新布局 124 | if (buttonList.count && ((UIButton *)buttonList.lastObject).frame.origin.x + ((UIButton *)buttonList.lastObject).frame.size.widthCGRectGetWidth(self.view.frame))) { 177 | return; 178 | } 179 | if (CGRectGetMidX(button.frame)>CGRectGetMidX(self.view.frame)) { 180 | if (_titleBGScroll.contentSize.width *)previousViewControllers transitionCompleted:(BOOL)completed 194 | { 195 | if (completed) { 196 | if (currentVCIndex != [VCArray indexOfObject:previousViewControllers[0]]) { 197 | [self chooseTitleIndex:currentVCIndex]; 198 | if ([self.delegate respondsToSelector:@selector(viewPagerViewController:didFinishScrollWithCurrentViewController:)]) { 199 | [self.delegate viewPagerViewController:self didFinishScrollWithCurrentViewController:[VCArray objectAtIndex:currentVCIndex]]; 200 | } 201 | } 202 | 203 | } 204 | } 205 | 206 | - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers 207 | { 208 | currentVCIndex = [VCArray indexOfObject:pendingViewControllers[0]]; 209 | if ([self.delegate respondsToSelector:@selector(viewPagerViewController:willScrollerWithCurrentViewController:)]) { 210 | [self.delegate viewPagerViewController:self willScrollerWithCurrentViewController:pageViewController.viewControllers[0]]; 211 | } 212 | } 213 | 214 | #pragma mark -UIPageViewControllerDataSource 215 | - (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController 216 | { 217 | NSInteger index = [VCArray indexOfObject:viewController]; 218 | if (index == 0 || index == NSNotFound) { 219 | return nil; 220 | 221 | }else{ 222 | return VCArray[--index]; 223 | } 224 | } 225 | 226 | - (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController 227 | { 228 | NSInteger index = [VCArray indexOfObject:viewController]; 229 | if (index == VCArray.count-1 || index == NSNotFound) { 230 | return nil; 231 | 232 | }else{ 233 | return VCArray[++index]; 234 | } 235 | } 236 | 237 | -(void)chooseTitleIndex:(NSInteger)index 238 | { 239 | [self titleButtonConvert:buttonArray[index]]; 240 | } 241 | 242 | -(void)viewDidLayoutSubviews 243 | { 244 | 245 | headerView.frame = CGRectMake(0, self.topLayoutGuide.length, self.view.frame.size.width,[self.dataSource respondsToSelector:@selector(heightForHeaderViewPager:)]?[self.dataSource heightForHeaderViewPager:self]:0); 246 | 247 | _titleBGScroll.frame = CGRectMake(0, (headerView.frame.size.height)?headerView.frame.origin.y+headerView.frame.size.height:self.topLayoutGuide.length, self.view.frame.size.width,[self.dataSource respondsToSelector:@selector(heightForTitleViewPager:)]?[self.dataSource heightForTitleViewPager:self]:0); 248 | 249 | if (buttonArray.count) { 250 | 251 | _titleBGScroll.contentSize = CGSizeMake(((UIButton *)buttonArray.lastObject).frame.size.width+((UIButton *)buttonArray.lastObject).frame.origin.x, _titleBGScroll.frame.size.height); 252 | } 253 | 254 | _pageViewController.view.frame = CGRectMake(0, _titleBGScroll.frame.origin.y+_titleBGScroll.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-(_titleBGScroll.frame.origin.y+_titleBGScroll.frame.size.height)); 255 | } 256 | 257 | #pragma mark 计算字体宽度 258 | -(CGFloat)textString:(NSString *)text withFontHeight:(CGFloat)height 259 | { 260 | CGFloat padding = 20; 261 | NSDictionary *fontAttribute = @{NSFontAttributeName : self.titleFont}; 262 | CGSize fontSize = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:fontAttribute context:nil].size; 263 | return fontSize.width+padding; 264 | } 265 | 266 | @end 267 | 268 | #pragma mark 标题按钮的属性设置 269 | @implementation XLBasePageTitleButton 270 | - (instancetype)init 271 | { 272 | self = [super init]; 273 | if (self) { 274 | 275 | } 276 | return self; 277 | } 278 | 279 | -(void)drawRect:(CGRect)rect 280 | { 281 | if (self.selected) { 282 | CGFloat lineWidth = 1.0; 283 | CGColorRef color = self.titleLabel.textColor.CGColor; 284 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 285 | CGContextSetStrokeColorWithColor(ctx, color); 286 | CGContextSetLineWidth(ctx, lineWidth); 287 | CGContextMoveToPoint(ctx, 0, self.frame.size.height-lineWidth); 288 | CGContextAddLineToPoint(ctx, self.frame.size.width, self.frame.size.height-lineWidth); 289 | CGContextStrokePath(ctx); 290 | } 291 | } 292 | 293 | @end 294 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Model/LXFCalculateResultModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculateResultModel.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LXFCalculateResultModel : NSObject 12 | 13 | /** title */ 14 | @property (nonatomic, copy) NSString *title; 15 | /** value */ 16 | @property (nonatomic, copy) NSString *value; 17 | /** titleColor */ 18 | @property (nonatomic, strong) UIColor *titleColor; 19 | /** valueColor */ 20 | @property (nonatomic, strong) UIColor *valueColor; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/Model/LXFCalculateResultModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculateResultModel.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculateResultModel.h" 10 | 11 | @implementation LXFCalculateResultModel 12 | 13 | - (UIColor *)titleColor { 14 | if (!_titleColor) { 15 | _titleColor = [UIColor blackColor]; 16 | } 17 | return _titleColor; 18 | } 19 | 20 | - (UIColor *)valueColor { 21 | if (!_valueColor) { 22 | _valueColor = [UIColor darkGrayColor]; 23 | } 24 | return _valueColor; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalcInputCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalcInputCell.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LXFCalcInputCell : UITableViewCell 12 | @property (weak, nonatomic) IBOutlet UILabel *titleLabel; 13 | @property (weak, nonatomic) IBOutlet UITextField *valueLabel; 14 | @property (weak, nonatomic) IBOutlet UILabel *unitLabel; 15 | 16 | /** 输入回调 */ 17 | @property (nonatomic, copy) void (^inputBlock)(NSString *text); 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalcInputCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalcInputCell.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalcInputCell.h" 10 | 11 | @implementation LXFCalcInputCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | 16 | [self.valueLabel addTarget:self action:@selector(textField1TextChange:) forControlEvents:UIControlEventEditingChanged]; 17 | } 18 | 19 | -(void)textField1TextChange:(UITextField *)textField{ 20 | if (self.inputBlock) { 21 | self.inputBlock(textField.text); 22 | } 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalcInputCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 28 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalcSelectStrCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalcSelectStrCell.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LXFCalcSelectStrCell : UITableViewCell 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *titleLabel; 14 | @property (weak, nonatomic) IBOutlet UILabel *valueLabel; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalcSelectStrCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalcSelectStrCell.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalcSelectStrCell.h" 10 | 11 | @implementation LXFCalcSelectStrCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalcSelectStrCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 28 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalculatorCalcBtnView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorCalcBtnView.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LXFCalculatorCalcBtnView : UIView 12 | 13 | /** 开始计算Block */ 14 | @property (nonatomic, copy) void (^startCalcBlock)(); 15 | 16 | + (CGFloat)viewHeight; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalculatorCalcBtnView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFCalculatorCalcBtnView.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFCalculatorCalcBtnView.h" 10 | 11 | @implementation LXFCalculatorCalcBtnView 12 | - (IBAction)startCalc { 13 | NSLog(@"开始计算"); 14 | if (self.startCalcBlock) { 15 | self.startCalcBlock(); 16 | } 17 | } 18 | 19 | - (void)awakeFromNib { 20 | [super awakeFromNib]; 21 | 22 | } 23 | 24 | + (CGFloat)viewHeight { 25 | return 100; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFCalculatorCalcBtnView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFPopResultCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFPopResultCell.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | @class LXFCalculateResultModel; 11 | 12 | @interface LXFPopResultCell : UITableViewCell 13 | 14 | @property (nonatomic, strong) LXFCalculateResultModel *model; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFPopResultCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFPopResultCell.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFPopResultCell.h" 10 | #import "LXFCalculateResultModel.h" 11 | 12 | @interface LXFPopResultCell() 13 | 14 | @property (weak, nonatomic) IBOutlet UILabel *title; 15 | @property (weak, nonatomic) IBOutlet UILabel *value; 16 | 17 | @end 18 | 19 | @implementation LXFPopResultCell 20 | 21 | - (void)setModel:(LXFCalculateResultModel *)model { 22 | _model = model; 23 | self.title.text = model.title; 24 | self.value.text = model.value; 25 | self.title.textColor = model.titleColor; 26 | self.value.textColor = model.valueColor; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFPopResultCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFPopResultView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFPopResultView.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LXFHouseLoanCalculator.h" 11 | 12 | @interface LXFPopResultView : UIView 13 | //弹出 14 | - (void)pop; 15 | //消失 16 | - (void)dismiss; 17 | 18 | /** resultModel */ 19 | @property (nonatomic, strong) LXFHouseLoanResultModel *model; 20 | /** 计算方式是否为总价 */ 21 | @property (nonatomic, assign) BOOL isCalcMethodTotalPrice; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Classes/View/LXFPopResultView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LXFPopResultView.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "LXFPopResultView.h" 10 | #import "LXFPopResultCell.h" 11 | #import "LXFCalculateResultModel.h" 12 | 13 | #import "UITableViewCell+LXF.h" 14 | 15 | #define kRowHeight 40 16 | #define kHeaderHeight 40 17 | #define KSCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) 18 | #define KSCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) 19 | 20 | static NSString * const LXFTableViewCellID = @"LXFPopResultCell"; 21 | 22 | @interface LXFPopResultView() 23 | 24 | @property (nonatomic, weak) UITableView *tableView; 25 | /** dataArr */ 26 | @property (nonatomic, strong) NSMutableArray *dataArr; 27 | 28 | @end 29 | 30 | @implementation LXFPopResultView 31 | 32 | - (void)setModel:(LXFHouseLoanResultModel *)model { 33 | _model = model; 34 | [self.dataArr removeAllObjects]; 35 | 36 | if (!self.isCalcMethodTotalPrice) { 37 | // 房屋总价 38 | LXFCalculateResultModel *modelx = [LXFCalculateResultModel new]; 39 | modelx.title = @"房屋总价"; 40 | modelx.value = [NSString stringWithFormat:@"%.2f元", model.houseTotalPrice]; 41 | [self.dataArr addObject:modelx]; 42 | } 43 | 44 | // 贷款总额 45 | LXFCalculateResultModel *model1 = [LXFCalculateResultModel new]; 46 | model1.title = @"贷款总额"; 47 | model1.value = [NSString stringWithFormat:@"%.2f元", model.loanTotalPrice]; 48 | model1.valueColor = [UIColor redColor]; 49 | [self.dataArr addObject:model1]; 50 | 51 | // 还款总额 52 | LXFCalculateResultModel *model2 = [LXFCalculateResultModel new]; 53 | model2.title = @"还款总额"; 54 | model2.value = [NSString stringWithFormat:@"%.2f元", model.repayTotalPrice]; 55 | [self.dataArr addObject:model2]; 56 | 57 | // 支付利息 58 | LXFCalculateResultModel *model3 = [LXFCalculateResultModel new]; 59 | model3.title = @"支付利息"; 60 | model3.value = [NSString stringWithFormat:@"%.2f元", model.interestPayment]; 61 | [self.dataArr addObject:model3]; 62 | 63 | if (!self.isCalcMethodTotalPrice) { 64 | // 首期付款 65 | LXFCalculateResultModel *modelx = [LXFCalculateResultModel new]; 66 | modelx.title = @"首期付款"; 67 | modelx.value = [NSString stringWithFormat:@"%.2f元", model.houseTotalPrice]; 68 | [self.dataArr addObject:modelx]; 69 | } 70 | 71 | // 按揭年数 72 | LXFCalculateResultModel *model4 = [LXFCalculateResultModel new]; 73 | model4.title = @"按揭年数"; 74 | model4.value = [NSString stringWithFormat:@"%d年(%d个月)",(int)model.mortgageYear ,(int)model.mortgageMonth]; 75 | // model4.value = [NSString stringWithFormat:@"%.2f", model.mortgageYear];r 76 | [self.dataArr addObject:model4]; 77 | 78 | // 月均还款 79 | LXFCalculateResultModel *model5 = [LXFCalculateResultModel new]; 80 | model5.title = @"月均还款"; 81 | model5.value = [NSString stringWithFormat:@"%.2f元", model.avgMonthRepayment]; 82 | [self.dataArr addObject:model5]; 83 | 84 | [self.tableView reloadData]; 85 | } 86 | 87 | - (instancetype)initWithFrame:(CGRect)frame { 88 | 89 | if (self = [super initWithFrame:frame]) { 90 | 91 | self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:.4]; 92 | } 93 | return self; 94 | } 95 | 96 | #pragma mark - UITableViewDelegate,UITableViewDataSource 97 | 98 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 99 | 100 | return self.dataArr.count; 101 | 102 | } 103 | 104 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 105 | LXFPopResultCell *cell = [LXFPopResultCell loadCellFromNib:tableView]; 106 | cell.model = self.dataArr[indexPath.row]; 107 | return cell; 108 | } 109 | 110 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 111 | return kRowHeight; 112 | } 113 | 114 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 115 | { 116 | UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KSCREEN_WIDTH - 70, kHeaderHeight)]; 117 | view.backgroundColor = [UIColor blackColor]; 118 | 119 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, KSCREEN_WIDTH - 70, kHeaderHeight)]; 120 | label.text = @"计算结果"; 121 | label.font = [UIFont systemFontOfSize:14.0]; 122 | label.textAlignment = NSTextAlignmentCenter; 123 | label.textColor = [UIColor whiteColor]; 124 | [view addSubview:label]; 125 | return view; 126 | } 127 | 128 | - (void)pop { 129 | UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; 130 | [keyWindow addSubview:self]; 131 | //动画效果弹出 132 | self.alpha = 0; 133 | CGRect frame = CGRectMake(35, 0, KSCREEN_WIDTH - 70, self.dataArr.count * kRowHeight + kHeaderHeight); 134 | self.tableView.frame = frame; 135 | [UIView animateWithDuration:.25 animations:^{ 136 | self.alpha = 1; 137 | self.tableView.frame = CGRectMake(35, (KSCREEN_HEIGHT - self.dataArr.count * kRowHeight) * 0.5 - kHeaderHeight, KSCREEN_WIDTH - 70, self.dataArr.count * kRowHeight + kHeaderHeight); 138 | }]; 139 | } 140 | 141 | - (void)dismiss { 142 | //动画效果淡出 143 | [UIView animateWithDuration:.25 animations:^{ 144 | 145 | CGRect frame = CGRectMake(35, 0, KSCREEN_WIDTH - 70, self.dataArr.count * kRowHeight + kHeaderHeight); 146 | self.tableView.frame = frame; 147 | } completion:^(BOOL finished) { 148 | if (finished) { 149 | [self removeFromSuperview]; 150 | } 151 | }]; 152 | } 153 | 154 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 155 | UITouch *touch = [touches anyObject]; 156 | if (![touch.view isEqual:self.tableView]) { 157 | [self dismiss]; 158 | } 159 | } 160 | 161 | #pragma mark - 懒加载 162 | - (UITableView *)tableView { 163 | if (!_tableView) { 164 | UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 10, KSCREEN_WIDTH - 70, self.dataArr.count * kRowHeight + kHeaderHeight)]; 165 | tableView.delegate = self; 166 | tableView.dataSource = self; 167 | tableView.backgroundColor = [UIColor clearColor]; 168 | tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 169 | tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); 170 | tableView.sectionHeaderHeight = 40; 171 | tableView.scrollEnabled = NO; 172 | tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 173 | [self addSubview:tableView]; 174 | _tableView = tableView; 175 | } 176 | return _tableView; 177 | } 178 | - (NSMutableArray *)dataArr { 179 | if (!_dataArr) { 180 | _dataArr = [NSMutableArray array]; 181 | } 182 | return _dataArr; 183 | } 184 | 185 | @end 186 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculator/LXFHouseLoanCalculator.h: -------------------------------------------------------------------------------- 1 | // 2 | // LXFHouseLoanCalculator.h 3 | // 4 | // Created by LinXunFeng on 2017/8/25. 5 | // Copyright © 2017年 LinXunFeng. All rights reserved. 6 | // 7 | // GitHub: https://github.com/LinXunFeng 8 | // 简书: http://www.jianshu.com/users/31e85e7a22a2 9 | 10 | #import 11 | @class LXFHouseLoanCalcModel, LXFHouseLoanResultModel; 12 | 13 | @interface LXFHouseLoanCalculator : NSObject 14 | 15 | /** =================================== 商业贷款 =================================== */ 16 | 17 | #pragma mark 按商业贷款等额本息总价计算(总价) 18 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 19 | #pragma mark 按商业贷款等额本金总价计算(总价) 20 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 21 | #pragma mark 按商业贷款等额本息单价计算(单价和面积) 22 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsUnitPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 23 | #pragma mark 按商业贷款等额本金单价计算(单价和面积) 24 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsUnitPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 25 | 26 | /** =================================== 公积金贷款 =================================== */ 27 | 28 | #pragma mark 按公积金贷款等额本息总价计算(总价) 29 | + (LXFHouseLoanResultModel *)calculateFundLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 30 | #pragma mark 按公积金贷款等额本金总价计算(总价) 31 | + (LXFHouseLoanResultModel *)calculateFundLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 32 | #pragma mark 按公积金贷款等额本息单价计算(单价和面积) 33 | + (LXFHouseLoanResultModel *)calculateFundLoanAsUnitPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 34 | #pragma mark 按公积金贷款等额本金单价计算(单价和面积) 35 | + (LXFHouseLoanResultModel *)calculateFundLoanAsUnitPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 36 | 37 | /** =================================== 组合型贷款 =================================== */ 38 | #pragma mark 按组合型贷款等额本息总价计算(总价) 39 | + (LXFHouseLoanResultModel *)calculateCombinedLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 40 | #pragma mark 按组合型贷款等额本金总价计算(总价) 41 | + (LXFHouseLoanResultModel *)calculateCombinedLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 42 | 43 | @end 44 | 45 | @interface LXFHouseLoanCalcModel : NSObject 46 | 47 | /** 单价 */ 48 | @property (nonatomic, assign) double unitPrice; 49 | /** 面积 */ 50 | @property (nonatomic, assign) double area; 51 | /** 商业贷款总额 */ 52 | @property (nonatomic, assign) double businessTotalPrice; 53 | /** 公积金贷款总额 */ 54 | @property (nonatomic, assign) double fundTotalPrice; 55 | /** 按揭年数 */ 56 | @property (nonatomic, assign) int mortgageYear; 57 | /** 按揭成数 */ 58 | @property (nonatomic, assign) int mortgageMulti; 59 | /** 银行利率 */ 60 | @property (nonatomic, assign) double bankRate; 61 | /** 公积金利率 */ 62 | @property (nonatomic, assign) double fundRate; 63 | 64 | @end 65 | 66 | 67 | @interface LXFHouseLoanResultModel : NSObject 68 | // 房屋总价 69 | @property (nonatomic, assign) double houseTotalPrice; 70 | /** 贷款总额 */ 71 | @property (nonatomic, assign) double loanTotalPrice; 72 | /** 还款总额 */ 73 | @property (nonatomic, assign) double repayTotalPrice; 74 | /** 支付利息 */ 75 | @property (nonatomic, assign) double interestPayment; 76 | /** 按揭年数 */ 77 | @property (nonatomic, assign) double mortgageYear; 78 | /** 按揭月数 */ 79 | @property (nonatomic, assign) double mortgageMonth; 80 | /** 月均还款 */ 81 | @property (nonatomic, assign) double avgMonthRepayment; 82 | /** 首月还款 */ 83 | @property (nonatomic, assign) double firstMonthRepayment; 84 | /** 每月还款数组 */ 85 | @property (nonatomic, strong) NSMutableArray *monthRepaymentArr; 86 | 87 | @end 88 | 89 | 90 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /LXFHouseLoanCalculatorDemo/LXFHouseLoanCalculatorDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LXFHouseLoanCalculatorDemo 4 | // 5 | // Created by 林洵锋 on 2017/9/2. 6 | // Copyright © 2017年 LinXunFeng. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LXFHouseLoanCalculator 2 | iOS - 房贷计算器 3 | 4 | 5 | 6 | ## Usage 7 | 8 | 商业贷款 9 | 10 | ```objective-c 11 | #pragma mark 按商业贷款等额本息总价计算(总价) 12 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 13 | 14 | #pragma mark 按商业贷款等额本金总价计算(总价) 15 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 16 | 17 | #pragma mark 按商业贷款等额本息单价计算(单价和面积) 18 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsUnitPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 19 | 20 | #pragma mark 按商业贷款等额本金单价计算(单价和面积) 21 | + (LXFHouseLoanResultModel *)calculateBusinessLoanAsUnitPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 22 | ``` 23 | 24 | 25 | 26 | 公积金贷款 27 | 28 | ```objective-c 29 | #pragma mark 按公积金贷款等额本息总价计算(总价) 30 | + (LXFHouseLoanResultModel *)calculateFundLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 31 | #pragma mark 按公积金贷款等额本金总价计算(总价) 32 | + (LXFHouseLoanResultModel *)calculateFundLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 33 | #pragma mark 按公积金贷款等额本息单价计算(单价和面积) 34 | + (LXFHouseLoanResultModel *)calculateFundLoanAsUnitPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 35 | #pragma mark 按公积金贷款等额本金单价计算(单价和面积) 36 | + (LXFHouseLoanResultModel *)calculateFundLoanAsUnitPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 37 | ``` 38 | 39 | 40 | 41 | 组合型贷款 42 | 43 | ```objective-c 44 | #pragma mark 按组合型贷款等额本息总价计算(总价) 45 | + (LXFHouseLoanResultModel *)calculateCombinedLoanAsTotalPriceAndEqualPrincipalInterestWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 46 | #pragma mark 按组合型贷款等额本金总价计算(总价) 47 | + (LXFHouseLoanResultModel *)calculateCombinedLoanAsTotalPriceAndEqualPrincipalWithCalcModel:(LXFHouseLoanCalcModel *)calcModel; 48 | ``` 49 | 50 | 51 | 52 | ## Exhibition 53 | 54 | 55 | 56 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/1.png) 57 | 58 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/2.png) 59 | 60 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/3.png) 61 | 62 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/4.png) 63 | 64 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/5.png) 65 | 66 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/6.png) 67 | 68 | ![image](https://github.com/LinXunFeng/LXFHouseLoanCalculator/raw/master/Screenshots/7.png) 69 | 70 | -------------------------------------------------------------------------------- /Screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/1.png -------------------------------------------------------------------------------- /Screenshots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/2.png -------------------------------------------------------------------------------- /Screenshots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/3.png -------------------------------------------------------------------------------- /Screenshots/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/4.png -------------------------------------------------------------------------------- /Screenshots/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/5.png -------------------------------------------------------------------------------- /Screenshots/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/6.png -------------------------------------------------------------------------------- /Screenshots/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinXunFeng/LXFHouseLoanCalculator/72b36b88751d55e46e91e54dfb10dc099627a0d9/Screenshots/7.png --------------------------------------------------------------------------------