├── LICENSE ├── LZCartViewController ├── LZCartViewController.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── Artron_LQQ.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── Artron_LQQ.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── LZCartViewController.xcscheme │ │ └── xcschememanagement.plist ├── LZCartViewController │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── LZCartViewController │ │ ├── ConfigFile │ │ │ ├── LZConfigFile.h │ │ │ ├── UIViewExt.h │ │ │ └── UIViewExt.m │ │ ├── LZCartModel │ │ │ ├── LZCartModel.h │ │ │ └── LZCartModel.m │ │ ├── LZCartTableViewCell │ │ │ ├── LZCartTableViewCell.h │ │ │ └── LZCartTableViewCell.m │ │ ├── LZCartViewController.h │ │ ├── LZCartViewController.m │ │ └── icons │ │ │ ├── back_button@2x.png │ │ │ ├── cart_addBtn_highlight@2x.png │ │ │ ├── cart_addBtn_nomal@2x.png │ │ │ ├── cart_cutBtn_highlight@2x.png │ │ │ ├── cart_cutBtn_nomal@2x.png │ │ │ ├── cart_default_bg.png │ │ │ ├── cart_selected_btn@2x.png │ │ │ └── cart_unSelect_btn@2x.png │ ├── ViewController.h │ ├── ViewController.m │ ├── aaa.jpg │ └── main.m ├── LZCartViewController2 │ ├── LZCartViewController.xcodeproj │ │ ├── LZCarViewController2.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── Artron_LQQ.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ ├── UINavigationBar │ │ │ ├── UINavigationBar.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ ├── project.xcworkspace │ │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ │ └── xcuserdata │ │ │ │ │ │ └── Artron_LQQ.xcuserdatad │ │ │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ │ └── xcuserdata │ │ │ │ │ └── Artron_LQQ.xcuserdatad │ │ │ │ │ └── xcschemes │ │ │ │ │ ├── UINavigationBar.xcscheme │ │ │ │ │ └── xcschememanagement.plist │ │ │ ├── UINavigationBar │ │ │ │ ├── 40fe711f9b754b596159f3a6.jpg │ │ │ │ ├── AppDelegate.h │ │ │ │ ├── AppDelegate.m │ │ │ │ ├── Assets.xcassets │ │ │ │ │ └── AppIcon.appiconset │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── Base.lproj │ │ │ │ │ ├── LaunchScreen.storyboard │ │ │ │ │ └── Main.storyboard │ │ │ │ ├── Info.plist │ │ │ │ ├── UINavigationBar.xcdatamodeld │ │ │ │ │ ├── .xccurrentversion │ │ │ │ │ └── UINavigationBar.xcdatamodel │ │ │ │ │ │ └── contents │ │ │ │ ├── UINavigationBar │ │ │ │ │ ├── LZNavigationTool.h │ │ │ │ │ └── LZNavigationTool.m │ │ │ │ ├── ViewController.h │ │ │ │ ├── ViewController.m │ │ │ │ └── main.m │ │ │ ├── UINavigationBarTests │ │ │ │ ├── Info.plist │ │ │ │ └── UINavigationBarTests.m │ │ │ └── UINavigationBarUITests │ │ │ │ ├── Info.plist │ │ │ │ └── UINavigationBarUITests.m │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── Artron_LQQ.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── Artron_LQQ.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ ├── LZCartViewController2.xcscheme │ │ │ └── xcschememanagement.plist │ ├── LZCartViewController │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── LZCartViewController │ │ │ ├── ConfigFile │ │ │ │ ├── LZConfigFile.h │ │ │ │ ├── UIViewExt.h │ │ │ │ └── UIViewExt.m │ │ │ ├── LZCartModel │ │ │ │ ├── LZGoodsModel.h │ │ │ │ ├── LZGoodsModel.m │ │ │ │ ├── LZShopModel.h │ │ │ │ └── LZShopModel.m │ │ │ ├── LZCartTableViewCell │ │ │ │ ├── LZCartTableViewCell.h │ │ │ │ ├── LZCartTableViewCell.m │ │ │ │ ├── LZTableHeaderView.h │ │ │ │ └── LZTableHeaderView.m │ │ │ ├── LZCartViewController.h │ │ │ ├── LZCartViewController.m │ │ │ └── icons │ │ │ │ ├── back_button@2x.png │ │ │ │ ├── cart_addBtn_highlight@2x.png │ │ │ │ ├── cart_addBtn_nomal@2x.png │ │ │ │ ├── cart_cutBtn_highlight@2x.png │ │ │ │ ├── cart_cutBtn_nomal@2x.png │ │ │ │ ├── cart_default_bg.png │ │ │ │ ├── cart_selected_btn@2x.png │ │ │ │ └── cart_unSelect_btn@2x.png │ │ ├── ShopCarNew.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ ├── aaa.jpg │ │ └── main.m │ ├── LZCartViewControllerTests │ │ ├── Info.plist │ │ └── LZCartViewControllerTests.m │ └── LZCartViewControllerUITests │ │ ├── Info.plist │ │ └── LZCartViewControllerUITests.m ├── LZCartViewControllerTests │ ├── Info.plist │ └── LZCartViewControllerTests.m └── LZCartViewControllerUITests │ ├── Info.plist │ └── LZCartViewControllerUITests.m ├── README.md ├── Untitled.xcworkspace ├── contents.xcworkspacedata ├── xcshareddata │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── Artron_LQQ.xcuserdatad │ ├── UserInterfaceState.xcuserstate │ └── xcdebugger │ └── Breakpoints_v2.xcbkptlist ├── test.gif └── testttt.gif /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 LQiqiang(LQQZYY) 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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/LZCartViewController.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LZCartViewController.xcscheme 8 | 9 | isShown 10 | 11 | orderHint 12 | 0 13 | 14 | 15 | SuppressBuildableAutocreation 16 | 17 | 9148CA611CEBFC8B0054A40A 18 | 19 | primary 20 | 21 | 22 | 9148CA7A1CEBFC8C0054A40A 23 | 24 | primary 25 | 26 | 27 | 9148CA851CEBFC8C0054A40A 28 | 29 | primary 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. 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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/ConfigFile/LZConfigFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZConfigFile.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #ifndef LZConfigFile_h 12 | #define LZConfigFile_h 13 | #import "UIViewExt.h" 14 | 15 | //16进制RGB的颜色转换 16 | #define LZColorFromHex(rgbValue) [UIColor \ 17 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 18 | green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 19 | blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 20 | 21 | //R G B 颜色 22 | #define LZColorFromRGB(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] 23 | 24 | //红色 25 | #define BASECOLOR_RED [UIColor \ 26 | colorWithRed:((float)((0xED5565 & 0xFF0000) >> 16))/255.0 \ 27 | green:((float)((0xED5565 & 0xFF00) >> 8))/255.0 \ 28 | blue:((float)(0xED5565 & 0xFF))/255.0 alpha:1.0] 29 | 30 | 31 | 32 | #define LZSCREEN_HEIGHT ([[UIScreen mainScreen]bounds].size.height) 33 | #define LZSCREEN_WIDTH ([[UIScreen mainScreen]bounds].size.width) 34 | #define LZNaigationBarHeight 64 35 | #define LZTabBarHeight 49 36 | 37 | #define TAG_CartEmptyView 100 38 | 39 | 40 | static NSString *lz_BackButtonString = @"back_button"; 41 | static NSString *lz_Bottom_UnSelectButtonString = @"cart_unSelect_btn"; 42 | static NSString *lz_Bottom_SelectButtonString = @"cart_selected_btn"; 43 | static NSString *lz_CartEmptyString = @"cart_default_bg"; 44 | static NSInteger lz_CartRowHeight = 100; 45 | #endif /* LZConfigFile_h */ 46 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/ConfigFile/UIViewExt.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import 4 | //#import 5 | #import 6 | 7 | 8 | @interface UIView(UIViewExt) 9 | 10 | /** 11 | * Shortcut for frame.origin.x. 12 | * 13 | * Sets frame.origin.x = left 14 | */ 15 | @property (nonatomic) CGFloat left; 16 | 17 | /** 18 | * Shortcut for frame.origin.y 19 | * 20 | * Sets frame.origin.y = top 21 | */ 22 | @property (nonatomic) CGFloat top; 23 | 24 | /** 25 | * Shortcut for frame.origin.x + frame.size.width 26 | * 27 | * Sets frame.origin.x = right - frame.size.width 28 | */ 29 | @property (nonatomic) CGFloat right; 30 | 31 | /** 32 | * Shortcut for frame.origin.y + frame.size.height 33 | * 34 | * Sets frame.origin.y = bottom - frame.size.height 35 | */ 36 | @property (nonatomic) CGFloat bottom; 37 | 38 | /** 39 | * Shortcut for frame.size.width 40 | * 41 | * Sets frame.size.width = width 42 | */ 43 | @property (nonatomic) CGFloat width; 44 | 45 | /** 46 | * Shortcut for frame.size.height 47 | * 48 | * Sets frame.size.height = height 49 | */ 50 | @property (nonatomic) CGFloat height; 51 | 52 | /** 53 | * Shortcut for center.x 54 | * 55 | * Sets center.x = centerX 56 | */ 57 | @property (nonatomic) CGFloat centerX; 58 | 59 | /** 60 | * Shortcut for center.y 61 | * 62 | * Sets center.y = centerY 63 | */ 64 | @property (nonatomic) CGFloat centerY; 65 | 66 | /** 67 | * Shortcut for frame.origin 68 | */ 69 | @property (nonatomic) CGPoint origin; 70 | 71 | /** 72 | * Shortcut for frame.size 73 | */ 74 | @property (nonatomic) CGSize size; 75 | 76 | @end -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/ConfigFile/UIViewExt.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "UIViewExt.h" 3 | @implementation UIView(UIViewExt) 4 | 5 | - (CGFloat)left { 6 | return self.frame.origin.x; 7 | } 8 | 9 | 10 | /////////////////////////////////////////////////////////////////////////////////////////////////// 11 | - (void)setLeft:(CGFloat)x { 12 | CGRect frame = self.frame; 13 | frame.origin.x = x; 14 | self.frame = frame; 15 | } 16 | 17 | 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// 19 | - (CGFloat)top { 20 | return self.frame.origin.y; 21 | } 22 | 23 | 24 | /////////////////////////////////////////////////////////////////////////////////////////////////// 25 | - (void)setTop:(CGFloat)y { 26 | CGRect frame = self.frame; 27 | frame.origin.y = y; 28 | self.frame = frame; 29 | } 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////////// 33 | - (CGFloat)right { 34 | return self.frame.origin.x + self.width; 35 | } 36 | 37 | 38 | /////////////////////////////////////////////////////////////////////////////////////////////////// 39 | - (void)setRight:(CGFloat)right { 40 | CGRect frame = self.frame; 41 | frame.origin.x = right - frame.size.width; 42 | self.frame = frame; 43 | } 44 | 45 | 46 | /////////////////////////////////////////////////////////////////////////////////////////////////// 47 | - (CGFloat)bottom { 48 | return self.frame.origin.y + self.frame.size.height; 49 | } 50 | 51 | 52 | /////////////////////////////////////////////////////////////////////////////////////////////////// 53 | - (void)setBottom:(CGFloat)bottom { 54 | CGRect frame = self.frame; 55 | frame.origin.y = bottom - frame.size.height; 56 | self.frame = frame; 57 | } 58 | 59 | 60 | /////////////////////////////////////////////////////////////////////////////////////////////////// 61 | - (CGFloat)centerX { 62 | return self.center.x; 63 | } 64 | 65 | 66 | /////////////////////////////////////////////////////////////////////////////////////////////////// 67 | - (void)setCenterX:(CGFloat)centerX { 68 | self.center = CGPointMake(centerX, self.center.y); 69 | } 70 | 71 | 72 | /////////////////////////////////////////////////////////////////////////////////////////////////// 73 | - (CGFloat)centerY { 74 | return self.center.y; 75 | } 76 | 77 | 78 | /////////////////////////////////////////////////////////////////////////////////////////////////// 79 | - (void)setCenterY:(CGFloat)centerY { 80 | self.center = CGPointMake(self.center.x, centerY); 81 | } 82 | 83 | 84 | /////////////////////////////////////////////////////////////////////////////////////////////////// 85 | - (CGFloat)width { 86 | return self.frame.size.width; 87 | } 88 | 89 | 90 | /////////////////////////////////////////////////////////////////////////////////////////////////// 91 | - (void)setWidth:(CGFloat)width { 92 | CGRect frame = self.frame; 93 | frame.size.width = width; 94 | self.frame = frame; 95 | } 96 | 97 | 98 | /////////////////////////////////////////////////////////////////////////////////////////////////// 99 | - (CGFloat)height { 100 | return self.frame.size.height; 101 | } 102 | 103 | 104 | /////////////////////////////////////////////////////////////////////////////////////////////////// 105 | - (void)setHeight:(CGFloat)height { 106 | CGRect frame = self.frame; 107 | frame.size.height = height; 108 | self.frame = frame; 109 | } 110 | 111 | 112 | /////////////////////////////////////////////////////////////////////////////////////////////////// 113 | - (CGPoint)origin { 114 | return self.frame.origin; 115 | } 116 | 117 | 118 | /////////////////////////////////////////////////////////////////////////////////////////////////// 119 | - (void)setOrigin:(CGPoint)origin { 120 | CGRect frame = self.frame; 121 | frame.origin = origin; 122 | self.frame = frame; 123 | } 124 | 125 | 126 | /////////////////////////////////////////////////////////////////////////////////////////////////// 127 | - (CGSize)size { 128 | return self.frame.size; 129 | } 130 | 131 | 132 | /////////////////////////////////////////////////////////////////////////////////////////////////// 133 | - (void)setSize:(CGSize)size { 134 | CGRect frame = self.frame; 135 | frame.size = size; 136 | self.frame = frame; 137 | } 138 | @end -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/LZCartModel/LZCartModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartModel.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import 12 | #import 13 | 14 | @interface LZCartModel : NSObject 15 | //自定义模型时,这三个属性必须有 16 | @property (nonatomic,assign) BOOL select; 17 | @property (nonatomic,assign) NSInteger number; 18 | @property (nonatomic,copy) NSString *price; 19 | //下面的属性可根据自己的需求修改 20 | @property (nonatomic,copy) NSString *sizeStr; 21 | @property (nonatomic,copy) NSString *nameStr; 22 | @property (nonatomic,copy) NSString *dateStr; 23 | @property (nonatomic,retain)UIImage *image; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/LZCartModel/LZCartModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartModel.m 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import "LZCartModel.h" 12 | 13 | @implementation LZCartModel 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/LZCartTableViewCell/LZCartTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartTableViewCell.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import 12 | 13 | @class LZCartModel; 14 | typedef void(^LZNumberChangedBlock)(NSInteger number); 15 | typedef void(^LZCellSelectedBlock)(BOOL select); 16 | @interface LZCartTableViewCell : UITableViewCell 17 | //商品数量 18 | @property (assign,nonatomic)NSInteger lzNumber; 19 | @property (assign,nonatomic)BOOL lzSelected; 20 | 21 | - (void)reloadDataWithModel:(LZCartModel*)model; 22 | - (void)numberAddWithBlock:(LZNumberChangedBlock)block; 23 | - (void)numberCutWithBlock:(LZNumberChangedBlock)block; 24 | - (void)cellSelectedWithBlock:(LZCellSelectedBlock)block; 25 | @end 26 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/LZCartTableViewCell/LZCartTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartTableViewCell.m 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import "LZCartTableViewCell.h" 12 | #import "LZConfigFile.h" 13 | #import "LZCartModel.h" 14 | 15 | @interface LZCartTableViewCell () 16 | { 17 | LZNumberChangedBlock numberAddBlock; 18 | LZNumberChangedBlock numberCutBlock; 19 | LZCellSelectedBlock cellSelectedBlock; 20 | } 21 | //选中按钮 22 | @property (nonatomic,retain) UIButton *selectBtn; 23 | //显示照片 24 | @property (nonatomic,retain) UIImageView *lzImageView; 25 | //商品名 26 | @property (nonatomic,retain) UILabel *nameLabel; 27 | //尺寸 28 | @property (nonatomic,retain) UILabel *sizeLabel; 29 | //时间 30 | @property (nonatomic,retain) UILabel *dateLabel; 31 | //价格 32 | @property (nonatomic,retain) UILabel *priceLabel; 33 | //数量 34 | @property (nonatomic,retain)UILabel *numberLabel; 35 | 36 | @end 37 | 38 | @implementation LZCartTableViewCell 39 | 40 | - (void)awakeFromNib { 41 | [super awakeFromNib]; 42 | // Initialization code 43 | } 44 | 45 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 46 | [super setSelected:selected animated:animated]; 47 | 48 | // Configure the view for the selected state 49 | } 50 | 51 | -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 52 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 53 | if (self) { 54 | self.backgroundColor = LZColorFromRGB(245, 246, 248); 55 | self.selectionStyle = UITableViewCellSelectionStyleNone; 56 | [self setupMainView]; 57 | } 58 | return self; 59 | } 60 | #pragma mark - public method 61 | - (void)reloadDataWithModel:(LZCartModel*)model { 62 | 63 | self.lzImageView.image = model.image; 64 | self.nameLabel.text = model.nameStr; 65 | self.priceLabel.text = model.price; 66 | self.dateLabel.text = model.dateStr; 67 | self.numberLabel.text = [NSString stringWithFormat:@"%ld",(long)model.number]; 68 | self.sizeLabel.text = model.sizeStr; 69 | self.selectBtn.selected = model.select; 70 | } 71 | 72 | - (void)numberAddWithBlock:(LZNumberChangedBlock)block { 73 | numberAddBlock = block; 74 | } 75 | 76 | - (void)numberCutWithBlock:(LZNumberChangedBlock)block { 77 | numberCutBlock = block; 78 | } 79 | 80 | - (void)cellSelectedWithBlock:(LZCellSelectedBlock)block { 81 | cellSelectedBlock = block; 82 | } 83 | #pragma mark - 重写setter方法 84 | - (void)setLzNumber:(NSInteger)lzNumber { 85 | _lzNumber = lzNumber; 86 | 87 | self.numberLabel.text = [NSString stringWithFormat:@"%ld",(long)lzNumber]; 88 | } 89 | 90 | - (void)setLzSelected:(BOOL)lzSelected { 91 | _lzSelected = lzSelected; 92 | self.selectBtn.selected = lzSelected; 93 | } 94 | #pragma mark - 按钮点击方法 95 | - (void)selectBtnClick:(UIButton*)button { 96 | button.selected = !button.selected; 97 | 98 | if (cellSelectedBlock) { 99 | cellSelectedBlock(button.selected); 100 | } 101 | } 102 | 103 | - (void)addBtnClick:(UIButton*)button { 104 | 105 | NSInteger count = [self.numberLabel.text integerValue]; 106 | count++; 107 | 108 | if (numberAddBlock) { 109 | numberAddBlock(count); 110 | } 111 | } 112 | 113 | - (void)cutBtnClick:(UIButton*)button { 114 | NSInteger count = [self.numberLabel.text integerValue]; 115 | count--; 116 | if(count <= 0){ 117 | return ; 118 | } 119 | 120 | if (numberCutBlock) { 121 | numberCutBlock(count); 122 | } 123 | } 124 | #pragma mark - 布局主视图 125 | -(void)setupMainView { 126 | //白色背景 127 | UIView *bgView = [[UIView alloc]init]; 128 | bgView.frame = CGRectMake(10, 10, LZSCREEN_WIDTH - 20, lz_CartRowHeight - 10); 129 | bgView.backgroundColor = [UIColor whiteColor]; 130 | bgView.layer.borderColor = LZColorFromHex(0xEEEEEE).CGColor; 131 | bgView.layer.borderWidth = 1; 132 | [self addSubview:bgView]; 133 | 134 | //选中按钮 135 | UIButton* selectBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 136 | selectBtn.center = CGPointMake(20, bgView.height/2.0); 137 | selectBtn.bounds = CGRectMake(0, 0, 30, 30); 138 | [selectBtn setImage:[UIImage imageNamed:lz_Bottom_UnSelectButtonString] forState:UIControlStateNormal]; 139 | [selectBtn setImage:[UIImage imageNamed:lz_Bottom_SelectButtonString] forState:UIControlStateSelected]; 140 | [selectBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 141 | [bgView addSubview:selectBtn]; 142 | self.selectBtn = selectBtn; 143 | 144 | //照片背景 145 | UIView *imageBgView = [[UIView alloc]init]; 146 | imageBgView.frame = CGRectMake(selectBtn.right + 5, 5, bgView.height - 10, bgView.height - 10); 147 | imageBgView.backgroundColor = LZColorFromHex(0xF3F3F3); 148 | [bgView addSubview:imageBgView]; 149 | 150 | //显示照片 151 | UIImageView* imageView = [[UIImageView alloc]init]; 152 | imageView.image = [UIImage imageNamed:@"default_pic_1"]; 153 | imageView.frame = CGRectMake(imageBgView.left + 5, imageBgView.top + 5, imageBgView.width - 10, imageBgView.height - 10); 154 | imageView.contentMode = UIViewContentModeScaleAspectFit; 155 | [bgView addSubview:imageView]; 156 | self.lzImageView = imageView; 157 | 158 | CGFloat width = (bgView.width - imageBgView.right - 30)/2.0; 159 | //价格 160 | UILabel* priceLabel = [[UILabel alloc]init]; 161 | priceLabel.frame = CGRectMake(bgView.width - width - 10, 10, width, 30); 162 | priceLabel.font = [UIFont boldSystemFontOfSize:16]; 163 | priceLabel.textColor = BASECOLOR_RED; 164 | priceLabel.textAlignment = NSTextAlignmentRight; 165 | [bgView addSubview:priceLabel]; 166 | self.priceLabel = priceLabel; 167 | 168 | //商品名 169 | UILabel* nameLabel = [[UILabel alloc]init]; 170 | nameLabel.frame = CGRectMake(imageBgView.right + 10, 10, width, 25); 171 | nameLabel.font = [UIFont systemFontOfSize:15]; 172 | [bgView addSubview:nameLabel]; 173 | self.nameLabel = nameLabel; 174 | 175 | //尺寸 176 | UILabel* sizeLabel = [[UILabel alloc]init]; 177 | sizeLabel.frame = CGRectMake(nameLabel.left, nameLabel.bottom + 5, width, 20); 178 | sizeLabel.textColor = LZColorFromRGB(132, 132, 132); 179 | sizeLabel.font = [UIFont systemFontOfSize:12]; 180 | [bgView addSubview:sizeLabel]; 181 | self.sizeLabel = sizeLabel; 182 | 183 | //时间 184 | UILabel* dateLabel = [[UILabel alloc]init]; 185 | dateLabel.frame = CGRectMake(nameLabel.left, sizeLabel.bottom , width, 20); 186 | dateLabel.font = [UIFont systemFontOfSize:10]; 187 | dateLabel.textColor = LZColorFromRGB(132, 132, 132); 188 | [bgView addSubview:dateLabel]; 189 | self.dateLabel = dateLabel; 190 | 191 | //数量加按钮 192 | UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 193 | addBtn.frame = CGRectMake(bgView.width - 35, bgView.height - 35, 25, 25); 194 | [addBtn setImage:[UIImage imageNamed:@"cart_addBtn_nomal"] forState:UIControlStateNormal]; 195 | [addBtn setImage:[UIImage imageNamed:@"cart_addBtn_highlight"] forState:UIControlStateHighlighted]; 196 | [addBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 197 | [bgView addSubview:addBtn]; 198 | 199 | //数量显示 200 | UILabel* numberLabel = [[UILabel alloc]init]; 201 | numberLabel.frame = CGRectMake(addBtn.left - 30, addBtn.top, 30, 25); 202 | numberLabel.textAlignment = NSTextAlignmentCenter; 203 | numberLabel.text = @"1"; 204 | numberLabel.font = [UIFont systemFontOfSize:15]; 205 | [bgView addSubview:numberLabel]; 206 | self.numberLabel = numberLabel; 207 | 208 | //数量减按钮 209 | UIButton *cutBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 210 | cutBtn.frame = CGRectMake(numberLabel.left - 25, addBtn.top, 25, 25); 211 | [cutBtn setImage:[UIImage imageNamed:@"cart_cutBtn_nomal"] forState:UIControlStateNormal]; 212 | [cutBtn setImage:[UIImage imageNamed:@"cart_cutBtn_highlight"] forState:UIControlStateHighlighted]; 213 | [cutBtn addTarget:self action:@selector(cutBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 214 | [bgView addSubview:cutBtn]; 215 | } 216 | 217 | @end 218 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/LZCartViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewController.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import 12 | 13 | @interface LZCartViewController : UIViewController 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/LZCartViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewController.m 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import "LZCartViewController.h" 12 | #import "LZConfigFile.h" 13 | #import "LZCartTableViewCell.h" 14 | #import "LZCartModel.h" 15 | 16 | @interface LZCartViewController () 17 | { 18 | BOOL _isHiddenNavigationBarWhenDisappear;//记录当页面消失时是否需要隐藏系统导航 19 | BOOL _isHasTabBarController;//是否含有tabbar 20 | BOOL _isHasNavitationController;//是否含有导航 21 | } 22 | 23 | @property (strong,nonatomic)NSMutableArray *dataArray; 24 | @property (strong,nonatomic)NSMutableArray *selectedArray; 25 | @property (strong,nonatomic)UITableView *myTableView; 26 | @property (strong,nonatomic)UIButton *allSellectedButton; 27 | @property (strong,nonatomic)UILabel *totlePriceLabel; 28 | @end 29 | 30 | @implementation LZCartViewController 31 | 32 | #pragma mark - viewController life cicle 33 | - (void)viewWillAppear:(BOOL)animated { 34 | 35 | if (_isHasNavitationController == YES) { 36 | if (self.navigationController.navigationBarHidden == YES) { 37 | _isHiddenNavigationBarWhenDisappear = NO; 38 | } else { 39 | self.navigationController.navigationBarHidden = YES; 40 | _isHiddenNavigationBarWhenDisappear = YES; 41 | } 42 | } 43 | 44 | 45 | //当进入购物车的时候判断是否有已选择的商品,有就清空 46 | //主要是提交订单后再返回到购物车,如果不清空,还会显示 47 | if (self.selectedArray.count > 0) { 48 | for (LZCartModel *model in self.selectedArray) { 49 | model.select = NO;//这个其实有点多余,提交订单后的数据源不会包含这些,保险起见,加上了 50 | } 51 | [self.selectedArray removeAllObjects]; 52 | } 53 | 54 | //初始化显示状态 55 | _allSellectedButton.selected = NO; 56 | _totlePriceLabel.attributedText = [self LZSetString:@"¥0.00"]; 57 | } 58 | 59 | -(void)creatData { 60 | for (int i = 0; i < 10; i++) { 61 | LZCartModel *model = [[LZCartModel alloc]init]; 62 | 63 | model.nameStr = [NSString stringWithFormat:@"测试数据%d",i]; 64 | model.price = @"100.00"; 65 | model.number = 1; 66 | model.image = [UIImage imageNamed:@"aaa.jpg"]; 67 | model.dateStr = @"2016.02.18"; 68 | model.sizeStr = @"18*20cm"; 69 | 70 | [self.dataArray addObject:model]; 71 | } 72 | } 73 | - (void)loadData { 74 | [self creatData]; 75 | [self changeView]; 76 | } 77 | - (void)viewDidLoad { 78 | [super viewDidLoad]; 79 | // Do any additional setup after loading the view. 80 | self.view.backgroundColor = [UIColor whiteColor]; 81 | _isHasTabBarController = self.tabBarController?YES:NO; 82 | _isHasNavitationController = self.navigationController?YES:NO; 83 | 84 | #warning 模仿请求数据,延迟2s加载数据 85 | [self performSelector:@selector(loadData) withObject:nil afterDelay:2]; 86 | 87 | 88 | [self setupCustomNavigationBar]; 89 | if (self.dataArray.count > 0) { 90 | 91 | [self setupCartView]; 92 | } else { 93 | [self setupCartEmptyView]; 94 | } 95 | } 96 | 97 | - (void)viewWillDisappear:(BOOL)animated { 98 | if (_isHiddenNavigationBarWhenDisappear == YES) { 99 | self.navigationController.navigationBarHidden = NO; 100 | } 101 | } 102 | 103 | /** 104 | * @author LQQ, 16-02-18 11:02:16 105 | * 106 | * 计算已选中商品金额 107 | */ 108 | -(void)countPrice { 109 | double totlePrice = 0.0; 110 | 111 | for (LZCartModel *model in self.selectedArray) { 112 | 113 | double price = [model.price doubleValue]; 114 | 115 | totlePrice += price*model.number; 116 | } 117 | NSString *string = [NSString stringWithFormat:@"¥%.2f",totlePrice]; 118 | self.totlePriceLabel.attributedText = [self LZSetString:string]; 119 | } 120 | 121 | #pragma mark - 初始化数组 122 | - (NSMutableArray *)dataArray { 123 | if (_dataArray == nil) { 124 | _dataArray = [NSMutableArray arrayWithCapacity:0]; 125 | } 126 | 127 | return _dataArray; 128 | } 129 | 130 | - (NSMutableArray *)selectedArray { 131 | if (_selectedArray == nil) { 132 | _selectedArray = [NSMutableArray arrayWithCapacity:0]; 133 | } 134 | 135 | return _selectedArray; 136 | } 137 | 138 | #pragma mark - 布局页面视图 139 | #pragma mark -- 自定义导航 140 | - (void)setupCustomNavigationBar { 141 | UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, LZSCREEN_WIDTH, LZNaigationBarHeight)]; 142 | backgroundView.backgroundColor = LZColorFromRGB(236, 236, 236); 143 | [self.view addSubview:backgroundView]; 144 | 145 | UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, LZNaigationBarHeight - 0.5, LZSCREEN_WIDTH, 0.5)]; 146 | lineView.backgroundColor = [UIColor lightGrayColor]; 147 | [self.view addSubview:lineView]; 148 | 149 | UILabel *titleLabel = [[UILabel alloc]init]; 150 | titleLabel.text = @"购物车"; 151 | titleLabel.font = [UIFont systemFontOfSize:20]; 152 | 153 | titleLabel.center = CGPointMake(self.view.center.x, (LZNaigationBarHeight - 20)/2.0 + 20); 154 | CGSize size = [titleLabel sizeThatFits:CGSizeMake(300, 44)]; 155 | titleLabel.bounds = CGRectMake(0, 0, size.width + 20, size.height); 156 | 157 | titleLabel.textAlignment = NSTextAlignmentCenter; 158 | [self.view addSubview:titleLabel]; 159 | 160 | UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; 161 | backButton.frame = CGRectMake(10, 20, 40, 44); 162 | [backButton setImage:[UIImage imageNamed:lz_BackButtonString] forState:UIControlStateNormal]; 163 | [backButton addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 164 | [self.view addSubview:backButton]; 165 | } 166 | #pragma mark -- 自定义底部视图 167 | - (void)setupCustomBottomView { 168 | 169 | UIView *backgroundView = [[UIView alloc]init]; 170 | backgroundView.backgroundColor = LZColorFromRGB(245, 245, 245); 171 | backgroundView.tag = TAG_CartEmptyView + 1; 172 | [self.view addSubview:backgroundView]; 173 | 174 | //当有tabBarController时,在tabBar的上面 175 | if (_isHasTabBarController == YES) { 176 | backgroundView.frame = CGRectMake(0, LZSCREEN_HEIGHT - 2*LZTabBarHeight, LZSCREEN_WIDTH, LZTabBarHeight); 177 | } else { 178 | backgroundView.frame = CGRectMake(0, LZSCREEN_HEIGHT - LZTabBarHeight, LZSCREEN_WIDTH, LZTabBarHeight); 179 | } 180 | 181 | UIView *lineView = [[UIView alloc]init]; 182 | lineView.frame = CGRectMake(0, 0, LZSCREEN_WIDTH, 1); 183 | lineView.backgroundColor = [UIColor lightGrayColor]; 184 | [backgroundView addSubview:lineView]; 185 | 186 | //全选按钮 187 | UIButton *selectAll = [UIButton buttonWithType:UIButtonTypeCustom]; 188 | selectAll.titleLabel.font = [UIFont systemFontOfSize:16]; 189 | selectAll.frame = CGRectMake(10, 5, 80, LZTabBarHeight - 10); 190 | [selectAll setTitle:@" 全选" forState:UIControlStateNormal]; 191 | [selectAll setImage:[UIImage imageNamed:lz_Bottom_UnSelectButtonString] forState:UIControlStateNormal]; 192 | [selectAll setImage:[UIImage imageNamed:lz_Bottom_SelectButtonString] forState:UIControlStateSelected]; 193 | [selectAll setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 194 | [selectAll addTarget:self action:@selector(selectAllBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 195 | [backgroundView addSubview:selectAll]; 196 | self.allSellectedButton = selectAll; 197 | 198 | //结算按钮 199 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 200 | btn.backgroundColor = BASECOLOR_RED; 201 | btn.frame = CGRectMake(LZSCREEN_WIDTH - 80, 0, 80, LZTabBarHeight); 202 | [btn setTitle:@"去结算" forState:UIControlStateNormal]; 203 | [btn addTarget:self action:@selector(goToPayButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 204 | [backgroundView addSubview:btn]; 205 | 206 | //合计 207 | UILabel *label = [[UILabel alloc]init]; 208 | label.font = [UIFont systemFontOfSize:18]; 209 | label.textColor = [UIColor redColor]; 210 | [backgroundView addSubview:label]; 211 | 212 | label.attributedText = [self LZSetString:@"¥0.00"]; 213 | CGFloat maxWidth = LZSCREEN_WIDTH - selectAll.bounds.size.width - btn.bounds.size.width - 30; 214 | // CGSize size = [label sizeThatFits:CGSizeMake(maxWidth, LZTabBarHeight)]; 215 | label.frame = CGRectMake(selectAll.bounds.size.width + 20, 0, maxWidth - 10, LZTabBarHeight); 216 | self.totlePriceLabel = label; 217 | } 218 | 219 | - (NSMutableAttributedString*)LZSetString:(NSString*)string { 220 | 221 | NSString *text = [NSString stringWithFormat:@"合计:%@",string]; 222 | NSMutableAttributedString *LZString = [[NSMutableAttributedString alloc]initWithString:text]; 223 | NSRange rang = [text rangeOfString:@"合计:"]; 224 | [LZString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:rang]; 225 | [LZString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:rang]; 226 | return LZString; 227 | } 228 | #pragma mark -- 购物车为空时的默认视图 229 | - (void)changeView { 230 | if (self.dataArray.count > 0) { 231 | UIView *view = [self.view viewWithTag:TAG_CartEmptyView]; 232 | if (view != nil) { 233 | [view removeFromSuperview]; 234 | } 235 | 236 | [self setupCartView]; 237 | } else { 238 | UIView *bottomView = [self.view viewWithTag:TAG_CartEmptyView + 1]; 239 | [bottomView removeFromSuperview]; 240 | 241 | [self.myTableView removeFromSuperview]; 242 | self.myTableView = nil; 243 | [self setupCartEmptyView]; 244 | } 245 | } 246 | 247 | - (void)setupCartEmptyView { 248 | //默认视图背景 249 | UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, LZNaigationBarHeight, LZSCREEN_WIDTH, LZSCREEN_HEIGHT - LZNaigationBarHeight)]; 250 | backgroundView.tag = TAG_CartEmptyView; 251 | [self.view addSubview:backgroundView]; 252 | 253 | //默认图片 254 | UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:lz_CartEmptyString]]; 255 | img.center = CGPointMake(LZSCREEN_WIDTH/2.0, LZSCREEN_HEIGHT/2.0 - 120); 256 | img.bounds = CGRectMake(0, 0, 247.0/187 * 100, 100); 257 | [backgroundView addSubview:img]; 258 | 259 | UILabel *warnLabel = [[UILabel alloc]init]; 260 | warnLabel.center = CGPointMake(LZSCREEN_WIDTH/2.0, LZSCREEN_HEIGHT/2.0 - 10); 261 | warnLabel.bounds = CGRectMake(0, 0, LZSCREEN_WIDTH, 30); 262 | warnLabel.textAlignment = NSTextAlignmentCenter; 263 | warnLabel.text = @"购物车为空!"; 264 | warnLabel.font = [UIFont systemFontOfSize:15]; 265 | warnLabel.textColor = LZColorFromHex(0x706F6F); 266 | [backgroundView addSubview:warnLabel]; 267 | } 268 | #pragma mark -- 购物车有商品时的视图 269 | - (void)setupCartView { 270 | //创建底部视图 271 | [self setupCustomBottomView]; 272 | 273 | UITableView *table = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; 274 | 275 | table.delegate = self; 276 | table.dataSource = self; 277 | 278 | table.rowHeight = lz_CartRowHeight; 279 | table.separatorStyle = UITableViewCellSeparatorStyleNone; 280 | table.backgroundColor = LZColorFromRGB(245, 246, 248); 281 | [self.view addSubview:table]; 282 | self.myTableView = table; 283 | 284 | if (_isHasTabBarController) { 285 | table.frame = CGRectMake(0, LZNaigationBarHeight, LZSCREEN_WIDTH, LZSCREEN_HEIGHT - LZNaigationBarHeight - 2*LZTabBarHeight); 286 | } else { 287 | table.frame = CGRectMake(0, LZNaigationBarHeight, LZSCREEN_WIDTH, LZSCREEN_HEIGHT - LZNaigationBarHeight - LZTabBarHeight); 288 | } 289 | } 290 | #pragma mark --- UITableViewDataSource & UITableViewDelegate 291 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 292 | return self.dataArray.count; 293 | } 294 | 295 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 296 | LZCartTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LZCartReusableCell"]; 297 | if (cell == nil) { 298 | cell = [[LZCartTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"LZCartReusableCell"]; 299 | } 300 | 301 | LZCartModel *model = self.dataArray[indexPath.row]; 302 | __block typeof(cell)wsCell = cell; 303 | 304 | [cell numberAddWithBlock:^(NSInteger number) { 305 | wsCell.lzNumber = number; 306 | model.number = number; 307 | 308 | [self.dataArray replaceObjectAtIndex:indexPath.row withObject:model]; 309 | if ([self.selectedArray containsObject:model]) { 310 | [self.selectedArray removeObject:model]; 311 | [self.selectedArray addObject:model]; 312 | [self countPrice]; 313 | } 314 | }]; 315 | 316 | [cell numberCutWithBlock:^(NSInteger number) { 317 | 318 | wsCell.lzNumber = number; 319 | model.number = number; 320 | 321 | [self.dataArray replaceObjectAtIndex:indexPath.row withObject:model]; 322 | 323 | //判断已选择数组里有无该对象,有就删除 重新添加 324 | if ([self.selectedArray containsObject:model]) { 325 | [self.selectedArray removeObject:model]; 326 | [self.selectedArray addObject:model]; 327 | [self countPrice]; 328 | } 329 | }]; 330 | 331 | [cell cellSelectedWithBlock:^(BOOL select) { 332 | 333 | model.select = select; 334 | if (select) { 335 | [self.selectedArray addObject:model]; 336 | } else { 337 | [self.selectedArray removeObject:model]; 338 | } 339 | 340 | if (self.selectedArray.count == self.dataArray.count) { 341 | _allSellectedButton.selected = YES; 342 | } else { 343 | _allSellectedButton.selected = NO; 344 | } 345 | 346 | [self countPrice]; 347 | }]; 348 | 349 | [cell reloadDataWithModel:model]; 350 | return cell; 351 | } 352 | 353 | -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 354 | return @"删除"; 355 | } 356 | 357 | -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 358 | 359 | if (editingStyle == UITableViewCellEditingStyleDelete) { 360 | 361 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要删除该商品?删除后无法恢复!" preferredStyle:1]; 362 | UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 363 | 364 | LZCartModel *model = [self.dataArray objectAtIndex:indexPath.row]; 365 | 366 | [self.dataArray removeObjectAtIndex:indexPath.row]; 367 | // 删除 368 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 369 | 370 | //判断删除的商品是否已选择 371 | if ([self.selectedArray containsObject:model]) { 372 | //从已选中删除,重新计算价格 373 | [self.selectedArray removeObject:model]; 374 | [self countPrice]; 375 | } 376 | 377 | if (self.selectedArray.count == self.dataArray.count) { 378 | _allSellectedButton.selected = YES; 379 | } else { 380 | _allSellectedButton.selected = NO; 381 | } 382 | 383 | if (self.dataArray.count == 0) { 384 | [self changeView]; 385 | } 386 | 387 | //如果删除的时候数据紊乱,可延迟0.5s刷新一下 388 | [self performSelector:@selector(reloadTable) withObject:nil afterDelay:0.5]; 389 | 390 | }]; 391 | 392 | UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; 393 | 394 | [alert addAction:okAction]; 395 | [alert addAction:cancel]; 396 | [self presentViewController:alert animated:YES completion:nil]; 397 | } 398 | 399 | } 400 | - (void)reloadTable { 401 | [self.myTableView reloadData]; 402 | } 403 | #pragma mark -- 页面按钮点击事件 404 | #pragma mark --- 返回按钮点击事件 405 | - (void)backButtonClick:(UIButton*)button { 406 | if (_isHasNavitationController == NO) { 407 | [self dismissViewControllerAnimated:YES completion:nil]; 408 | } else { 409 | [self.navigationController popViewControllerAnimated:YES]; 410 | } 411 | } 412 | #pragma mark --- 全选按钮点击事件 413 | - (void)selectAllBtnClick:(UIButton*)button { 414 | button.selected = !button.selected; 415 | 416 | //点击全选时,把之前已选择的全部删除 417 | for (LZCartModel *model in self.selectedArray) { 418 | model.select = NO; 419 | } 420 | 421 | [self.selectedArray removeAllObjects]; 422 | 423 | if (button.selected) { 424 | 425 | for (LZCartModel *model in self.dataArray) { 426 | model.select = YES; 427 | [self.selectedArray addObject:model]; 428 | } 429 | } 430 | 431 | [self.myTableView reloadData]; 432 | [self countPrice]; 433 | } 434 | #pragma mark --- 确认选择,提交订单按钮点击事件 435 | - (void)goToPayButtonClick:(UIButton*)button { 436 | if (self.selectedArray.count > 0) { 437 | for (LZCartModel *model in self.selectedArray) { 438 | NSLog(@"选择的商品>>%@>>>%ld",model,(long)model.number); 439 | } 440 | } else { 441 | NSLog(@"你还没有选择任何商品"); 442 | } 443 | 444 | } 445 | 446 | - (void)didReceiveMemoryWarning { 447 | [super didReceiveMemoryWarning]; 448 | // Dispose of any resources that can be recreated. 449 | } 450 | 451 | /* 452 | #pragma mark - Navigation 453 | 454 | // In a storyboard-based application, you will often want to do a little preparation before navigation 455 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 456 | // Get the new view controller using [segue destinationViewController]. 457 | // Pass the selected object to the new view controller. 458 | } 459 | */ 460 | 461 | @end 462 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/back_button@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/back_button@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_addBtn_highlight@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_addBtn_highlight@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_addBtn_nomal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_addBtn_nomal@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_cutBtn_highlight@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_cutBtn_highlight@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_cutBtn_nomal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_cutBtn_nomal@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_default_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_default_bg.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_selected_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_selected_btn@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_unSelect_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/LZCartViewController/icons/cart_unSelect_btn@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LZCartViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | 22 | 23 | } 24 | - (IBAction)selector:(id)sender { 25 | LZCartViewController *cart = [[LZCartViewController alloc]init]; 26 | 27 | // UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:cart]; 28 | [self presentViewController:cart animated:YES completion:nil]; 29 | } 30 | - (void)didReceiveMemoryWarning { 31 | [super didReceiveMemoryWarning]; 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/aaa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController/aaa.jpg -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. 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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/LZCarViewController2.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 22 | 25 | 27 | 28 | 29 | 30 | 33 | 35 | 36 | 38 | 39 | 40 | 42 | 43 | 45 | 46 | 49 | 51 | 52 | 54 | 55 | 56 | 58 | 59 | 61 | 62 | 64 | 65 | 66 | 68 | 69 | 72 | 74 | 75 | 77 | 78 | 79 | 82 | 84 | 85 | 87 | 88 | 89 | 90 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/LZCarViewController2.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/LZCarViewController2.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 91610F081D40798D0083FF5D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 91610F071D40798D0083FF5D /* main.m */; }; 11 | 91610F0B1D40798D0083FF5D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 91610F0A1D40798D0083FF5D /* AppDelegate.m */; }; 12 | 91610F0E1D40798D0083FF5D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 91610F0D1D40798D0083FF5D /* ViewController.m */; }; 13 | 91610F111D40798D0083FF5D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91610F0F1D40798D0083FF5D /* Main.storyboard */; }; 14 | 91610F141D40798D0083FF5D /* UINavigationBar.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 91610F121D40798D0083FF5D /* UINavigationBar.xcdatamodeld */; }; 15 | 91610F161D40798D0083FF5D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 91610F151D40798D0083FF5D /* Assets.xcassets */; }; 16 | 91610F191D40798D0083FF5D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91610F171D40798D0083FF5D /* LaunchScreen.storyboard */; }; 17 | 91610F241D40798D0083FF5D /* UINavigationBarTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 91610F231D40798D0083FF5D /* UINavigationBarTests.m */; }; 18 | 91610F2F1D40798D0083FF5D /* UINavigationBarUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 91610F2E1D40798D0083FF5D /* UINavigationBarUITests.m */; }; 19 | 91610F451D40AA580083FF5D /* LZNavigationTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 91610F441D40AA580083FF5D /* LZNavigationTool.m */; }; 20 | 91610F471D40B5CA0083FF5D /* 40fe711f9b754b596159f3a6.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 91610F461D40B5CA0083FF5D /* 40fe711f9b754b596159f3a6.jpg */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 91610F201D40798D0083FF5D /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 91610EFB1D40798D0083FF5D /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 91610F021D40798D0083FF5D; 29 | remoteInfo = UINavigationBar; 30 | }; 31 | 91610F2B1D40798D0083FF5D /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 91610EFB1D40798D0083FF5D /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 91610F021D40798D0083FF5D; 36 | remoteInfo = UINavigationBar; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 91610F031D40798D0083FF5D /* UINavigationBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UINavigationBar.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 91610F071D40798D0083FF5D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 43 | 91610F091D40798D0083FF5D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | 91610F0A1D40798D0083FF5D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | 91610F0C1D40798D0083FF5D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 46 | 91610F0D1D40798D0083FF5D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 47 | 91610F101D40798D0083FF5D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | 91610F131D40798D0083FF5D /* UINavigationBar.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = UINavigationBar.xcdatamodel; sourceTree = ""; }; 49 | 91610F151D40798D0083FF5D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 50 | 91610F181D40798D0083FF5D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | 91610F1A1D40798D0083FF5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 91610F1F1D40798D0083FF5D /* UINavigationBarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UINavigationBarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 91610F231D40798D0083FF5D /* UINavigationBarTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UINavigationBarTests.m; sourceTree = ""; }; 54 | 91610F251D40798D0083FF5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | 91610F2A1D40798D0083FF5D /* UINavigationBarUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UINavigationBarUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56 | 91610F2E1D40798D0083FF5D /* UINavigationBarUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UINavigationBarUITests.m; sourceTree = ""; }; 57 | 91610F301D40798D0083FF5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | 91610F431D40AA580083FF5D /* LZNavigationTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LZNavigationTool.h; sourceTree = ""; }; 59 | 91610F441D40AA580083FF5D /* LZNavigationTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LZNavigationTool.m; sourceTree = ""; }; 60 | 91610F461D40B5CA0083FF5D /* 40fe711f9b754b596159f3a6.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 40fe711f9b754b596159f3a6.jpg; sourceTree = ""; }; 61 | /* End PBXFileReference section */ 62 | 63 | /* Begin PBXFrameworksBuildPhase section */ 64 | 91610F001D40798D0083FF5D /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | 91610F1C1D40798D0083FF5D /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | 91610F271D40798D0083FF5D /* Frameworks */ = { 79 | isa = PBXFrameworksBuildPhase; 80 | buildActionMask = 2147483647; 81 | files = ( 82 | ); 83 | runOnlyForDeploymentPostprocessing = 0; 84 | }; 85 | /* End PBXFrameworksBuildPhase section */ 86 | 87 | /* Begin PBXGroup section */ 88 | 91610EFA1D40798D0083FF5D = { 89 | isa = PBXGroup; 90 | children = ( 91 | 91610F051D40798D0083FF5D /* UINavigationBar */, 92 | 91610F221D40798D0083FF5D /* UINavigationBarTests */, 93 | 91610F2D1D40798D0083FF5D /* UINavigationBarUITests */, 94 | 91610F041D40798D0083FF5D /* Products */, 95 | ); 96 | sourceTree = ""; 97 | }; 98 | 91610F041D40798D0083FF5D /* Products */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 91610F031D40798D0083FF5D /* UINavigationBar.app */, 102 | 91610F1F1D40798D0083FF5D /* UINavigationBarTests.xctest */, 103 | 91610F2A1D40798D0083FF5D /* UINavigationBarUITests.xctest */, 104 | ); 105 | name = Products; 106 | sourceTree = ""; 107 | }; 108 | 91610F051D40798D0083FF5D /* UINavigationBar */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 91610F461D40B5CA0083FF5D /* 40fe711f9b754b596159f3a6.jpg */, 112 | 91610F3C1D4079990083FF5D /* UINavigationBar */, 113 | 91610F091D40798D0083FF5D /* AppDelegate.h */, 114 | 91610F0A1D40798D0083FF5D /* AppDelegate.m */, 115 | 91610F0C1D40798D0083FF5D /* ViewController.h */, 116 | 91610F0D1D40798D0083FF5D /* ViewController.m */, 117 | 91610F0F1D40798D0083FF5D /* Main.storyboard */, 118 | 91610F151D40798D0083FF5D /* Assets.xcassets */, 119 | 91610F171D40798D0083FF5D /* LaunchScreen.storyboard */, 120 | 91610F1A1D40798D0083FF5D /* Info.plist */, 121 | 91610F121D40798D0083FF5D /* UINavigationBar.xcdatamodeld */, 122 | 91610F061D40798D0083FF5D /* Supporting Files */, 123 | ); 124 | path = UINavigationBar; 125 | sourceTree = ""; 126 | }; 127 | 91610F061D40798D0083FF5D /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 91610F071D40798D0083FF5D /* main.m */, 131 | ); 132 | name = "Supporting Files"; 133 | sourceTree = ""; 134 | }; 135 | 91610F221D40798D0083FF5D /* UINavigationBarTests */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 91610F231D40798D0083FF5D /* UINavigationBarTests.m */, 139 | 91610F251D40798D0083FF5D /* Info.plist */, 140 | ); 141 | path = UINavigationBarTests; 142 | sourceTree = ""; 143 | }; 144 | 91610F2D1D40798D0083FF5D /* UINavigationBarUITests */ = { 145 | isa = PBXGroup; 146 | children = ( 147 | 91610F2E1D40798D0083FF5D /* UINavigationBarUITests.m */, 148 | 91610F301D40798D0083FF5D /* Info.plist */, 149 | ); 150 | path = UINavigationBarUITests; 151 | sourceTree = ""; 152 | }; 153 | 91610F3C1D4079990083FF5D /* UINavigationBar */ = { 154 | isa = PBXGroup; 155 | children = ( 156 | 91610F431D40AA580083FF5D /* LZNavigationTool.h */, 157 | 91610F441D40AA580083FF5D /* LZNavigationTool.m */, 158 | ); 159 | path = UINavigationBar; 160 | sourceTree = ""; 161 | }; 162 | /* End PBXGroup section */ 163 | 164 | /* Begin PBXNativeTarget section */ 165 | 91610F021D40798D0083FF5D /* UINavigationBar */ = { 166 | isa = PBXNativeTarget; 167 | buildConfigurationList = 91610F331D40798D0083FF5D /* Build configuration list for PBXNativeTarget "UINavigationBar" */; 168 | buildPhases = ( 169 | 91610EFF1D40798D0083FF5D /* Sources */, 170 | 91610F001D40798D0083FF5D /* Frameworks */, 171 | 91610F011D40798D0083FF5D /* Resources */, 172 | ); 173 | buildRules = ( 174 | ); 175 | dependencies = ( 176 | ); 177 | name = UINavigationBar; 178 | productName = UINavigationBar; 179 | productReference = 91610F031D40798D0083FF5D /* UINavigationBar.app */; 180 | productType = "com.apple.product-type.application"; 181 | }; 182 | 91610F1E1D40798D0083FF5D /* UINavigationBarTests */ = { 183 | isa = PBXNativeTarget; 184 | buildConfigurationList = 91610F361D40798D0083FF5D /* Build configuration list for PBXNativeTarget "UINavigationBarTests" */; 185 | buildPhases = ( 186 | 91610F1B1D40798D0083FF5D /* Sources */, 187 | 91610F1C1D40798D0083FF5D /* Frameworks */, 188 | 91610F1D1D40798D0083FF5D /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | 91610F211D40798D0083FF5D /* PBXTargetDependency */, 194 | ); 195 | name = UINavigationBarTests; 196 | productName = UINavigationBarTests; 197 | productReference = 91610F1F1D40798D0083FF5D /* UINavigationBarTests.xctest */; 198 | productType = "com.apple.product-type.bundle.unit-test"; 199 | }; 200 | 91610F291D40798D0083FF5D /* UINavigationBarUITests */ = { 201 | isa = PBXNativeTarget; 202 | buildConfigurationList = 91610F391D40798D0083FF5D /* Build configuration list for PBXNativeTarget "UINavigationBarUITests" */; 203 | buildPhases = ( 204 | 91610F261D40798D0083FF5D /* Sources */, 205 | 91610F271D40798D0083FF5D /* Frameworks */, 206 | 91610F281D40798D0083FF5D /* Resources */, 207 | ); 208 | buildRules = ( 209 | ); 210 | dependencies = ( 211 | 91610F2C1D40798D0083FF5D /* PBXTargetDependency */, 212 | ); 213 | name = UINavigationBarUITests; 214 | productName = UINavigationBarUITests; 215 | productReference = 91610F2A1D40798D0083FF5D /* UINavigationBarUITests.xctest */; 216 | productType = "com.apple.product-type.bundle.ui-testing"; 217 | }; 218 | /* End PBXNativeTarget section */ 219 | 220 | /* Begin PBXProject section */ 221 | 91610EFB1D40798D0083FF5D /* Project object */ = { 222 | isa = PBXProject; 223 | attributes = { 224 | LastUpgradeCheck = 0730; 225 | ORGANIZATIONNAME = Artup; 226 | TargetAttributes = { 227 | 91610F021D40798D0083FF5D = { 228 | CreatedOnToolsVersion = 7.3; 229 | }; 230 | 91610F1E1D40798D0083FF5D = { 231 | CreatedOnToolsVersion = 7.3; 232 | TestTargetID = 91610F021D40798D0083FF5D; 233 | }; 234 | 91610F291D40798D0083FF5D = { 235 | CreatedOnToolsVersion = 7.3; 236 | TestTargetID = 91610F021D40798D0083FF5D; 237 | }; 238 | }; 239 | }; 240 | buildConfigurationList = 91610EFE1D40798D0083FF5D /* Build configuration list for PBXProject "UINavigationBar" */; 241 | compatibilityVersion = "Xcode 3.2"; 242 | developmentRegion = English; 243 | hasScannedForEncodings = 0; 244 | knownRegions = ( 245 | en, 246 | Base, 247 | ); 248 | mainGroup = 91610EFA1D40798D0083FF5D; 249 | productRefGroup = 91610F041D40798D0083FF5D /* Products */; 250 | projectDirPath = ""; 251 | projectRoot = ""; 252 | targets = ( 253 | 91610F021D40798D0083FF5D /* UINavigationBar */, 254 | 91610F1E1D40798D0083FF5D /* UINavigationBarTests */, 255 | 91610F291D40798D0083FF5D /* UINavigationBarUITests */, 256 | ); 257 | }; 258 | /* End PBXProject section */ 259 | 260 | /* Begin PBXResourcesBuildPhase section */ 261 | 91610F011D40798D0083FF5D /* Resources */ = { 262 | isa = PBXResourcesBuildPhase; 263 | buildActionMask = 2147483647; 264 | files = ( 265 | 91610F191D40798D0083FF5D /* LaunchScreen.storyboard in Resources */, 266 | 91610F471D40B5CA0083FF5D /* 40fe711f9b754b596159f3a6.jpg in Resources */, 267 | 91610F161D40798D0083FF5D /* Assets.xcassets in Resources */, 268 | 91610F111D40798D0083FF5D /* Main.storyboard in Resources */, 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | }; 272 | 91610F1D1D40798D0083FF5D /* Resources */ = { 273 | isa = PBXResourcesBuildPhase; 274 | buildActionMask = 2147483647; 275 | files = ( 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | }; 279 | 91610F281D40798D0083FF5D /* Resources */ = { 280 | isa = PBXResourcesBuildPhase; 281 | buildActionMask = 2147483647; 282 | files = ( 283 | ); 284 | runOnlyForDeploymentPostprocessing = 0; 285 | }; 286 | /* End PBXResourcesBuildPhase section */ 287 | 288 | /* Begin PBXSourcesBuildPhase section */ 289 | 91610EFF1D40798D0083FF5D /* Sources */ = { 290 | isa = PBXSourcesBuildPhase; 291 | buildActionMask = 2147483647; 292 | files = ( 293 | 91610F0E1D40798D0083FF5D /* ViewController.m in Sources */, 294 | 91610F0B1D40798D0083FF5D /* AppDelegate.m in Sources */, 295 | 91610F081D40798D0083FF5D /* main.m in Sources */, 296 | 91610F451D40AA580083FF5D /* LZNavigationTool.m in Sources */, 297 | 91610F141D40798D0083FF5D /* UINavigationBar.xcdatamodeld in Sources */, 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | 91610F1B1D40798D0083FF5D /* Sources */ = { 302 | isa = PBXSourcesBuildPhase; 303 | buildActionMask = 2147483647; 304 | files = ( 305 | 91610F241D40798D0083FF5D /* UINavigationBarTests.m in Sources */, 306 | ); 307 | runOnlyForDeploymentPostprocessing = 0; 308 | }; 309 | 91610F261D40798D0083FF5D /* Sources */ = { 310 | isa = PBXSourcesBuildPhase; 311 | buildActionMask = 2147483647; 312 | files = ( 313 | 91610F2F1D40798D0083FF5D /* UINavigationBarUITests.m in Sources */, 314 | ); 315 | runOnlyForDeploymentPostprocessing = 0; 316 | }; 317 | /* End PBXSourcesBuildPhase section */ 318 | 319 | /* Begin PBXTargetDependency section */ 320 | 91610F211D40798D0083FF5D /* PBXTargetDependency */ = { 321 | isa = PBXTargetDependency; 322 | target = 91610F021D40798D0083FF5D /* UINavigationBar */; 323 | targetProxy = 91610F201D40798D0083FF5D /* PBXContainerItemProxy */; 324 | }; 325 | 91610F2C1D40798D0083FF5D /* PBXTargetDependency */ = { 326 | isa = PBXTargetDependency; 327 | target = 91610F021D40798D0083FF5D /* UINavigationBar */; 328 | targetProxy = 91610F2B1D40798D0083FF5D /* PBXContainerItemProxy */; 329 | }; 330 | /* End PBXTargetDependency section */ 331 | 332 | /* Begin PBXVariantGroup section */ 333 | 91610F0F1D40798D0083FF5D /* Main.storyboard */ = { 334 | isa = PBXVariantGroup; 335 | children = ( 336 | 91610F101D40798D0083FF5D /* Base */, 337 | ); 338 | name = Main.storyboard; 339 | sourceTree = ""; 340 | }; 341 | 91610F171D40798D0083FF5D /* LaunchScreen.storyboard */ = { 342 | isa = PBXVariantGroup; 343 | children = ( 344 | 91610F181D40798D0083FF5D /* Base */, 345 | ); 346 | name = LaunchScreen.storyboard; 347 | sourceTree = ""; 348 | }; 349 | /* End PBXVariantGroup section */ 350 | 351 | /* Begin XCBuildConfiguration section */ 352 | 91610F311D40798D0083FF5D /* Debug */ = { 353 | isa = XCBuildConfiguration; 354 | buildSettings = { 355 | ALWAYS_SEARCH_USER_PATHS = NO; 356 | CLANG_ANALYZER_NONNULL = YES; 357 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 358 | CLANG_CXX_LIBRARY = "libc++"; 359 | CLANG_ENABLE_MODULES = YES; 360 | CLANG_ENABLE_OBJC_ARC = YES; 361 | CLANG_WARN_BOOL_CONVERSION = YES; 362 | CLANG_WARN_CONSTANT_CONVERSION = YES; 363 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 364 | CLANG_WARN_EMPTY_BODY = YES; 365 | CLANG_WARN_ENUM_CONVERSION = YES; 366 | CLANG_WARN_INT_CONVERSION = YES; 367 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 368 | CLANG_WARN_UNREACHABLE_CODE = YES; 369 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 370 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 371 | COPY_PHASE_STRIP = NO; 372 | DEBUG_INFORMATION_FORMAT = dwarf; 373 | ENABLE_STRICT_OBJC_MSGSEND = YES; 374 | ENABLE_TESTABILITY = YES; 375 | GCC_C_LANGUAGE_STANDARD = gnu99; 376 | GCC_DYNAMIC_NO_PIC = NO; 377 | GCC_NO_COMMON_BLOCKS = YES; 378 | GCC_OPTIMIZATION_LEVEL = 0; 379 | GCC_PREPROCESSOR_DEFINITIONS = ( 380 | "DEBUG=1", 381 | "$(inherited)", 382 | ); 383 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 384 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 385 | GCC_WARN_UNDECLARED_SELECTOR = YES; 386 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 387 | GCC_WARN_UNUSED_FUNCTION = YES; 388 | GCC_WARN_UNUSED_VARIABLE = YES; 389 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 390 | MTL_ENABLE_DEBUG_INFO = YES; 391 | ONLY_ACTIVE_ARCH = YES; 392 | SDKROOT = iphoneos; 393 | TARGETED_DEVICE_FAMILY = "1,2"; 394 | }; 395 | name = Debug; 396 | }; 397 | 91610F321D40798D0083FF5D /* Release */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | ALWAYS_SEARCH_USER_PATHS = NO; 401 | CLANG_ANALYZER_NONNULL = YES; 402 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 403 | CLANG_CXX_LIBRARY = "libc++"; 404 | CLANG_ENABLE_MODULES = YES; 405 | CLANG_ENABLE_OBJC_ARC = YES; 406 | CLANG_WARN_BOOL_CONVERSION = YES; 407 | CLANG_WARN_CONSTANT_CONVERSION = YES; 408 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 409 | CLANG_WARN_EMPTY_BODY = YES; 410 | CLANG_WARN_ENUM_CONVERSION = YES; 411 | CLANG_WARN_INT_CONVERSION = YES; 412 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 413 | CLANG_WARN_UNREACHABLE_CODE = YES; 414 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 415 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 416 | COPY_PHASE_STRIP = NO; 417 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 418 | ENABLE_NS_ASSERTIONS = NO; 419 | ENABLE_STRICT_OBJC_MSGSEND = YES; 420 | GCC_C_LANGUAGE_STANDARD = gnu99; 421 | GCC_NO_COMMON_BLOCKS = YES; 422 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 423 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 424 | GCC_WARN_UNDECLARED_SELECTOR = YES; 425 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 426 | GCC_WARN_UNUSED_FUNCTION = YES; 427 | GCC_WARN_UNUSED_VARIABLE = YES; 428 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 429 | MTL_ENABLE_DEBUG_INFO = NO; 430 | SDKROOT = iphoneos; 431 | TARGETED_DEVICE_FAMILY = "1,2"; 432 | VALIDATE_PRODUCT = YES; 433 | }; 434 | name = Release; 435 | }; 436 | 91610F341D40798D0083FF5D /* Debug */ = { 437 | isa = XCBuildConfiguration; 438 | buildSettings = { 439 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 440 | INFOPLIST_FILE = UINavigationBar/Info.plist; 441 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 442 | PRODUCT_BUNDLE_IDENTIFIER = com.artup.UINavigationBar; 443 | PRODUCT_NAME = "$(TARGET_NAME)"; 444 | }; 445 | name = Debug; 446 | }; 447 | 91610F351D40798D0083FF5D /* Release */ = { 448 | isa = XCBuildConfiguration; 449 | buildSettings = { 450 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 451 | INFOPLIST_FILE = UINavigationBar/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 453 | PRODUCT_BUNDLE_IDENTIFIER = com.artup.UINavigationBar; 454 | PRODUCT_NAME = "$(TARGET_NAME)"; 455 | }; 456 | name = Release; 457 | }; 458 | 91610F371D40798D0083FF5D /* Debug */ = { 459 | isa = XCBuildConfiguration; 460 | buildSettings = { 461 | BUNDLE_LOADER = "$(TEST_HOST)"; 462 | INFOPLIST_FILE = UINavigationBarTests/Info.plist; 463 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 464 | PRODUCT_BUNDLE_IDENTIFIER = com.artup.UINavigationBarTests; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UINavigationBar.app/UINavigationBar"; 467 | }; 468 | name = Debug; 469 | }; 470 | 91610F381D40798D0083FF5D /* Release */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | BUNDLE_LOADER = "$(TEST_HOST)"; 474 | INFOPLIST_FILE = UINavigationBarTests/Info.plist; 475 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 476 | PRODUCT_BUNDLE_IDENTIFIER = com.artup.UINavigationBarTests; 477 | PRODUCT_NAME = "$(TARGET_NAME)"; 478 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UINavigationBar.app/UINavigationBar"; 479 | }; 480 | name = Release; 481 | }; 482 | 91610F3A1D40798D0083FF5D /* Debug */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | INFOPLIST_FILE = UINavigationBarUITests/Info.plist; 486 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 487 | PRODUCT_BUNDLE_IDENTIFIER = com.artup.UINavigationBarUITests; 488 | PRODUCT_NAME = "$(TARGET_NAME)"; 489 | TEST_TARGET_NAME = UINavigationBar; 490 | }; 491 | name = Debug; 492 | }; 493 | 91610F3B1D40798D0083FF5D /* Release */ = { 494 | isa = XCBuildConfiguration; 495 | buildSettings = { 496 | INFOPLIST_FILE = UINavigationBarUITests/Info.plist; 497 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 498 | PRODUCT_BUNDLE_IDENTIFIER = com.artup.UINavigationBarUITests; 499 | PRODUCT_NAME = "$(TARGET_NAME)"; 500 | TEST_TARGET_NAME = UINavigationBar; 501 | }; 502 | name = Release; 503 | }; 504 | /* End XCBuildConfiguration section */ 505 | 506 | /* Begin XCConfigurationList section */ 507 | 91610EFE1D40798D0083FF5D /* Build configuration list for PBXProject "UINavigationBar" */ = { 508 | isa = XCConfigurationList; 509 | buildConfigurations = ( 510 | 91610F311D40798D0083FF5D /* Debug */, 511 | 91610F321D40798D0083FF5D /* Release */, 512 | ); 513 | defaultConfigurationIsVisible = 0; 514 | defaultConfigurationName = Release; 515 | }; 516 | 91610F331D40798D0083FF5D /* Build configuration list for PBXNativeTarget "UINavigationBar" */ = { 517 | isa = XCConfigurationList; 518 | buildConfigurations = ( 519 | 91610F341D40798D0083FF5D /* Debug */, 520 | 91610F351D40798D0083FF5D /* Release */, 521 | ); 522 | defaultConfigurationIsVisible = 0; 523 | }; 524 | 91610F361D40798D0083FF5D /* Build configuration list for PBXNativeTarget "UINavigationBarTests" */ = { 525 | isa = XCConfigurationList; 526 | buildConfigurations = ( 527 | 91610F371D40798D0083FF5D /* Debug */, 528 | 91610F381D40798D0083FF5D /* Release */, 529 | ); 530 | defaultConfigurationIsVisible = 0; 531 | }; 532 | 91610F391D40798D0083FF5D /* Build configuration list for PBXNativeTarget "UINavigationBarUITests" */ = { 533 | isa = XCConfigurationList; 534 | buildConfigurations = ( 535 | 91610F3A1D40798D0083FF5D /* Debug */, 536 | 91610F3B1D40798D0083FF5D /* Release */, 537 | ); 538 | defaultConfigurationIsVisible = 0; 539 | }; 540 | /* End XCConfigurationList section */ 541 | 542 | /* Begin XCVersionGroup section */ 543 | 91610F121D40798D0083FF5D /* UINavigationBar.xcdatamodeld */ = { 544 | isa = XCVersionGroup; 545 | children = ( 546 | 91610F131D40798D0083FF5D /* UINavigationBar.xcdatamodel */, 547 | ); 548 | currentVersion = 91610F131D40798D0083FF5D /* UINavigationBar.xcdatamodel */; 549 | path = UINavigationBar.xcdatamodeld; 550 | sourceTree = ""; 551 | versionGroupType = wrapper.xcdatamodel; 552 | }; 553 | /* End XCVersionGroup section */ 554 | }; 555 | rootObject = 91610EFB1D40798D0083FF5D /* Project object */; 556 | } 557 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/UINavigationBar.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UINavigationBar.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 91610F021D40798D0083FF5D 16 | 17 | primary 18 | 19 | 20 | 91610F1E1D40798D0083FF5D 21 | 22 | primary 23 | 24 | 25 | 91610F291D40798D0083FF5D 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/40fe711f9b754b596159f3a6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/40fe711f9b754b596159f3a6.jpg -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (strong, nonatomic) UIWindow *window; 15 | 16 | @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; 17 | @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; 18 | @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; 19 | 20 | - (void)saveContext; 21 | - (NSURL *)applicationDocumentsDirectory; 22 | 23 | 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | // Override point for customization after application launch. 21 | 22 | ViewController *view = [[ViewController alloc]init]; 23 | 24 | UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:view]; 25 | 26 | self.window.rootViewController = nav; 27 | return YES; 28 | } 29 | 30 | - (void)applicationWillResignActive:(UIApplication *)application { 31 | // 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. 32 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 33 | } 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application { 36 | // 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. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | - (void)applicationWillEnterForeground:(UIApplication *)application { 41 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 42 | } 43 | 44 | - (void)applicationDidBecomeActive:(UIApplication *)application { 45 | // 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. 46 | } 47 | 48 | - (void)applicationWillTerminate:(UIApplication *)application { 49 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 50 | // Saves changes in the application's managed object context before the application terminates. 51 | [self saveContext]; 52 | } 53 | 54 | #pragma mark - Core Data stack 55 | 56 | @synthesize managedObjectContext = _managedObjectContext; 57 | @synthesize managedObjectModel = _managedObjectModel; 58 | @synthesize persistentStoreCoordinator = _persistentStoreCoordinator; 59 | 60 | - (NSURL *)applicationDocumentsDirectory { 61 | // The directory the application uses to store the Core Data store file. This code uses a directory named "com.artup.UINavigationBar" in the application's documents directory. 62 | return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 63 | } 64 | 65 | - (NSManagedObjectModel *)managedObjectModel { 66 | // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. 67 | if (_managedObjectModel != nil) { 68 | return _managedObjectModel; 69 | } 70 | NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UINavigationBar" withExtension:@"momd"]; 71 | _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 72 | return _managedObjectModel; 73 | } 74 | 75 | - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 76 | // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. 77 | if (_persistentStoreCoordinator != nil) { 78 | return _persistentStoreCoordinator; 79 | } 80 | 81 | // Create the coordinator and store 82 | 83 | _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 84 | NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"UINavigationBar.sqlite"]; 85 | NSError *error = nil; 86 | NSString *failureReason = @"There was an error creating or loading the application's saved data."; 87 | if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 88 | // Report any error we got. 89 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 90 | dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data"; 91 | dict[NSLocalizedFailureReasonErrorKey] = failureReason; 92 | dict[NSUnderlyingErrorKey] = error; 93 | error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; 94 | // Replace this with code to handle the error appropriately. 95 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 96 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 97 | abort(); 98 | } 99 | 100 | return _persistentStoreCoordinator; 101 | } 102 | 103 | 104 | - (NSManagedObjectContext *)managedObjectContext { 105 | // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) 106 | if (_managedObjectContext != nil) { 107 | return _managedObjectContext; 108 | } 109 | 110 | NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; 111 | if (!coordinator) { 112 | return nil; 113 | } 114 | _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; 115 | [_managedObjectContext setPersistentStoreCoordinator:coordinator]; 116 | return _managedObjectContext; 117 | } 118 | 119 | #pragma mark - Core Data Saving support 120 | 121 | - (void)saveContext { 122 | NSManagedObjectContext *managedObjectContext = self.managedObjectContext; 123 | if (managedObjectContext != nil) { 124 | NSError *error = nil; 125 | if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { 126 | // Replace this implementation with code to handle the error appropriately. 127 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 128 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 129 | abort(); 130 | } 131 | } 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/UINavigationBar.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | UINavigationBar.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/UINavigationBar.xcdatamodeld/UINavigationBar.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/UINavigationBar/LZNavigationTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZNavigationTool.h 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | // nullable 可为nil 9 | // nonnull 不可为nil 10 | 11 | #import 12 | #import 13 | 14 | @interface LZNavigationTool : NSObject 15 | 16 | + (void)naviBarInViewController:(nonnull UIViewController *)vc backgroundColor:(nullable UIColor *)color; 17 | 18 | + (void)naviBarInViewController:(nonnull UIViewController *)vc backgroundImage:(nullable NSString *)imageName; 19 | + (void)naviBarInViewController:(nonnull UIViewController *)vc backgroundImageWithColor:(nullable UIColor *)color alpha:(CGFloat)alpha; 20 | + (void)addLeftBarButtonToViewController:(nonnull UIViewController *)vc withTitle:(nullable NSString *)title target:(nullable id)target action:(nullable SEL)action; 21 | + (void)addLeftBarButtonToViewController:(nonnull UIViewController *)vc withImageName:(nullable NSString *)imageName target:(nullable id)target action:(nullable SEL)action; 22 | + (void)addRightBarButtonToViewController:(nonnull UIViewController *)vc withTitle:(nullable NSString *)title target:(nullable id)target action:(nullable SEL)action; 23 | + (void)addRightBarButtonToViewController:(nonnull UIViewController *)vc withImageName:(nullable NSString *)imageName target:(nullable id)target action:(nullable SEL)action; 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/UINavigationBar/LZNavigationTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZNavigationTool.m 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "LZNavigationTool.h" 10 | 11 | @implementation LZNavigationTool 12 | 13 | + (void)naviBarInViewController:(UIViewController *)vc backgroundColor:(UIColor *)color { 14 | 15 | vc.navigationController.navigationBar.barTintColor = color; 16 | } 17 | + (void)naviBarInViewController:(UIViewController *)vc backgroundImage:(NSString *)imageName { 18 | 19 | // [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:imageName] forBarMetrics:UIBarMetricsDefault]; 20 | 21 | [vc.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:imageName] forBarMetrics:UIBarMetricsDefault]; 22 | } 23 | 24 | + (void)naviBarInViewController:(UIViewController *)vc backgroundImageWithColor:(UIColor *)color alpha:(CGFloat)alpha { 25 | 26 | UIImage *image = [self imageWithColor:[color colorWithAlphaComponent:alpha]]; 27 | 28 | // [[UINavigationBar appearance]setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 29 | [vc.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 30 | } 31 | + (void)addLeftBarButtonToViewController:(UIViewController *)vc withTitle:(NSString *)title target:(nullable id)target action:(nullable SEL)action { 32 | 33 | UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithTitle:title style:UIBarButtonItemStylePlain target:target action:action]; 34 | barButton.tintColor = [UIColor redColor]; 35 | 36 | vc.navigationItem.leftBarButtonItem = barButton; 37 | 38 | } 39 | 40 | + (void)addLeftBarButtonToViewController:(UIViewController *)vc withImageName:(NSString *)imageName target:(nullable id)target action:(nullable SEL)action{ 41 | 42 | UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStylePlain target:target action:action]; 43 | vc.navigationItem.leftBarButtonItem = barButton; 44 | } 45 | 46 | + (void)addRightBarButtonToViewController:(UIViewController *)vc withTitle:(NSString *)title target:(nullable id)target action:(nullable SEL)action{ 47 | 48 | UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithTitle:title style:UIBarButtonItemStylePlain target:target action:action]; 49 | 50 | vc.navigationItem.rightBarButtonItem = barButton; 51 | } 52 | 53 | + (void)addRightBarButtonToViewController:(UIViewController *)vc withImageName:(NSString *)imageName target:(nullable id)target action:(nullable SEL)action{ 54 | 55 | UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStylePlain target:target action:action]; 56 | vc.navigationItem.rightBarButtonItem = barButton; 57 | } 58 | 59 | + (UIImage *)imageWithColor:(UIColor *)color 60 | { 61 | // 描述矩形 62 | CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); 63 | 64 | // 开启位图上下文 65 | UIGraphicsBeginImageContext(rect.size); 66 | // 获取位图上下文 67 | CGContextRef context = UIGraphicsGetCurrentContext(); 68 | // 使用color演示填充上下文 69 | CGContextSetFillColorWithColor(context, [color CGColor]); 70 | // 渲染上下文 71 | CGContextFillRect(context, rect); 72 | // 从上下文中获取图片 73 | UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); 74 | // 结束上下文 75 | UIGraphicsEndImageContext(); 76 | 77 | return theImage; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LZNavigationTool.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | self.view.backgroundColor = [UIColor whiteColor]; 22 | // self.navigationItem.leftBarButtonItem 23 | self.title = @"aaaaa"; 24 | // [LZNavigationTool setNavigationBackgroundColor:[UIColor redColor]]; 25 | // 26 | // [LZNavigationTool addLeftBarButtonToViewController:self withTitle:@"back" target:self action:@selector(back)]; 27 | 28 | // [LZNavigationTool setNavBarBackgroundImageWithColor:[UIColor orangeColor] alpha:0.5]; 29 | 30 | [LZNavigationTool naviBarInViewController:self backgroundImage:@"40fe711f9b754b596159f3a6.jpg"]; 31 | [LZNavigationTool naviBarInViewController:self backgroundColor:[UIColor redColor]]; 32 | 33 | // [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"40fe711f9b754b596159f3a6.jpg"] forBarMetrics:UIBarMetricsDefault]; 34 | } 35 | 36 | - (void)didReceiveMemoryWarning { 37 | [super didReceiveMemoryWarning]; 38 | // Dispose of any resources that can be recreated. 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBar/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UINavigationBar 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. 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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBarTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBarTests/UINavigationBarTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBarTests.m 3 | // UINavigationBarTests 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UINavigationBarTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation UINavigationBarTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBarUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/UINavigationBar/UINavigationBarUITests/UINavigationBarUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBarUITests.m 3 | // UINavigationBarUITests 4 | // 5 | // Created by Artron_LQQ on 16/7/21. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UINavigationBarUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation UINavigationBarUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/LZCartViewController2.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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LZCartViewController2.xcscheme 8 | 9 | isShown 10 | 11 | orderHint 12 | 1 13 | 14 | 15 | SuppressBuildableAutocreation 16 | 17 | 9148CA611CEBFC8B0054A40A 18 | 19 | primary 20 | 21 | 22 | 9148CA7A1CEBFC8C0054A40A 23 | 24 | primary 25 | 26 | 27 | 9148CA851CEBFC8C0054A40A 28 | 29 | primary 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. 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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/ConfigFile/LZConfigFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZConfigFile.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #ifndef LZConfigFile_h 12 | #define LZConfigFile_h 13 | #import "UIViewExt.h" 14 | 15 | //16进制RGB的颜色转换 16 | #define LZColorFromHex(rgbValue) [UIColor \ 17 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 18 | green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 19 | blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 20 | 21 | //R G B 颜色 22 | #define LZColorFromRGB(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] 23 | 24 | //红色 25 | #define BASECOLOR_RED [UIColor \ 26 | colorWithRed:((float)((0xED5565 & 0xFF0000) >> 16))/255.0 \ 27 | green:((float)((0xED5565 & 0xFF00) >> 8))/255.0 \ 28 | blue:((float)(0xED5565 & 0xFF))/255.0 alpha:1.0] 29 | 30 | 31 | 32 | #define LZSCREEN_HEIGHT ([[UIScreen mainScreen]bounds].size.height) 33 | #define LZSCREEN_WIDTH ([[UIScreen mainScreen]bounds].size.width) 34 | #define LZNaigationBarHeight 64 35 | #define LZTabBarHeight 49 36 | #define LZTableViewHeaderHeight 40 37 | 38 | #define TAG_CartEmptyView 100 39 | 40 | 41 | static NSString *lz_BackButtonString = @"back_button"; 42 | static NSString *lz_Bottom_UnSelectButtonString = @"cart_unSelect_btn"; 43 | static NSString *lz_Bottom_SelectButtonString = @"cart_selected_btn"; 44 | static NSString *lz_CartEmptyString = @"cart_default_bg"; 45 | static NSInteger lz_CartRowHeight = 100; 46 | #endif /* LZConfigFile_h */ 47 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/ConfigFile/UIViewExt.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import 4 | //#import 5 | #import 6 | 7 | 8 | @interface UIView(UIViewExt) 9 | 10 | /** 11 | * Shortcut for frame.origin.x. 12 | * 13 | * Sets frame.origin.x = left 14 | */ 15 | @property (nonatomic) CGFloat left; 16 | 17 | /** 18 | * Shortcut for frame.origin.y 19 | * 20 | * Sets frame.origin.y = top 21 | */ 22 | @property (nonatomic) CGFloat top; 23 | 24 | /** 25 | * Shortcut for frame.origin.x + frame.size.width 26 | * 27 | * Sets frame.origin.x = right - frame.size.width 28 | */ 29 | @property (nonatomic) CGFloat right; 30 | 31 | /** 32 | * Shortcut for frame.origin.y + frame.size.height 33 | * 34 | * Sets frame.origin.y = bottom - frame.size.height 35 | */ 36 | @property (nonatomic) CGFloat bottom; 37 | 38 | /** 39 | * Shortcut for frame.size.width 40 | * 41 | * Sets frame.size.width = width 42 | */ 43 | @property (nonatomic) CGFloat width; 44 | 45 | /** 46 | * Shortcut for frame.size.height 47 | * 48 | * Sets frame.size.height = height 49 | */ 50 | @property (nonatomic) CGFloat height; 51 | 52 | /** 53 | * Shortcut for center.x 54 | * 55 | * Sets center.x = centerX 56 | */ 57 | @property (nonatomic) CGFloat centerX; 58 | 59 | /** 60 | * Shortcut for center.y 61 | * 62 | * Sets center.y = centerY 63 | */ 64 | @property (nonatomic) CGFloat centerY; 65 | 66 | /** 67 | * Shortcut for frame.origin 68 | */ 69 | @property (nonatomic) CGPoint origin; 70 | 71 | /** 72 | * Shortcut for frame.size 73 | */ 74 | @property (nonatomic) CGSize size; 75 | 76 | @end -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/ConfigFile/UIViewExt.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "UIViewExt.h" 3 | @implementation UIView(UIViewExt) 4 | 5 | - (CGFloat)left { 6 | return self.frame.origin.x; 7 | } 8 | 9 | 10 | /////////////////////////////////////////////////////////////////////////////////////////////////// 11 | - (void)setLeft:(CGFloat)x { 12 | CGRect frame = self.frame; 13 | frame.origin.x = x; 14 | self.frame = frame; 15 | } 16 | 17 | 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// 19 | - (CGFloat)top { 20 | return self.frame.origin.y; 21 | } 22 | 23 | 24 | /////////////////////////////////////////////////////////////////////////////////////////////////// 25 | - (void)setTop:(CGFloat)y { 26 | CGRect frame = self.frame; 27 | frame.origin.y = y; 28 | self.frame = frame; 29 | } 30 | 31 | 32 | /////////////////////////////////////////////////////////////////////////////////////////////////// 33 | - (CGFloat)right { 34 | return self.frame.origin.x + self.width; 35 | } 36 | 37 | 38 | /////////////////////////////////////////////////////////////////////////////////////////////////// 39 | - (void)setRight:(CGFloat)right { 40 | CGRect frame = self.frame; 41 | frame.origin.x = right - frame.size.width; 42 | self.frame = frame; 43 | } 44 | 45 | 46 | /////////////////////////////////////////////////////////////////////////////////////////////////// 47 | - (CGFloat)bottom { 48 | return self.frame.origin.y + self.frame.size.height; 49 | } 50 | 51 | 52 | /////////////////////////////////////////////////////////////////////////////////////////////////// 53 | - (void)setBottom:(CGFloat)bottom { 54 | CGRect frame = self.frame; 55 | frame.origin.y = bottom - frame.size.height; 56 | self.frame = frame; 57 | } 58 | 59 | 60 | /////////////////////////////////////////////////////////////////////////////////////////////////// 61 | - (CGFloat)centerX { 62 | return self.center.x; 63 | } 64 | 65 | 66 | /////////////////////////////////////////////////////////////////////////////////////////////////// 67 | - (void)setCenterX:(CGFloat)centerX { 68 | self.center = CGPointMake(centerX, self.center.y); 69 | } 70 | 71 | 72 | /////////////////////////////////////////////////////////////////////////////////////////////////// 73 | - (CGFloat)centerY { 74 | return self.center.y; 75 | } 76 | 77 | 78 | /////////////////////////////////////////////////////////////////////////////////////////////////// 79 | - (void)setCenterY:(CGFloat)centerY { 80 | self.center = CGPointMake(self.center.x, centerY); 81 | } 82 | 83 | 84 | /////////////////////////////////////////////////////////////////////////////////////////////////// 85 | - (CGFloat)width { 86 | return self.frame.size.width; 87 | } 88 | 89 | 90 | /////////////////////////////////////////////////////////////////////////////////////////////////// 91 | - (void)setWidth:(CGFloat)width { 92 | CGRect frame = self.frame; 93 | frame.size.width = width; 94 | self.frame = frame; 95 | } 96 | 97 | 98 | /////////////////////////////////////////////////////////////////////////////////////////////////// 99 | - (CGFloat)height { 100 | return self.frame.size.height; 101 | } 102 | 103 | 104 | /////////////////////////////////////////////////////////////////////////////////////////////////// 105 | - (void)setHeight:(CGFloat)height { 106 | CGRect frame = self.frame; 107 | frame.size.height = height; 108 | self.frame = frame; 109 | } 110 | 111 | 112 | /////////////////////////////////////////////////////////////////////////////////////////////////// 113 | - (CGPoint)origin { 114 | return self.frame.origin; 115 | } 116 | 117 | 118 | /////////////////////////////////////////////////////////////////////////////////////////////////// 119 | - (void)setOrigin:(CGPoint)origin { 120 | CGRect frame = self.frame; 121 | frame.origin = origin; 122 | self.frame = frame; 123 | } 124 | 125 | 126 | /////////////////////////////////////////////////////////////////////////////////////////////////// 127 | - (CGSize)size { 128 | return self.frame.size; 129 | } 130 | 131 | 132 | /////////////////////////////////////////////////////////////////////////////////////////////////// 133 | - (void)setSize:(CGSize)size { 134 | CGRect frame = self.frame; 135 | frame.size = size; 136 | self.frame = frame; 137 | } 138 | @end -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartModel/LZGoodsModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZGoodsModel.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/31. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface LZGoodsModel : NSObject 13 | 14 | @property (nonatomic,assign) BOOL select; 15 | 16 | @property (assign,nonatomic)NSInteger count; 17 | @property (copy,nonatomic)NSString *goodsID; 18 | @property (copy,nonatomic)NSString *goodsName; 19 | @property (copy,nonatomic)NSString *price; 20 | @property (strong,nonatomic)UIImage *image; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartModel/LZGoodsModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZGoodsModel.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/31. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "LZGoodsModel.h" 10 | 11 | @implementation LZGoodsModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartModel/LZShopModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZShopModel.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/31. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LZShopModel : NSObject 12 | 13 | @property (assign,nonatomic)BOOL select; 14 | @property (copy,nonatomic)NSString *shopID; 15 | @property (copy,nonatomic)NSString *shopName; 16 | @property (copy,nonatomic)NSString *sID; 17 | @property (strong,nonatomic,readonly)NSMutableArray *goodsArray; 18 | 19 | - (void)configGoodsArrayWithArray:(NSArray*)array; 20 | @end 21 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartModel/LZShopModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZShopModel.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/31. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "LZShopModel.h" 10 | #import "LZGoodsModel.h" 11 | 12 | @implementation LZShopModel 13 | 14 | - (void)configGoodsArrayWithArray:(NSArray*)array; { 15 | if (array.count > 0) { 16 | NSMutableArray *dataArray = [NSMutableArray arrayWithCapacity:0]; 17 | for (NSDictionary *dic in array) { 18 | LZGoodsModel *model = [[LZGoodsModel alloc]init]; 19 | 20 | model.count = [[dic objectForKey:@"count"] integerValue]; 21 | model.goodsID = [dic objectForKey:@"goodsId"]; 22 | model.goodsName = [dic objectForKey:@"goodsName"]; 23 | model.price = [NSString stringWithFormat:@"%@",[dic objectForKey:@"realPrice"]]; 24 | 25 | [dataArray addObject:model]; 26 | } 27 | 28 | _goodsArray = [dataArray mutableCopy]; 29 | } 30 | } 31 | @end 32 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartTableViewCell/LZCartTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartTableViewCell.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import 12 | 13 | @class LZGoodsModel; 14 | typedef void(^LZNumberChangedBlock)(NSInteger number); 15 | typedef void(^LZCellSelectedBlock)(BOOL select); 16 | @interface LZCartTableViewCell : UITableViewCell 17 | //商品数量 18 | @property (assign,nonatomic)NSInteger lzNumber; 19 | @property (assign,nonatomic)BOOL lzSelected; 20 | 21 | - (void)reloadDataWithModel:(LZGoodsModel*)model; 22 | - (void)numberAddWithBlock:(LZNumberChangedBlock)block; 23 | - (void)numberCutWithBlock:(LZNumberChangedBlock)block; 24 | - (void)cellSelectedWithBlock:(LZCellSelectedBlock)block; 25 | @end 26 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartTableViewCell/LZCartTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartTableViewCell.m 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import "LZCartTableViewCell.h" 12 | #import "LZConfigFile.h" 13 | //#import "LZCartModel.h" 14 | #import "LZGoodsModel.h" 15 | 16 | 17 | @interface LZCartTableViewCell () 18 | { 19 | LZNumberChangedBlock numberAddBlock; 20 | LZNumberChangedBlock numberCutBlock; 21 | LZCellSelectedBlock cellSelectedBlock; 22 | } 23 | //选中按钮 24 | @property (nonatomic,retain) UIButton *selectBtn; 25 | //显示照片 26 | @property (nonatomic,retain) UIImageView *lzImageView; 27 | //商品名 28 | @property (nonatomic,retain) UILabel *nameLabel; 29 | //尺寸 30 | @property (nonatomic,retain) UILabel *sizeLabel; 31 | //时间 32 | @property (nonatomic,retain) UILabel *dateLabel; 33 | //价格 34 | @property (nonatomic,retain) UILabel *priceLabel; 35 | //数量 36 | @property (nonatomic,retain)UILabel *numberLabel; 37 | 38 | @end 39 | 40 | @implementation LZCartTableViewCell 41 | 42 | - (void)awakeFromNib { 43 | [super awakeFromNib]; 44 | // Initialization code 45 | } 46 | 47 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 48 | [super setSelected:selected animated:animated]; 49 | 50 | // Configure the view for the selected state 51 | } 52 | 53 | -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 54 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 55 | if (self) { 56 | self.backgroundColor = LZColorFromRGB(245, 246, 248); 57 | self.selectionStyle = UITableViewCellSelectionStyleNone; 58 | [self setupMainView]; 59 | } 60 | return self; 61 | } 62 | #pragma mark - public method 63 | - (void)reloadDataWithModel:(LZGoodsModel*)model { 64 | 65 | self.lzImageView.image = model.image; 66 | self.nameLabel.text = model.goodsName; 67 | self.priceLabel.text = model.price; 68 | self.dateLabel.text = model.price; 69 | self.numberLabel.text = [NSString stringWithFormat:@"%ld",(long)model.count]; 70 | // self.sizeLabel.text = model.sizeStr; 71 | self.selectBtn.selected = model.select; 72 | } 73 | 74 | - (void)numberAddWithBlock:(LZNumberChangedBlock)block { 75 | numberAddBlock = block; 76 | } 77 | 78 | - (void)numberCutWithBlock:(LZNumberChangedBlock)block { 79 | numberCutBlock = block; 80 | } 81 | 82 | - (void)cellSelectedWithBlock:(LZCellSelectedBlock)block { 83 | cellSelectedBlock = block; 84 | } 85 | #pragma mark - 重写setter方法 86 | - (void)setLzNumber:(NSInteger)lzNumber { 87 | _lzNumber = lzNumber; 88 | 89 | self.numberLabel.text = [NSString stringWithFormat:@"%ld",(long)lzNumber]; 90 | } 91 | 92 | - (void)setLzSelected:(BOOL)lzSelected { 93 | _lzSelected = lzSelected; 94 | self.selectBtn.selected = lzSelected; 95 | } 96 | #pragma mark - 按钮点击方法 97 | - (void)selectBtnClick:(UIButton*)button { 98 | button.selected = !button.selected; 99 | 100 | if (cellSelectedBlock) { 101 | cellSelectedBlock(button.selected); 102 | } 103 | } 104 | 105 | - (void)addBtnClick:(UIButton*)button { 106 | 107 | NSInteger count = [self.numberLabel.text integerValue]; 108 | count++; 109 | 110 | if (numberAddBlock) { 111 | numberAddBlock(count); 112 | } 113 | } 114 | 115 | - (void)cutBtnClick:(UIButton*)button { 116 | NSInteger count = [self.numberLabel.text integerValue]; 117 | count--; 118 | if(count <= 0){ 119 | return ; 120 | } 121 | 122 | if (numberCutBlock) { 123 | numberCutBlock(count); 124 | } 125 | } 126 | #pragma mark - 布局主视图 127 | -(void)setupMainView { 128 | //白色背景 129 | UIView *bgView = [[UIView alloc]init]; 130 | bgView.frame = CGRectMake(10, 10, LZSCREEN_WIDTH - 20, lz_CartRowHeight - 10); 131 | bgView.backgroundColor = [UIColor whiteColor]; 132 | bgView.layer.borderColor = LZColorFromHex(0xEEEEEE).CGColor; 133 | bgView.layer.borderWidth = 1; 134 | [self addSubview:bgView]; 135 | 136 | //选中按钮 137 | UIButton* selectBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 138 | selectBtn.center = CGPointMake(20, bgView.height/2.0); 139 | selectBtn.bounds = CGRectMake(0, 0, 30, 30); 140 | [selectBtn setImage:[UIImage imageNamed:lz_Bottom_UnSelectButtonString] forState:UIControlStateNormal]; 141 | [selectBtn setImage:[UIImage imageNamed:lz_Bottom_SelectButtonString] forState:UIControlStateSelected]; 142 | [selectBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 143 | [bgView addSubview:selectBtn]; 144 | self.selectBtn = selectBtn; 145 | 146 | //照片背景 147 | UIView *imageBgView = [[UIView alloc]init]; 148 | imageBgView.frame = CGRectMake(selectBtn.right + 5, 5, bgView.height - 10, bgView.height - 10); 149 | imageBgView.backgroundColor = LZColorFromHex(0xF3F3F3); 150 | [bgView addSubview:imageBgView]; 151 | 152 | //显示照片 153 | UIImageView* imageView = [[UIImageView alloc]init]; 154 | imageView.image = [UIImage imageNamed:@"default_pic_1"]; 155 | imageView.frame = CGRectMake(imageBgView.left + 5, imageBgView.top + 5, imageBgView.width - 10, imageBgView.height - 10); 156 | imageView.contentMode = UIViewContentModeScaleAspectFit; 157 | [bgView addSubview:imageView]; 158 | self.lzImageView = imageView; 159 | 160 | CGFloat width = (bgView.width - imageBgView.right - 30)/2.0; 161 | //价格 162 | UILabel* priceLabel = [[UILabel alloc]init]; 163 | priceLabel.frame = CGRectMake(bgView.width - width - 10, 10, width, 30); 164 | priceLabel.font = [UIFont boldSystemFontOfSize:16]; 165 | priceLabel.textColor = BASECOLOR_RED; 166 | priceLabel.textAlignment = NSTextAlignmentRight; 167 | [bgView addSubview:priceLabel]; 168 | self.priceLabel = priceLabel; 169 | 170 | //商品名 171 | UILabel* nameLabel = [[UILabel alloc]init]; 172 | nameLabel.frame = CGRectMake(imageBgView.right + 10, 10, width, 25); 173 | nameLabel.font = [UIFont systemFontOfSize:15]; 174 | [bgView addSubview:nameLabel]; 175 | self.nameLabel = nameLabel; 176 | 177 | //尺寸 178 | UILabel* sizeLabel = [[UILabel alloc]init]; 179 | sizeLabel.frame = CGRectMake(nameLabel.left, nameLabel.bottom + 5, width, 20); 180 | sizeLabel.textColor = LZColorFromRGB(132, 132, 132); 181 | sizeLabel.font = [UIFont systemFontOfSize:12]; 182 | [bgView addSubview:sizeLabel]; 183 | self.sizeLabel = sizeLabel; 184 | 185 | //时间 186 | UILabel* dateLabel = [[UILabel alloc]init]; 187 | dateLabel.frame = CGRectMake(nameLabel.left, sizeLabel.bottom , width, 20); 188 | dateLabel.font = [UIFont systemFontOfSize:10]; 189 | dateLabel.textColor = LZColorFromRGB(132, 132, 132); 190 | [bgView addSubview:dateLabel]; 191 | self.dateLabel = dateLabel; 192 | 193 | //数量加按钮 194 | UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 195 | addBtn.frame = CGRectMake(bgView.width - 35, bgView.height - 35, 25, 25); 196 | [addBtn setImage:[UIImage imageNamed:@"cart_addBtn_nomal"] forState:UIControlStateNormal]; 197 | [addBtn setImage:[UIImage imageNamed:@"cart_addBtn_highlight"] forState:UIControlStateHighlighted]; 198 | [addBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 199 | [bgView addSubview:addBtn]; 200 | 201 | //数量显示 202 | UILabel* numberLabel = [[UILabel alloc]init]; 203 | numberLabel.frame = CGRectMake(addBtn.left - 30, addBtn.top, 30, 25); 204 | numberLabel.textAlignment = NSTextAlignmentCenter; 205 | numberLabel.text = @"1"; 206 | numberLabel.font = [UIFont systemFontOfSize:15]; 207 | [bgView addSubview:numberLabel]; 208 | self.numberLabel = numberLabel; 209 | 210 | //数量减按钮 211 | UIButton *cutBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 212 | cutBtn.frame = CGRectMake(numberLabel.left - 25, addBtn.top, 25, 25); 213 | [cutBtn setImage:[UIImage imageNamed:@"cart_cutBtn_nomal"] forState:UIControlStateNormal]; 214 | [cutBtn setImage:[UIImage imageNamed:@"cart_cutBtn_highlight"] forState:UIControlStateHighlighted]; 215 | [cutBtn addTarget:self action:@selector(cutBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 216 | [bgView addSubview:cutBtn]; 217 | } 218 | 219 | @end 220 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartTableViewCell/LZTableHeaderView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZTableHeaderView.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/31. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^buttonClickBlock)(BOOL select); 12 | @interface LZTableHeaderView : UITableViewHeaderFooterView 13 | 14 | @property (copy,nonatomic)NSString *title; 15 | @property (copy,nonatomic)buttonClickBlock lzClickBlock; 16 | @property (assign,nonatomic)BOOL select; 17 | @end 18 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartTableViewCell/LZTableHeaderView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZTableHeaderView.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/31. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "LZTableHeaderView.h" 10 | #import "LZConfigFile.h" 11 | 12 | @interface LZTableHeaderView () 13 | 14 | @property (strong,nonatomic)UILabel *titleLabel; 15 | @property (strong,nonatomic)UIButton *button; 16 | @end 17 | @implementation LZTableHeaderView 18 | 19 | - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier { 20 | self = [super initWithReuseIdentifier:reuseIdentifier]; 21 | if (self) { 22 | 23 | [self setupUI]; 24 | } 25 | 26 | return self; 27 | } 28 | 29 | - (void)setupUI { 30 | 31 | UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 32 | button.frame = CGRectMake(5, 15, 50, 30); 33 | 34 | [button setImage:[UIImage imageNamed:@"cart_unSelect_btn"] forState:UIControlStateNormal]; 35 | [button setImage:[UIImage imageNamed:@"cart_selected_btn"] forState:UIControlStateSelected]; 36 | [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; 37 | [self.contentView addSubview:button]; 38 | self.button = button; 39 | 40 | UILabel *label = [[UILabel alloc]init]; 41 | label.frame = CGRectMake(70, 15, LZSCREEN_WIDTH - 100, 30); 42 | label.font = [UIFont systemFontOfSize:14]; 43 | [self.contentView addSubview:label]; 44 | self.titleLabel = label; 45 | } 46 | - (void)buttonClick:(UIButton*)button { 47 | button.selected = !button.selected; 48 | 49 | if (self.lzClickBlock) { 50 | self.lzClickBlock(button.selected); 51 | } 52 | } 53 | 54 | - (void)setSelect:(BOOL)select { 55 | 56 | self.button.selected = select; 57 | _select = select; 58 | } 59 | 60 | - (void)setTitle:(NSString *)title { 61 | self.titleLabel.text = title; 62 | _title = title; 63 | } 64 | /* 65 | // Only override drawRect: if you perform custom drawing. 66 | // An empty implementation adversely affects performance during animation. 67 | - (void)drawRect:(CGRect)rect { 68 | // Drawing code 69 | } 70 | */ 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewController.h 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import 12 | 13 | @interface LZCartViewController : UIViewController 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/LZCartViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewController.m 3 | // LZCartViewController 4 | // 5 | // Created by LQQ on 16/5/18. 6 | // Copyright © 2016年 LQQ. All rights reserved. 7 | // https://github.com/LQQZYY/CartDemo 8 | // http://blog.csdn.net/lqq200912408 9 | // QQ交流: 302934443 10 | 11 | #import "LZCartViewController.h" 12 | #import "LZConfigFile.h" 13 | #import "LZCartTableViewCell.h" 14 | #import "LZShopModel.h" 15 | #import "LZGoodsModel.h" 16 | #import "LZTableHeaderView.h" 17 | 18 | 19 | @interface LZCartViewController () 20 | { 21 | BOOL _isHiddenNavigationBarWhenDisappear;//记录当页面消失时是否需要隐藏系统导航 22 | BOOL _isHasTabBarController;//是否含有tabbar 23 | BOOL _isHasNavitationController;//是否含有导航 24 | } 25 | 26 | @property (strong,nonatomic)NSMutableArray *dataArray; 27 | @property (strong,nonatomic)NSMutableArray *selectedArray; 28 | @property (strong,nonatomic)UITableView *myTableView; 29 | @property (strong,nonatomic)UIButton *allSellectedButton; 30 | @property (strong,nonatomic)UILabel *totlePriceLabel; 31 | @end 32 | 33 | @implementation LZCartViewController 34 | 35 | #pragma mark - viewController life cicle 36 | - (void)viewWillAppear:(BOOL)animated { 37 | 38 | if (_isHasNavitationController == YES) { 39 | if (self.navigationController.navigationBarHidden == YES) { 40 | _isHiddenNavigationBarWhenDisappear = NO; 41 | } else { 42 | self.navigationController.navigationBarHidden = YES; 43 | _isHiddenNavigationBarWhenDisappear = YES; 44 | } 45 | } 46 | 47 | 48 | //当进入购物车的时候判断是否有已选择的商品,有就清空 49 | //主要是提交订单后再返回到购物车,如果不清空,还会显示 50 | if (self.selectedArray.count > 0) { 51 | for (LZGoodsModel *model in self.selectedArray) { 52 | model.select = NO;//这个其实有点多余,提交订单后的数据源不会包含这些,保险起见,加上了 53 | } 54 | [self.selectedArray removeAllObjects]; 55 | } 56 | 57 | //初始化显示状态 58 | _allSellectedButton.selected = NO; 59 | _totlePriceLabel.attributedText = [self LZSetString:@"¥0.00"]; 60 | } 61 | 62 | -(void)creatData { 63 | // for (int i = 0; i < 10; i++) { 64 | // LZCartModel *model = [[LZCartModel alloc]init]; 65 | // 66 | // model.title = [NSString stringWithFormat:@"测试数据%d",i]; 67 | // model.price = @"100.00"; 68 | // model.number = 1; 69 | // model.image = [UIImage imageNamed:@"aaa.jpg"]; 70 | // model.dateStr = @"2016.02.18"; 71 | // model.subTitle = @"18*20cm"; 72 | // 73 | // [self.dataArray addObject:model]; 74 | // } 75 | 76 | NSString *path = [[NSBundle mainBundle] pathForResource:@"ShopCarNew" ofType:@"plist" inDirectory:nil]; 77 | 78 | NSDictionary *dic = [[NSDictionary alloc]initWithContentsOfFile:path]; 79 | NSLog(@"%@",dic); 80 | NSArray *array = [dic objectForKey:@"data"]; 81 | if (array.count > 0) { 82 | for (NSDictionary *dic in array) { 83 | LZShopModel *model = [[LZShopModel alloc]init]; 84 | model.shopID = [dic objectForKey:@"id"]; 85 | model.shopName = [dic objectForKey:@"shopName"]; 86 | model.sID = [dic objectForKey:@"sid"]; 87 | [model configGoodsArrayWithArray:[dic objectForKey:@"items"]]; 88 | 89 | [self.dataArray addObject:model]; 90 | } 91 | } 92 | 93 | // if (self.myTableView != nil) { 94 | // [self.myTableView reloadData]; 95 | // } else { 96 | // [self setupCartView]; 97 | // } 98 | } 99 | - (void)loadData { 100 | [self creatData]; 101 | [self changeView]; 102 | } 103 | - (void)viewDidLoad { 104 | [super viewDidLoad]; 105 | // Do any additional setup after loading the view. 106 | self.view.backgroundColor = [UIColor whiteColor]; 107 | _isHasTabBarController = self.tabBarController?YES:NO; 108 | _isHasNavitationController = self.navigationController?YES:NO; 109 | 110 | #warning 模仿请求数据,延迟2s加载数据,实际使用时请移除更换 111 | [self performSelector:@selector(loadData) withObject:nil afterDelay:2]; 112 | 113 | 114 | [self setupCustomNavigationBar]; 115 | if (self.dataArray.count > 0) { 116 | 117 | [self setupCartView]; 118 | } else { 119 | [self setupCartEmptyView]; 120 | } 121 | } 122 | 123 | - (void)viewWillDisappear:(BOOL)animated { 124 | if (_isHiddenNavigationBarWhenDisappear == YES) { 125 | self.navigationController.navigationBarHidden = NO; 126 | } 127 | } 128 | 129 | /** 130 | * @author LQQ, 16-02-18 11:02:16 131 | * 132 | * 计算已选中商品金额 133 | */ 134 | -(void)countPrice { 135 | double totlePrice = 0.0; 136 | 137 | for (LZGoodsModel *model in self.selectedArray) { 138 | 139 | double price = [model.price doubleValue]; 140 | 141 | totlePrice += price * model.count; 142 | } 143 | NSString *string = [NSString stringWithFormat:@"¥%.2f",totlePrice]; 144 | self.totlePriceLabel.attributedText = [self LZSetString:string]; 145 | } 146 | 147 | #pragma mark - 初始化数组 148 | - (NSMutableArray *)dataArray { 149 | if (_dataArray == nil) { 150 | _dataArray = [NSMutableArray arrayWithCapacity:0]; 151 | } 152 | 153 | return _dataArray; 154 | } 155 | 156 | - (NSMutableArray *)selectedArray { 157 | if (_selectedArray == nil) { 158 | _selectedArray = [NSMutableArray arrayWithCapacity:0]; 159 | } 160 | 161 | return _selectedArray; 162 | } 163 | 164 | #pragma mark - 布局页面视图 165 | #pragma mark -- 自定义导航 166 | - (void)setupCustomNavigationBar { 167 | UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, LZSCREEN_WIDTH, LZNaigationBarHeight)]; 168 | backgroundView.backgroundColor = LZColorFromRGB(236, 236, 236); 169 | [self.view addSubview:backgroundView]; 170 | 171 | UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, LZNaigationBarHeight - 0.5, LZSCREEN_WIDTH, 0.5)]; 172 | lineView.backgroundColor = [UIColor lightGrayColor]; 173 | [self.view addSubview:lineView]; 174 | 175 | UILabel *titleLabel = [[UILabel alloc]init]; 176 | titleLabel.text = @"购物车"; 177 | titleLabel.font = [UIFont systemFontOfSize:20]; 178 | 179 | titleLabel.center = CGPointMake(self.view.center.x, (LZNaigationBarHeight - 20)/2.0 + 20); 180 | CGSize size = [titleLabel sizeThatFits:CGSizeMake(300, 44)]; 181 | titleLabel.bounds = CGRectMake(0, 0, size.width + 20, size.height); 182 | 183 | titleLabel.textAlignment = NSTextAlignmentCenter; 184 | [self.view addSubview:titleLabel]; 185 | 186 | UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; 187 | backButton.frame = CGRectMake(10, 20, 40, 44); 188 | [backButton setImage:[UIImage imageNamed:lz_BackButtonString] forState:UIControlStateNormal]; 189 | [backButton addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 190 | [self.view addSubview:backButton]; 191 | } 192 | #pragma mark -- 自定义底部视图 193 | - (void)setupCustomBottomView { 194 | 195 | UIView *backgroundView = [[UIView alloc]init]; 196 | backgroundView.backgroundColor = LZColorFromRGB(245, 245, 245); 197 | backgroundView.tag = TAG_CartEmptyView + 1; 198 | [self.view addSubview:backgroundView]; 199 | 200 | //当有tabBarController时,在tabBar的上面 201 | if (_isHasTabBarController == YES) { 202 | backgroundView.frame = CGRectMake(0, LZSCREEN_HEIGHT - 2*LZTabBarHeight, LZSCREEN_WIDTH, LZTabBarHeight); 203 | } else { 204 | backgroundView.frame = CGRectMake(0, LZSCREEN_HEIGHT - LZTabBarHeight, LZSCREEN_WIDTH, LZTabBarHeight); 205 | } 206 | 207 | UIView *lineView = [[UIView alloc]init]; 208 | lineView.frame = CGRectMake(0, 0, LZSCREEN_WIDTH, 1); 209 | lineView.backgroundColor = [UIColor lightGrayColor]; 210 | [backgroundView addSubview:lineView]; 211 | 212 | //全选按钮 213 | UIButton *selectAll = [UIButton buttonWithType:UIButtonTypeCustom]; 214 | selectAll.titleLabel.font = [UIFont systemFontOfSize:16]; 215 | selectAll.frame = CGRectMake(10, 5, 80, LZTabBarHeight - 10); 216 | [selectAll setTitle:@" 全选" forState:UIControlStateNormal]; 217 | [selectAll setImage:[UIImage imageNamed:lz_Bottom_UnSelectButtonString] forState:UIControlStateNormal]; 218 | [selectAll setImage:[UIImage imageNamed:lz_Bottom_SelectButtonString] forState:UIControlStateSelected]; 219 | [selectAll setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 220 | [selectAll addTarget:self action:@selector(selectAllBtnClick:) forControlEvents:UIControlEventTouchUpInside]; 221 | [backgroundView addSubview:selectAll]; 222 | self.allSellectedButton = selectAll; 223 | 224 | //结算按钮 225 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 226 | btn.backgroundColor = BASECOLOR_RED; 227 | btn.frame = CGRectMake(LZSCREEN_WIDTH - 80, 0, 80, LZTabBarHeight); 228 | [btn setTitle:@"去结算" forState:UIControlStateNormal]; 229 | [btn addTarget:self action:@selector(goToPayButtonClick:) forControlEvents:UIControlEventTouchUpInside]; 230 | [backgroundView addSubview:btn]; 231 | 232 | //合计 233 | UILabel *label = [[UILabel alloc]init]; 234 | label.font = [UIFont systemFontOfSize:16]; 235 | label.textColor = [UIColor redColor]; 236 | [backgroundView addSubview:label]; 237 | 238 | label.attributedText = [self LZSetString:@"¥0.00"]; 239 | CGFloat maxWidth = LZSCREEN_WIDTH - selectAll.bounds.size.width - btn.bounds.size.width - 30; 240 | // CGSize size = [label sizeThatFits:CGSizeMake(maxWidth, LZTabBarHeight)]; 241 | label.frame = CGRectMake(selectAll.bounds.size.width + 20, 0, maxWidth - 10, LZTabBarHeight); 242 | self.totlePriceLabel = label; 243 | } 244 | 245 | - (NSMutableAttributedString*)LZSetString:(NSString*)string { 246 | 247 | NSString *text = [NSString stringWithFormat:@"合计:%@",string]; 248 | NSMutableAttributedString *LZString = [[NSMutableAttributedString alloc]initWithString:text]; 249 | NSRange rang = [text rangeOfString:@"合计:"]; 250 | [LZString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:rang]; 251 | [LZString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:rang]; 252 | return LZString; 253 | } 254 | #pragma mark -- 购物车为空时的默认视图 255 | - (void)changeView { 256 | if (self.dataArray.count > 0) { 257 | UIView *view = [self.view viewWithTag:TAG_CartEmptyView]; 258 | if (view != nil) { 259 | [view removeFromSuperview]; 260 | } 261 | 262 | [self setupCartView]; 263 | } else { 264 | UIView *bottomView = [self.view viewWithTag:TAG_CartEmptyView + 1]; 265 | [bottomView removeFromSuperview]; 266 | 267 | [self.myTableView removeFromSuperview]; 268 | self.myTableView = nil; 269 | [self setupCartEmptyView]; 270 | } 271 | } 272 | 273 | - (void)setupCartEmptyView { 274 | //默认视图背景 275 | UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, LZNaigationBarHeight, LZSCREEN_WIDTH, LZSCREEN_HEIGHT - LZNaigationBarHeight)]; 276 | backgroundView.tag = TAG_CartEmptyView; 277 | [self.view addSubview:backgroundView]; 278 | 279 | //默认图片 280 | UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:lz_CartEmptyString]]; 281 | img.center = CGPointMake(LZSCREEN_WIDTH/2.0, LZSCREEN_HEIGHT/2.0 - 120); 282 | img.bounds = CGRectMake(0, 0, 247.0/187 * 100, 100); 283 | [backgroundView addSubview:img]; 284 | 285 | UILabel *warnLabel = [[UILabel alloc]init]; 286 | warnLabel.center = CGPointMake(LZSCREEN_WIDTH/2.0, LZSCREEN_HEIGHT/2.0 - 10); 287 | warnLabel.bounds = CGRectMake(0, 0, LZSCREEN_WIDTH, 30); 288 | warnLabel.textAlignment = NSTextAlignmentCenter; 289 | warnLabel.text = @"购物车为空!"; 290 | warnLabel.font = [UIFont systemFontOfSize:15]; 291 | warnLabel.textColor = LZColorFromHex(0x706F6F); 292 | [backgroundView addSubview:warnLabel]; 293 | } 294 | #pragma mark -- 购物车有商品时的视图 295 | - (void)setupCartView { 296 | //创建底部视图 297 | [self setupCustomBottomView]; 298 | 299 | UITableView *table = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped]; 300 | 301 | table.delegate = self; 302 | table.dataSource = self; 303 | 304 | table.rowHeight = lz_CartRowHeight; 305 | table.separatorStyle = UITableViewCellSeparatorStyleNone; 306 | table.backgroundColor = LZColorFromRGB(245, 246, 248); 307 | [self.view addSubview:table]; 308 | self.myTableView = table; 309 | 310 | if (_isHasTabBarController) { 311 | table.frame = CGRectMake(0, LZNaigationBarHeight, LZSCREEN_WIDTH, LZSCREEN_HEIGHT - LZNaigationBarHeight - 2*LZTabBarHeight); 312 | } else { 313 | table.frame = CGRectMake(0, LZNaigationBarHeight, LZSCREEN_WIDTH, LZSCREEN_HEIGHT - LZNaigationBarHeight - LZTabBarHeight); 314 | } 315 | 316 | [table registerClass:[LZTableHeaderView class] forHeaderFooterViewReuseIdentifier:@"LZHeaderView"]; 317 | } 318 | #pragma mark --- UITableViewDataSource & UITableViewDelegate 319 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 320 | 321 | LZShopModel *model = [self.dataArray objectAtIndex:section]; 322 | return model.goodsArray.count; 323 | } 324 | 325 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 326 | 327 | return self.dataArray.count; 328 | } 329 | 330 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 331 | LZCartTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LZCartReusableCell"]; 332 | if (cell == nil) { 333 | cell = [[LZCartTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"LZCartReusableCell"]; 334 | } 335 | 336 | LZShopModel *shopModel = self.dataArray[indexPath.section]; 337 | LZGoodsModel *model = [shopModel.goodsArray objectAtIndex:indexPath.row]; 338 | 339 | __block typeof(cell)wsCell = cell; 340 | 341 | [cell numberAddWithBlock:^(NSInteger number) { 342 | wsCell.lzNumber = number; 343 | model.count = number; 344 | 345 | [shopModel.goodsArray replaceObjectAtIndex:indexPath.row withObject:model]; 346 | if ([self.selectedArray containsObject:model]) { 347 | [self.selectedArray removeObject:model]; 348 | [self.selectedArray addObject:model]; 349 | [self countPrice]; 350 | } 351 | }]; 352 | 353 | [cell numberCutWithBlock:^(NSInteger number) { 354 | 355 | wsCell.lzNumber = number; 356 | model.count = number; 357 | 358 | [shopModel.goodsArray replaceObjectAtIndex:indexPath.row withObject:model]; 359 | 360 | //判断已选择数组里有无该对象,有就删除 重新添加 361 | if ([self.selectedArray containsObject:model]) { 362 | [self.selectedArray removeObject:model]; 363 | [self.selectedArray addObject:model]; 364 | [self countPrice]; 365 | } 366 | }]; 367 | 368 | [cell cellSelectedWithBlock:^(BOOL select) { 369 | 370 | model.select = select; 371 | if (select) { 372 | [self.selectedArray addObject:model]; 373 | } else { 374 | [self.selectedArray removeObject:model]; 375 | } 376 | 377 | [self verityAllSelectState]; 378 | [self verityGroupSelectState:indexPath.section]; 379 | 380 | [self countPrice]; 381 | }]; 382 | 383 | [cell reloadDataWithModel:model]; 384 | return cell; 385 | } 386 | 387 | -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 388 | return @"删除"; 389 | } 390 | 391 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 392 | LZTableHeaderView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LZHeaderView"]; 393 | LZShopModel *model = [self.dataArray objectAtIndex:section]; 394 | NSLog(@">>>>>>%d", model.select); 395 | view.title = model.shopName; 396 | view.select = model.select; 397 | view.lzClickBlock = ^(BOOL select) { 398 | model.select = select; 399 | if (select) { 400 | 401 | for (LZGoodsModel *good in model.goodsArray) { 402 | good.select = YES; 403 | if (![self.selectedArray containsObject:good]) { 404 | 405 | [self.selectedArray addObject:good]; 406 | } 407 | } 408 | 409 | } else { 410 | for (LZGoodsModel *good in model.goodsArray) { 411 | good.select = NO; 412 | if ([self.selectedArray containsObject:good]) { 413 | 414 | [self.selectedArray removeObject:good]; 415 | } 416 | } 417 | } 418 | 419 | [self verityAllSelectState]; 420 | 421 | [tableView reloadData]; 422 | [self countPrice]; 423 | }; 424 | 425 | return view; 426 | } 427 | 428 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 429 | 430 | return LZTableViewHeaderHeight; 431 | } 432 | 433 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 434 | 435 | return 1; 436 | } 437 | -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 438 | 439 | if (editingStyle == UITableViewCellEditingStyleDelete) { 440 | 441 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要删除该商品?删除后无法恢复!" preferredStyle:1]; 442 | UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 443 | 444 | LZShopModel *shop = [self.dataArray objectAtIndex:indexPath.section]; 445 | LZGoodsModel *model = [shop.goodsArray objectAtIndex:indexPath.row]; 446 | 447 | [shop.goodsArray removeObjectAtIndex:indexPath.row]; 448 | // 删除 449 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 450 | 451 | if (shop.goodsArray.count == 0) { 452 | [self.dataArray removeObjectAtIndex:indexPath.section]; 453 | } 454 | 455 | //判断删除的商品是否已选择 456 | if ([self.selectedArray containsObject:model]) { 457 | //从已选中删除,重新计算价格 458 | [self.selectedArray removeObject:model]; 459 | [self countPrice]; 460 | } 461 | 462 | NSInteger count = 0; 463 | for (LZShopModel *shop in self.dataArray) { 464 | count += shop.goodsArray.count; 465 | } 466 | 467 | if (self.selectedArray.count == count) { 468 | _allSellectedButton.selected = YES; 469 | } else { 470 | _allSellectedButton.selected = NO; 471 | } 472 | 473 | if (count == 0) { 474 | [self changeView]; 475 | } 476 | 477 | //如果删除的时候数据紊乱,可延迟0.5s刷新一下 478 | [self performSelector:@selector(reloadTable) withObject:nil afterDelay:0.5]; 479 | 480 | }]; 481 | 482 | UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; 483 | 484 | [alert addAction:okAction]; 485 | [alert addAction:cancel]; 486 | [self presentViewController:alert animated:YES completion:nil]; 487 | } 488 | 489 | } 490 | - (void)reloadTable { 491 | [self.myTableView reloadData]; 492 | } 493 | #pragma mark -- 页面按钮点击事件 494 | #pragma mark --- 返回按钮点击事件 495 | - (void)backButtonClick:(UIButton*)button { 496 | if (_isHasNavitationController == NO) { 497 | [self dismissViewControllerAnimated:YES completion:nil]; 498 | } else { 499 | [self.navigationController popViewControllerAnimated:YES]; 500 | } 501 | } 502 | #pragma mark --- 全选按钮点击事件 503 | - (void)selectAllBtnClick:(UIButton*)button { 504 | button.selected = !button.selected; 505 | 506 | //点击全选时,把之前已选择的全部删除 507 | for (LZGoodsModel *model in self.selectedArray) { 508 | model.select = NO; 509 | } 510 | 511 | [self.selectedArray removeAllObjects]; 512 | 513 | if (button.selected) { 514 | 515 | for (LZShopModel *shop in self.dataArray) { 516 | shop.select = YES; 517 | for (LZGoodsModel *model in shop.goodsArray) { 518 | model.select = YES; 519 | [self.selectedArray addObject:model]; 520 | } 521 | } 522 | 523 | } else { 524 | for (LZShopModel *shop in self.dataArray) { 525 | shop.select = NO; 526 | } 527 | } 528 | 529 | [self.myTableView reloadData]; 530 | [self countPrice]; 531 | } 532 | #pragma mark --- 确认选择,提交订单按钮点击事件 533 | - (void)goToPayButtonClick:(UIButton*)button { 534 | if (self.selectedArray.count > 0) { 535 | for (LZGoodsModel *model in self.selectedArray) { 536 | NSLog(@"选择的商品>>%@>>>%ld",model,(long)model.count); 537 | } 538 | } else { 539 | NSLog(@"你还没有选择任何商品"); 540 | } 541 | 542 | } 543 | 544 | - (void)verityGroupSelectState:(NSInteger)section { 545 | 546 | // 判断某个区的商品是否全选 547 | LZShopModel *tempShop = self.dataArray[section]; 548 | // 是否全选标示符 549 | BOOL isShopAllSelect = YES; 550 | for (LZGoodsModel *model in tempShop.goodsArray) { 551 | // 当有一个为NO的是时候,将标示符置为NO,并跳出循环 552 | if (model.select == NO) { 553 | isShopAllSelect = NO; 554 | break; 555 | } 556 | } 557 | 558 | LZTableHeaderView *header = (LZTableHeaderView *)[self.myTableView headerViewForSection:section]; 559 | header.select = isShopAllSelect; 560 | tempShop.select = isShopAllSelect; 561 | } 562 | 563 | - (void)verityAllSelectState { 564 | 565 | NSInteger count = 0; 566 | for (LZShopModel *shop in self.dataArray) { 567 | count += shop.goodsArray.count; 568 | } 569 | 570 | if (self.selectedArray.count == count) { 571 | _allSellectedButton.selected = YES; 572 | } else { 573 | _allSellectedButton.selected = NO; 574 | } 575 | } 576 | - (void)didReceiveMemoryWarning { 577 | [super didReceiveMemoryWarning]; 578 | // Dispose of any resources that can be recreated. 579 | } 580 | 581 | /* 582 | #pragma mark - Navigation 583 | 584 | // In a storyboard-based application, you will often want to do a little preparation before navigation 585 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 586 | // Get the new view controller using [segue destinationViewController]. 587 | // Pass the selected object to the new view controller. 588 | } 589 | */ 590 | 591 | @end 592 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/back_button@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/back_button@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_addBtn_highlight@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_addBtn_highlight@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_addBtn_nomal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_addBtn_nomal@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_cutBtn_highlight@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_cutBtn_highlight@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_cutBtn_nomal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_cutBtn_nomal@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_default_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_default_bg.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_selected_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_selected_btn@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_unSelect_btn@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/LZCartViewController/icons/cart_unSelect_btn@2x.png -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/ShopCarNew.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | data 6 | 7 | 8 | id 9 | 3 10 | items 11 | 12 | 13 | categoryId 14 | 4aea47a653a2c7bc0153a2cdca680003 15 | count 16 | 1 17 | goodsId 18 | 11 19 | goodsName 20 | 品质回馈1 21 | goodsType 22 | 0 23 | id 24 | ff80808154ccbba30154ccf6bae90005 25 | orginalPrice 26 | 5320 27 | realPrice 28 | 5320 29 | shopId 30 | 3 31 | shopName 32 | 美年大健康旗舰店 33 | sid 34 | ff80808154ccbba30154ccf6bae90005 35 | total 36 | 5320 37 | userId 38 | 39 | 40 | 41 | categoryId 42 | 4aea47a653a2c7bc0153a2cdca680003 43 | count 44 | 1 45 | goodsId 46 | 11 47 | goodsName 48 | 品质回馈1 49 | goodsType 50 | 0 51 | id 52 | ff80808154ccbba30154ccf6bae90005 53 | orginalPrice 54 | 5320 55 | realPrice 56 | 5320 57 | shopId 58 | 3 59 | shopName 60 | 美年大健康旗舰店 61 | sid 62 | ff80808154ccbba30154ccf6bae90005 63 | total 64 | 5320 65 | userId 66 | 67 | 68 | 69 | categoryId 70 | 4aea47a653a2c7bc0153a2cdca680003 71 | count 72 | 1 73 | goodsId 74 | 11 75 | goodsName 76 | 品质回馈1 77 | goodsType 78 | 0 79 | id 80 | ff80808154ccbba30154ccf6bae90005 81 | orginalPrice 82 | 5320 83 | realPrice 84 | 5320 85 | shopId 86 | 3 87 | shopName 88 | 美年大健康旗舰店 89 | sid 90 | ff80808154ccbba30154ccf6bae90005 91 | total 92 | 5320 93 | userId 94 | 95 | 96 | 97 | shopName 98 | 美年大健康旗舰店00 99 | sid 100 | 3 101 | 102 | 103 | id 104 | 3 105 | items 106 | 107 | 108 | categoryId 109 | 4aea47a653a2c7bc0153a2cdca680003 110 | count 111 | 1 112 | goodsId 113 | 11 114 | goodsName 115 | 品质回馈1 116 | goodsType 117 | 0 118 | id 119 | ff80808154ccbba30154ccf6bae90005 120 | orginalPrice 121 | 5320 122 | realPrice 123 | 5320 124 | shopId 125 | 3 126 | shopName 127 | 美年大健康旗舰店 128 | sid 129 | ff80808154ccbba30154ccf6bae90005 130 | total 131 | 5320 132 | userId 133 | 134 | 135 | 136 | categoryId 137 | 4aea47a653a2c7bc0153a2cdca680003 138 | count 139 | 1 140 | goodsId 141 | 11 142 | goodsName 143 | 品质回馈1 144 | goodsType 145 | 0 146 | id 147 | ff80808154ccbba30154ccf6bae90005 148 | orginalPrice 149 | 5320 150 | realPrice 151 | 5320 152 | shopId 153 | 3 154 | shopName 155 | 美年大健康旗舰店 156 | sid 157 | ff80808154ccbba30154ccf6bae90005 158 | total 159 | 5320 160 | userId 161 | 162 | 163 | 164 | categoryId 165 | 4aea47a653a2c7bc0153a2cdca680003 166 | count 167 | 1 168 | goodsId 169 | 11 170 | goodsName 171 | 品质回馈1 172 | goodsType 173 | 0 174 | id 175 | ff80808154ccbba30154ccf6bae90005 176 | orginalPrice 177 | 5320 178 | realPrice 179 | 5320 180 | shopId 181 | 3 182 | shopName 183 | 美年大健康旗舰店 184 | sid 185 | ff80808154ccbba30154ccf6bae90005 186 | total 187 | 5320 188 | userId 189 | 190 | 191 | 192 | shopName 193 | 美年大健康旗舰店00 194 | sid 195 | 3 196 | 197 | 198 | id 199 | 3 200 | items 201 | 202 | 203 | categoryId 204 | 4aea47a653a2c7bc0153a2cdca680003 205 | count 206 | 1 207 | goodsId 208 | 11 209 | goodsName 210 | 品质回馈1 211 | goodsType 212 | 0 213 | id 214 | ff80808154ccbba30154ccf6bae90005 215 | orginalPrice 216 | 5320 217 | realPrice 218 | 5320 219 | shopId 220 | 3 221 | shopName 222 | 美年大健康旗舰店 223 | sid 224 | ff80808154ccbba30154ccf6bae90005 225 | total 226 | 5320 227 | userId 228 | 229 | 230 | 231 | categoryId 232 | 4aea47a653a2c7bc0153a2cdca680003 233 | count 234 | 1 235 | goodsId 236 | 11 237 | goodsName 238 | 品质回馈1 239 | goodsType 240 | 0 241 | id 242 | ff80808154ccbba30154ccf6bae90005 243 | orginalPrice 244 | 5320 245 | realPrice 246 | 5320 247 | shopId 248 | 3 249 | shopName 250 | 美年大健康旗舰店 251 | sid 252 | ff80808154ccbba30154ccf6bae90005 253 | total 254 | 5320 255 | userId 256 | 257 | 258 | 259 | shopName 260 | 美年大健康旗舰店11 261 | sid 262 | 3 263 | 264 | 265 | id 266 | 3 267 | items 268 | 269 | 270 | categoryId 271 | 4aea47a653a2c7bc0153a2cdca680003 272 | count 273 | 1 274 | goodsId 275 | 11 276 | goodsName 277 | 品质回馈1 278 | goodsType 279 | 0 280 | id 281 | ff80808154ccbba30154ccf6bae90005 282 | orginalPrice 283 | 5320 284 | realPrice 285 | 5320 286 | shopId 287 | 3 288 | shopName 289 | 美年大健康旗舰店 290 | sid 291 | ff80808154ccbba30154ccf6bae90005 292 | total 293 | 5320 294 | userId 295 | 296 | 297 | 298 | categoryId 299 | 4aea47a653a2c7bc0153a2cdca680003 300 | count 301 | 1 302 | goodsId 303 | 11 304 | goodsName 305 | 品质回馈1 306 | goodsType 307 | 0 308 | id 309 | ff80808154ccbba30154ccf6bae90005 310 | orginalPrice 311 | 5320 312 | realPrice 313 | 5320 314 | shopId 315 | 3 316 | shopName 317 | 美年大健康旗舰店 318 | sid 319 | ff80808154ccbba30154ccf6bae90005 320 | total 321 | 5320 322 | userId 323 | 324 | 325 | 326 | categoryId 327 | 4aea47a653a2c7bc0153a2cdca680003 328 | count 329 | 1 330 | goodsId 331 | 11 332 | goodsName 333 | 品质回馈1 334 | goodsType 335 | 0 336 | id 337 | ff80808154ccbba30154ccf6bae90005 338 | orginalPrice 339 | 5320 340 | realPrice 341 | 5320 342 | shopId 343 | 3 344 | shopName 345 | 美年大健康旗舰店 346 | sid 347 | ff80808154ccbba30154ccf6bae90005 348 | total 349 | 5320 350 | userId 351 | 352 | 353 | 354 | shopName 355 | 美年大健康旗舰店22 356 | sid 357 | 3 358 | 359 | 360 | success 361 | 362 | 363 | 364 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LZCartViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | 22 | 23 | } 24 | - (IBAction)selector:(id)sender { 25 | LZCartViewController *cart = [[LZCartViewController alloc]init]; 26 | 27 | // UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:cart]; 28 | [self presentViewController:cart animated:YES completion:nil]; 29 | } 30 | - (void)didReceiveMemoryWarning { 31 | [super didReceiveMemoryWarning]; 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/aaa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/LZCartViewController/LZCartViewController2/LZCartViewController/aaa.jpg -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewController/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LZCartViewController 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. 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 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewControllerTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewControllerTests/LZCartViewControllerTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewControllerTests.m 3 | // LZCartViewControllerTests 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LZCartViewControllerTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation LZCartViewControllerTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewControllerUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewController2/LZCartViewControllerUITests/LZCartViewControllerUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewControllerUITests.m 3 | // LZCartViewControllerUITests 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LZCartViewControllerUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation LZCartViewControllerUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewControllerTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewControllerTests/LZCartViewControllerTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewControllerTests.m 3 | // LZCartViewControllerTests 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LZCartViewControllerTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation LZCartViewControllerTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewControllerUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LZCartViewController/LZCartViewControllerUITests/LZCartViewControllerUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LZCartViewControllerUITests.m 3 | // LZCartViewControllerUITests 4 | // 5 | // Created by Artron_LQQ on 16/5/18. 6 | // Copyright © 2016年 Artup. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LZCartViewControllerUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation LZCartViewControllerUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LDCartViewController 2 | 重新整理了之前的购物车逻辑,删除了部分代码,修改了部分方法,逻辑结构更清晰,复用更容易 3 | #####此demo的swift版本:[CartDemo_Swift](https://github.com/LQQZYY/CartDemo_Swift) 4 | 5 | # 本demo完整展示了购物车的处理逻辑, 及实现思路, 具体的业务处理, 还需要根据自己的需求来定制 6 | ### 购物车功能 7 | 8 | - 商品展示 9 | - 商品选择 10 | - 价格计算 11 | - 商品删除 12 | 13 | ### 说明 14 | 本次更新,重新整理了代码,整体结构更清晰,方便在此基础上进行个人需求的定制 15 | - 整体布局脱离了对`Masnary`的依赖 16 | 如果需要使用`Masnary`,可重新设置控件坐标 17 | - 重写了自定义`cell`的对外方法 18 | 减少了不必要的属性暴漏在.h文件,尽量使用方法来调用相关设置,使用更方便,逻辑更清晰 19 | 20 | ```Objective-C 21 | @interface LZCartTableViewCell : UITableViewCell 22 | //商品数量 23 | @property (assign,nonatomic)NSInteger lzNumber; 24 | @property (assign,nonatomic)BOOL lzSelected; 25 | 26 | - (void)reloadDataWithModel:(LZCartModel*)model; 27 | - (void)numberAddWithBlock:(LZNumberChangedBlock)block; 28 | - (void)numberCutWithBlock:(LZNumberChangedBlock)block; 29 | - (void)cellSelectedWithBlock:(LZCellSelectedBlock)block; 30 | @end 31 | ``` 32 | 33 | 对这里的两个属性,需要简单的说明一下: 34 | - lzNumber :主要是提供给外部修改显示的商品数量,商品数量的变动,这次我放在`cell`内;一般情况下,外部需要和服务器交互,只有商品数量真正(服务器内记录的数据)发生变化了,才能去修改显示的数目,在上面的第二个和第三个方法的`block`内修改`cell`的这个属性即可,记得也要修改相应的数据模型; 35 | - lzSelected :主要是提供给外部修改该商品的选中状态,这次我将这个显示状态的变动放在了`cell`外部进行操作,同样是考虑到,外部要和服务器进行交互,只有商品真正(服务器记录的数据)添加到订单内,才能改变显示状态,同样在上面的第四个方法的`block`内修改这个属性即可,同样也要修改相应的数据模型;
36 | 37 | **PS:如果这两个量的变化不需要和服务器交互,直接在本地完成的,其显示状态可以直接在`cell`内部相应的点击方法里修改即可,外部只需修改相应的数据模型;** 38 | 39 |
代码中,我设置了3个`BOOL`值: 40 | ```Objective-C 41 | BOOL _isHiddenNavigationBarWhenDisappear;//记录当页面消失时是否需要隐藏系统导航 42 | BOOL _isHasTabBarController;//是否含有tabbar 43 | BOOL _isHasNavitationController;//是否含有导航 44 | ``` 45 | 作用后面都有注释,其中的第一个`BOOL`值需要简单说明一下: 46 | 因为我在控制器的`viewWillAppear`和`viewWillDisappear`方法里做了一些判断,前者判断了当前控制器是否是属于导航,当是属于导航时,需要隐藏系统的导航条,因为有可能不会使用导航,所以我在这里自定义了导航条;后者在退出此视图时,需要把隐藏掉的导航再显示出来,但是这有个前提:使用了系统的导航,没有自定义,鉴于很多情况下都是使用自定义的导航,这时如果显示了系统导航,反而会弄巧成拙,所以第一`BOOL`值就是用来记录是否使用了系统导航的; 47 | ```Objective-C 48 | - (void)viewWillAppear:(BOOL)animated { 49 | 50 | if (_isHasNavitationController == YES) { 51 | if (self.navigationController.navigationBarHidden == YES) { 52 | _isHiddenNavigationBarWhenDisappear = NO; 53 | } else { 54 | self.navigationController.navigationBarHidden = YES; 55 | _isHiddenNavigationBarWhenDisappear = YES; 56 | } 57 | } 58 | } 59 | ``` 60 | ```Objective-C 61 | - (void)viewWillDisappear:(BOOL)animated { 62 | if (_isHiddenNavigationBarWhenDisappear == YES) { 63 | self.navigationController.navigationBarHidden = NO; 64 | } 65 | } 66 | ``` 67 | ##### 价格计算 68 | 价格的计算,这里我是直接遍历已选择的数组,取出其中的`Model`来计算的: 69 | ```Objective-C 70 | /** 71 | * @author LQQ, 16-02-18 11:02:16 72 | * 73 | * 计算已选中商品金额 74 | */ 75 | -(void)countPrice { 76 | double totlePrice = 0.0; 77 | 78 | for (LZCartModel *model in self.selectedArray) { 79 | 80 | double price = [model.price doubleValue]; 81 | 82 | totlePrice += price*model.number; 83 | } 84 | self.totlePriceLabel.text = [NSString stringWithFormat:@"¥%.2f",totlePrice]; 85 | } 86 | ``` 87 | ### 使用 88 | 使用的时候直接将`demo`中的`LZCartViewController`文件夹下的文件拖进工程即可,注意不能直接使用,要根据自己的需求修改; 89 | ##### 关于控制器`LZCartViewController` 90 | 建议直接使用我这个控制器`LZCartViewController`,里面我根据功能划分了几个区域,界面的东西修改为自己需要的,逻辑部分可以不用做太大的修改,添加上与服务器的交互及验证逻辑即可; 91 | ##### 关于数据模型`LZCartModel` 92 | 数据模型这里肯定是要根据自己的需求进行定制的,这里我创建的模型是这样的: 93 | 94 | ```Objective-C 95 | @interface LZCartModel : NSObject 96 | //自定义模型时,这三个属性必须有 97 | @property (nonatomic,assign) BOOL select; 98 | @property (nonatomic,assign) NSInteger number; 99 | @property (nonatomic,copy) NSString *price; 100 | //下面的属性可根据自己的需求修改 101 | @property (nonatomic,copy) NSString *sizeStr; 102 | @property (nonatomic,copy) NSString *nameStr; 103 | @property (nonatomic,copy) NSString *dateStr; 104 | @property (nonatomic,retain)UIImage *image; 105 | 106 | @end 107 | ``` 108 | 需要注意的是,demo中的模型前三个属性,是必须要有的,一般购物车也都有这些属性,如果不想改动太多,建议使用和我一样的命名 109 | - select:用来记录当前数据是否被选中; 110 | - number和price:用来计算总价; 111 | 112 | ##### 关于自定义单元格`LZCartTableViewCell` 113 | 建议直接修改界面布局为自己项目的设计,里面大部分的逻辑是不需要动的,除非你把网络请求的一些东西放到`cell`中来了; 114 | .h文件内的属性和方法,建议不要修改,可以直接使用; 115 | ##### 关于`ConfigFile`文件夹 116 | 里面有三个文件,一个是`UIView`的扩展类目;一个是头文件,保存一些公共的宏定义和全局变量; 117 | ### 效果图 118 | ![效果图](https://github.com/LQQZYY/CartDemo/blob/master/test.gif) 119 | ![增加分组效果图](https://github.com/LQQZYY/CartDemo/blob/master/testttt.gif) 120 | ### 总结 121 | 购物车的逻辑其实并不复杂,重构这个`demo`也花了不少时间,希望对你能有所帮助,使用过程中如果有bug,或者功能上错误,或者一些新功能,或者其他的建议,请可以联系我302934443; 122 | #### 如果对你有帮助,欢迎右上角`star`或者`fork` 123 | ##### 本人[CSDN博客](http://blog.csdn.net/lqq200912408),欢迎访问,一同学习!!!! 124 | ##### [简书地址](http://www.jianshu.com/users/2846c3d3a974/latest_articles),目前文章还不多,慢慢的会发一些学习总结,欢迎关注! 125 | -------------------------------------------------------------------------------- /Untitled.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Untitled.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Untitled.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/Untitled.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Untitled.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/test.gif -------------------------------------------------------------------------------- /testttt.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrices/LQCartViewController/cff44d491ea908e858014f39e61bb3e682c58be4/testttt.gif --------------------------------------------------------------------------------