├── README.md ├── chosetype.gif └── shoppingcart ├── shoppingcart.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── lanaohudong.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── lanaohudong.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── shoppingcart ├── 0.jpg ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── guanbi.imageset │ │ ├── Contents.json │ │ ├── guanbi@2x.png │ │ └── guanbi@3x.png │ └── jiantou_down.imageset │ │ ├── Contents.json │ │ ├── jiantou_down@2x.png │ │ └── jiantou_down@3x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Header.swift ├── Info.plist ├── SVProgressHUD │ ├── SVIndefiniteAnimatedView.h │ ├── SVIndefiniteAnimatedView.m │ ├── SVProgressAnimatedView.h │ ├── SVProgressAnimatedView.m │ ├── SVProgressHUD-Prefix.pch │ ├── SVProgressHUD.bundle │ │ ├── angle-mask.png │ │ ├── angle-mask@2x.png │ │ ├── angle-mask@3x.png │ │ ├── error.png │ │ ├── error@2x.png │ │ ├── error@3x.png │ │ ├── info.png │ │ ├── info@2x.png │ │ ├── info@3x.png │ │ ├── success.png │ │ ├── success@2x.png │ │ └── success@3x.png │ ├── SVProgressHUD.h │ ├── SVProgressHUD.m │ ├── SVRadialGradientLayer.h │ └── SVRadialGradientLayer.m ├── Source │ ├── Constraint.swift │ ├── ConstraintAttributes.swift │ ├── ConstraintConfig.swift │ ├── ConstraintConstantTarget.swift │ ├── ConstraintDSL.swift │ ├── ConstraintDescription.swift │ ├── ConstraintInsetTarget.swift │ ├── ConstraintInsets.swift │ ├── ConstraintItem.swift │ ├── ConstraintLayoutGuide+Extensions.swift │ ├── ConstraintLayoutGuide.swift │ ├── ConstraintLayoutGuideDSL.swift │ ├── ConstraintLayoutSupport.swift │ ├── ConstraintLayoutSupportDSL.swift │ ├── ConstraintMaker.swift │ ├── ConstraintMakerEditable.swift │ ├── ConstraintMakerExtendable.swift │ ├── ConstraintMakerFinalizable.swift │ ├── ConstraintMakerPriortizable.swift │ ├── ConstraintMakerRelatable.swift │ ├── ConstraintMultiplierTarget.swift │ ├── ConstraintOffsetTarget.swift │ ├── ConstraintPriority.swift │ ├── ConstraintPriorityTarget.swift │ ├── ConstraintRelatableTarget.swift │ ├── ConstraintRelation.swift │ ├── ConstraintView+Extensions.swift │ ├── ConstraintView.swift │ ├── ConstraintViewDSL.swift │ ├── Debugging.swift │ ├── LayoutConstraint.swift │ ├── LayoutConstraintItem.swift │ ├── SnapKit.h │ ├── Typealiases.swift │ └── UILayoutSupport+Extensions.swift ├── ViewController.swift ├── shoppingcart.h └── 规格选择 │ ├── Models │ ├── GoodsModel.swift │ ├── GoodsPriceModel.swift │ ├── GoodsTypeModel.swift │ └── SizeAttributeModel.swift │ └── views │ ├── ChoosTypeTableViewCell.swift │ ├── ChoseGoodsTypeAlert.swift │ ├── CountView.swift │ ├── GoodsinfoView.swift │ └── TypeView.swift ├── shoppingcartTests ├── Info.plist └── shoppingcartTests.swift └── shoppingcartUITests ├── Info.plist └── shoppingcartUITests.swift /README.md: -------------------------------------------------------------------------------- 1 | 初学swift的demo,可能存在问题,可参考实现思路,根据oc版转换过来 2 | oc:https://github.com/qlyx/ChoseGoodsType 3 | 4 | 使用tableview可以设置多个商品规格,刷新数据源即可 5 | 6 | ![image](https://github.com/qlyx/swiftChooseGoodsType/blob/master/chosetype.gif) 7 | 8 | -------------------------------------------------------------------------------- /chosetype.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/chosetype.gif -------------------------------------------------------------------------------- /shoppingcart/shoppingcart.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart.xcodeproj/project.xcworkspace/xcuserdata/lanaohudong.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart.xcodeproj/project.xcworkspace/xcuserdata/lanaohudong.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /shoppingcart/shoppingcart.xcodeproj/xcuserdata/lanaohudong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart.xcodeproj/xcuserdata/lanaohudong.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | shoppingcart.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/0.jpg -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/1.jpg -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/2.jpg -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/3.jpg -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // shoppingcart 4 | // 5 | // Created by 澜海利奥 on 2018/2/5. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/guanbi.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "guanbi@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "guanbi@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/guanbi.imageset/guanbi@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/Assets.xcassets/guanbi.imageset/guanbi@2x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/guanbi.imageset/guanbi@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/Assets.xcassets/guanbi.imageset/guanbi@3x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/jiantou_down.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "jiantou_down@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "jiantou_down@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/jiantou_down.imageset/jiantou_down@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/Assets.xcassets/jiantou_down.imageset/jiantou_down@2x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Assets.xcassets/jiantou_down.imageset/jiantou_down@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/Assets.xcassets/jiantou_down.imageset/jiantou_down@3x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/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 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/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 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Header.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // shoppingcart 4 | // 5 | // Created by 澜海利奥 on 2018/2/5. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | 13 | let kWidth = UIScreen.main.bounds.size.width 14 | let kHeight = UIScreen.main.bounds.size.height 15 | let KBtncol = UIColor.red 16 | func kSize(width:CGFloat)->CGFloat{ 17 | return CGFloat(width*(kWidth/375)) 18 | } 19 | 20 | func cutCorner(cornerRadius:CGFloat,borderWidth:CGFloat,borderColor:UIColor,view:UIView) 21 | { 22 | view.layer.cornerRadius = cornerRadius 23 | view.layer.borderColor = borderColor.cgColor 24 | view.layer.borderWidth = borderWidth 25 | view.layer.masksToBounds = true 26 | } 27 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVIndefiniteAnimatedView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVIndefiniteAnimatedView.h 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2014-2017 Guillaume Campagna. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface SVIndefiniteAnimatedView : UIView 11 | 12 | @property (nonatomic, assign) CGFloat strokeThickness; 13 | @property (nonatomic, assign) CGFloat radius; 14 | @property (nonatomic, strong) UIColor *strokeColor; 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVIndefiniteAnimatedView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVIndefiniteAnimatedView.m 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2014-2017 Guillaume Campagna. All rights reserved. 6 | // 7 | 8 | #import "SVIndefiniteAnimatedView.h" 9 | #import "SVProgressHUD.h" 10 | 11 | @interface SVIndefiniteAnimatedView () 12 | 13 | @property (nonatomic, strong) CAShapeLayer *indefiniteAnimatedLayer; 14 | 15 | @end 16 | 17 | @implementation SVIndefiniteAnimatedView 18 | 19 | - (void)willMoveToSuperview:(UIView*)newSuperview { 20 | if (newSuperview) { 21 | [self layoutAnimatedLayer]; 22 | } else { 23 | [_indefiniteAnimatedLayer removeFromSuperlayer]; 24 | _indefiniteAnimatedLayer = nil; 25 | } 26 | } 27 | 28 | - (void)layoutAnimatedLayer { 29 | CALayer *layer = self.indefiniteAnimatedLayer; 30 | [self.layer addSublayer:layer]; 31 | 32 | CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds); 33 | CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds); 34 | layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2 - widthDiff / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2 - heightDiff / 2); 35 | } 36 | 37 | - (CAShapeLayer*)indefiniteAnimatedLayer { 38 | if(!_indefiniteAnimatedLayer) { 39 | CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5); 40 | UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:self.radius startAngle:(CGFloat) (M_PI*3/2) endAngle:(CGFloat) (M_PI/2+M_PI*5) clockwise:YES]; 41 | 42 | _indefiniteAnimatedLayer = [CAShapeLayer layer]; 43 | _indefiniteAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale]; 44 | _indefiniteAnimatedLayer.frame = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2); 45 | _indefiniteAnimatedLayer.fillColor = [UIColor clearColor].CGColor; 46 | _indefiniteAnimatedLayer.strokeColor = self.strokeColor.CGColor; 47 | _indefiniteAnimatedLayer.lineWidth = self.strokeThickness; 48 | _indefiniteAnimatedLayer.lineCap = kCALineCapRound; 49 | _indefiniteAnimatedLayer.lineJoin = kCALineJoinBevel; 50 | _indefiniteAnimatedLayer.path = smoothedPath.CGPath; 51 | 52 | CALayer *maskLayer = [CALayer layer]; 53 | 54 | NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]]; 55 | NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"]; 56 | NSBundle *imageBundle = [NSBundle bundleWithURL:url]; 57 | 58 | NSString *path = [imageBundle pathForResource:@"angle-mask" ofType:@"png"]; 59 | 60 | maskLayer.contents = (__bridge id)[[UIImage imageWithContentsOfFile:path] CGImage]; 61 | maskLayer.frame = _indefiniteAnimatedLayer.bounds; 62 | _indefiniteAnimatedLayer.mask = maskLayer; 63 | 64 | NSTimeInterval animationDuration = 1; 65 | CAMediaTimingFunction *linearCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 66 | 67 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 68 | animation.fromValue = (id) 0; 69 | animation.toValue = @(M_PI*2); 70 | animation.duration = animationDuration; 71 | animation.timingFunction = linearCurve; 72 | animation.removedOnCompletion = NO; 73 | animation.repeatCount = INFINITY; 74 | animation.fillMode = kCAFillModeForwards; 75 | animation.autoreverses = NO; 76 | [_indefiniteAnimatedLayer.mask addAnimation:animation forKey:@"rotate"]; 77 | 78 | CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; 79 | animationGroup.duration = animationDuration; 80 | animationGroup.repeatCount = INFINITY; 81 | animationGroup.removedOnCompletion = NO; 82 | animationGroup.timingFunction = linearCurve; 83 | 84 | CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"]; 85 | strokeStartAnimation.fromValue = @0.015; 86 | strokeStartAnimation.toValue = @0.515; 87 | 88 | CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 89 | strokeEndAnimation.fromValue = @0.485; 90 | strokeEndAnimation.toValue = @0.985; 91 | 92 | animationGroup.animations = @[strokeStartAnimation, strokeEndAnimation]; 93 | [_indefiniteAnimatedLayer addAnimation:animationGroup forKey:@"progress"]; 94 | 95 | } 96 | return _indefiniteAnimatedLayer; 97 | } 98 | 99 | - (void)setFrame:(CGRect)frame { 100 | if(!CGRectEqualToRect(frame, super.frame)) { 101 | [super setFrame:frame]; 102 | 103 | if(self.superview) { 104 | [self layoutAnimatedLayer]; 105 | } 106 | } 107 | 108 | } 109 | 110 | - (void)setRadius:(CGFloat)radius { 111 | if(radius != _radius) { 112 | _radius = radius; 113 | 114 | [_indefiniteAnimatedLayer removeFromSuperlayer]; 115 | _indefiniteAnimatedLayer = nil; 116 | 117 | if(self.superview) { 118 | [self layoutAnimatedLayer]; 119 | } 120 | } 121 | } 122 | 123 | - (void)setStrokeColor:(UIColor*)strokeColor { 124 | _strokeColor = strokeColor; 125 | _indefiniteAnimatedLayer.strokeColor = strokeColor.CGColor; 126 | } 127 | 128 | - (void)setStrokeThickness:(CGFloat)strokeThickness { 129 | _strokeThickness = strokeThickness; 130 | _indefiniteAnimatedLayer.lineWidth = _strokeThickness; 131 | } 132 | 133 | - (CGSize)sizeThatFits:(CGSize)size { 134 | return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2); 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressAnimatedView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVProgressAnimatedView.h 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2017 Tobias Tiemerding. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface SVProgressAnimatedView : UIView 11 | 12 | @property (nonatomic, assign) CGFloat radius; 13 | @property (nonatomic, assign) CGFloat strokeThickness; 14 | @property (nonatomic, strong) UIColor *strokeColor; 15 | @property (nonatomic, assign) CGFloat strokeEnd; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressAnimatedView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVProgressAnimatedView.m 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2017 Tobias Tiemerding. All rights reserved. 6 | // 7 | 8 | #import "SVProgressAnimatedView.h" 9 | 10 | @interface SVProgressAnimatedView () 11 | 12 | @property (nonatomic, strong) CAShapeLayer *ringAnimatedLayer; 13 | 14 | @end 15 | 16 | @implementation SVProgressAnimatedView 17 | 18 | - (void)willMoveToSuperview:(UIView*)newSuperview { 19 | if (newSuperview) { 20 | [self layoutAnimatedLayer]; 21 | } else { 22 | [_ringAnimatedLayer removeFromSuperlayer]; 23 | _ringAnimatedLayer = nil; 24 | } 25 | } 26 | 27 | - (void)layoutAnimatedLayer { 28 | CALayer *layer = self.ringAnimatedLayer; 29 | [self.layer addSublayer:layer]; 30 | 31 | CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds); 32 | CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds); 33 | layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2 - widthDiff / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2 - heightDiff / 2); 34 | } 35 | 36 | - (CAShapeLayer*)ringAnimatedLayer { 37 | if(!_ringAnimatedLayer) { 38 | CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5); 39 | UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:self.radius startAngle:(CGFloat)-M_PI_2 endAngle:(CGFloat) (M_PI + M_PI_2) clockwise:YES]; 40 | 41 | _ringAnimatedLayer = [CAShapeLayer layer]; 42 | _ringAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale]; 43 | _ringAnimatedLayer.frame = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2); 44 | _ringAnimatedLayer.fillColor = [UIColor clearColor].CGColor; 45 | _ringAnimatedLayer.strokeColor = self.strokeColor.CGColor; 46 | _ringAnimatedLayer.lineWidth = self.strokeThickness; 47 | _ringAnimatedLayer.lineCap = kCALineCapRound; 48 | _ringAnimatedLayer.lineJoin = kCALineJoinBevel; 49 | _ringAnimatedLayer.path = smoothedPath.CGPath; 50 | } 51 | return _ringAnimatedLayer; 52 | } 53 | 54 | - (void)setFrame:(CGRect)frame { 55 | if(!CGRectEqualToRect(frame, super.frame)) { 56 | [super setFrame:frame]; 57 | 58 | if(self.superview) { 59 | [self layoutAnimatedLayer]; 60 | } 61 | } 62 | } 63 | 64 | - (void)setRadius:(CGFloat)radius { 65 | if(radius != _radius) { 66 | _radius = radius; 67 | 68 | [_ringAnimatedLayer removeFromSuperlayer]; 69 | _ringAnimatedLayer = nil; 70 | 71 | if(self.superview) { 72 | [self layoutAnimatedLayer]; 73 | } 74 | } 75 | } 76 | 77 | - (void)setStrokeColor:(UIColor*)strokeColor { 78 | _strokeColor = strokeColor; 79 | _ringAnimatedLayer.strokeColor = strokeColor.CGColor; 80 | } 81 | 82 | - (void)setStrokeThickness:(CGFloat)strokeThickness { 83 | _strokeThickness = strokeThickness; 84 | _ringAnimatedLayer.lineWidth = _strokeThickness; 85 | } 86 | 87 | - (void)setStrokeEnd:(CGFloat)strokeEnd { 88 | _strokeEnd = strokeEnd; 89 | _ringAnimatedLayer.strokeEnd = _strokeEnd; 90 | } 91 | 92 | - (CGSize)sizeThatFits:(CGSize)size { 93 | return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2); 94 | } 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SVProgressHUD' target in the 'SVProgressHUD' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/angle-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/angle-mask.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/angle-mask@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/angle-mask@2x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/angle-mask@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/angle-mask@3x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/error.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/error@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/error@2x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/error@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/error@3x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/info.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/info@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/info@2x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/info@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/info@3x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/success.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/success@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/success@2x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/success@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qlyx/swiftChooseGoodsType/1c439a345c7519abbb98549f9cee773b8f61795a/shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.bundle/success@3x.png -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVProgressHUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVProgressHUD.h 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2011-2017 Sam Vermette and contributors. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | #if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000 12 | 13 | #define UI_APPEARANCE_SELECTOR 14 | 15 | #endif 16 | 17 | extern NSString * _Nonnull const SVProgressHUDDidReceiveTouchEventNotification; 18 | extern NSString * _Nonnull const SVProgressHUDDidTouchDownInsideNotification; 19 | extern NSString * _Nonnull const SVProgressHUDWillDisappearNotification; 20 | extern NSString * _Nonnull const SVProgressHUDDidDisappearNotification; 21 | extern NSString * _Nonnull const SVProgressHUDWillAppearNotification; 22 | extern NSString * _Nonnull const SVProgressHUDDidAppearNotification; 23 | 24 | extern NSString * _Nonnull const SVProgressHUDStatusUserInfoKey; 25 | 26 | typedef NS_ENUM(NSInteger, SVProgressHUDStyle) { 27 | SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred 28 | SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred 29 | SVProgressHUDStyleCustom // uses the fore- and background color properties 30 | }; 31 | 32 | typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) { 33 | SVProgressHUDMaskTypeNone = 1, // default mask type, allow user interactions while HUD is displayed 34 | SVProgressHUDMaskTypeClear, // don't allow user interactions with background objects 35 | SVProgressHUDMaskTypeBlack, // don't allow user interactions with background objects and dim the UI in the back of the HUD (as seen in iOS 7 and above) 36 | SVProgressHUDMaskTypeGradient, // don't allow user interactions with background objects and dim the UI with a a-la UIAlertView background gradient (as seen in iOS 6) 37 | SVProgressHUDMaskTypeCustom // don't allow user interactions with background objects and dim the UI in the back of the HUD with a custom color 38 | }; 39 | 40 | typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) { 41 | SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring) 42 | SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView 43 | }; 44 | 45 | typedef void (^SVProgressHUDShowCompletion)(void); 46 | typedef void (^SVProgressHUDDismissCompletion)(void); 47 | 48 | @interface SVProgressHUD : UIView 49 | 50 | #pragma mark - Customization 51 | 52 | @property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR; // default is SVProgressHUDStyleLight 53 | @property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDMaskTypeNone 54 | @property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDAnimationTypeFlat 55 | @property (strong, nonatomic, nullable) UIView *containerView; // if nil then use default window level 56 | @property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR; // default is CGSizeZero, can be used to avoid resizing for a larger message 57 | @property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR; // default is 2 pt 58 | @property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR; // default is 18 pt 59 | @property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR; // default is 24 pt 60 | @property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; // default is 14 pt 61 | @property (strong, nonatomic, nonnull) UIFont *font UI_APPEARANCE_SELECTOR; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] 62 | @property (strong, nonatomic, nonnull) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor ClearColor] 63 | @property (strong, nonatomic, nonnull) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor blackColor] 64 | @property (strong, nonatomic, nonnull) UIColor *backgroundLayerColor UI_APPEARANCE_SELECTOR;// default is [UIColor colorWithWhite:0 alpha:0.4] 65 | @property (assign, nonatomic) CGSize imageViewSize UI_APPEARANCE_SELECTOR; // default is 28x28 pt 66 | @property (strong, nonatomic, nonnull) UIImage *infoImage UI_APPEARANCE_SELECTOR; // default is the bundled info image provided by Freepik 67 | @property (strong, nonatomic, nonnull) UIImage *successImage UI_APPEARANCE_SELECTOR; // default is the bundled success image provided by Freepik 68 | @property (strong, nonatomic, nonnull) UIImage *errorImage UI_APPEARANCE_SELECTOR; // default is the bundled error image provided by Freepik 69 | @property (strong, nonatomic, nonnull) UIView *viewForExtension UI_APPEARANCE_SELECTOR; // default is nil, only used if #define SV_APP_EXTENSIONS is set 70 | @property (assign, nonatomic) NSTimeInterval graceTimeInterval; // default is 0 seconds 71 | @property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds 72 | @property (assign, nonatomic) NSTimeInterval maximumDismissTimeInterval; // default is CGFLOAT_MAX 73 | 74 | @property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0 75 | 76 | @property (assign, nonatomic) NSTimeInterval fadeInAnimationDuration UI_APPEARANCE_SELECTOR; // default is 0.15 77 | @property (assign, nonatomic) NSTimeInterval fadeOutAnimationDuration UI_APPEARANCE_SELECTOR; // default is 0.15 78 | 79 | @property (assign, nonatomic) UIWindowLevel maxSupportedWindowLevel; // default is UIWindowLevelNormal 80 | 81 | @property (assign, nonatomic) BOOL hapticsEnabled; // default is NO 82 | 83 | + (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight 84 | + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone 85 | + (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat 86 | + (void)setContainerView:(nullable UIView*)containerView; // default is window level 87 | + (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message 88 | + (void)setRingThickness:(CGFloat)ringThickness; // default is 2 pt 89 | + (void)setRingRadius:(CGFloat)radius; // default is 18 pt 90 | + (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt 91 | + (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt 92 | + (void)setBorderColor:(nonnull UIColor*)color; // default is nil 93 | + (void)setBorderWidth:(CGFloat)width; // default is 0 94 | + (void)setFont:(nonnull UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] 95 | + (void)setForegroundColor:(nonnull UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom 96 | + (void)setBackgroundColor:(nonnull UIColor*)color; // default is [UIColor ClearColor], only used for SVProgressHUDStyleCustom 97 | + (void)setBackgroundLayerColor:(nonnull UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.5], only used for SVProgressHUDMaskTypeCustom 98 | + (void)setImageViewSize:(CGSize)size; // default is 28x28 pt 99 | + (void)setInfoImage:(nonnull UIImage*)image; // default is the bundled info image provided by Freepik 100 | + (void)setSuccessImage:(nonnull UIImage*)image; // default is the bundled success image provided by Freepik 101 | + (void)setErrorImage:(nonnull UIImage*)image; // default is the bundled error image provided by Freepik 102 | + (void)setViewForExtension:(nonnull UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set 103 | + (void)setGraceTimeInterval:(NSTimeInterval)interval; // default is 0 seconds 104 | + (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds 105 | + (void)setMaximumDismissTimeInterval:(NSTimeInterval)interval; // default is infinite 106 | + (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds 107 | + (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds 108 | + (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel; // default is UIWindowLevelNormal 109 | + (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO 110 | 111 | #pragma mark - Show Methods 112 | 113 | + (void)show; 114 | + (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead."))); 115 | + (void)showWithStatus:(nullable NSString*)status; 116 | + (void)showWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showWithStatus: and setDefaultMaskType: instead."))); 117 | 118 | + (void)showProgress:(float)progress; 119 | + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead."))); 120 | + (void)showProgress:(float)progress status:(nullable NSString*)status; 121 | + (void)showProgress:(float)progress status:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress:status: and setDefaultMaskType: instead."))); 122 | //只显示文字 123 | + (void)showWithString:(NSString*)string; 124 | + (void)setStatus:(nullable NSString*)status; // change the HUD loading status while it's showing 125 | 126 | // stops the activity indicator, shows a glyph + status, and dismisses the HUD a little bit later 127 | + (void)showInfoWithStatus:(nullable NSString*)status; 128 | + (void)showInfoWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showInfoWithStatus: and setDefaultMaskType: instead."))); 129 | + (void)showSuccessWithStatus:(nullable NSString*)status; 130 | + (void)showSuccessWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showSuccessWithStatus: and setDefaultMaskType: instead."))); 131 | + (void)showErrorWithStatus:(nullable NSString*)status; 132 | + (void)showErrorWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showErrorWithStatus: and setDefaultMaskType: instead."))); 133 | 134 | // shows a image + status, use white PNGs with the imageViewSize (default is 28x28 pt) 135 | + (void)showImage:(nonnull UIImage*)image status:(nullable NSString*)status; 136 | + (void)showImage:(nonnull UIImage*)image status:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showImage:status: and setDefaultMaskType: instead."))); 137 | 138 | + (void)setOffsetFromCenter:(UIOffset)offset; 139 | + (void)resetOffsetFromCenter; 140 | 141 | + (void)popActivity; // decrease activity count, if activity count == 0 the HUD is dismissed 142 | + (void)dismiss; 143 | + (void)dismissWithCompletion:(nullable SVProgressHUDDismissCompletion)completion; 144 | + (void)dismissWithDelay:(NSTimeInterval)delay; 145 | + (void)dismissWithDelay:(NSTimeInterval)delay completion:(nullable SVProgressHUDDismissCompletion)completion; 146 | 147 | + (BOOL)isVisible; 148 | 149 | + (NSTimeInterval)displayDurationForString:(nullable NSString*)string; 150 | 151 | @end 152 | 153 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVRadialGradientLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVRadialGradientLayer.h 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2014-2017 Tobias Tiemerding. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface SVRadialGradientLayer : CALayer 11 | 12 | @property (nonatomic) CGPoint gradientCenter; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/SVProgressHUD/SVRadialGradientLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVRadialGradientLayer.m 3 | // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD 4 | // 5 | // Copyright (c) 2014-2017 Tobias Tiemerding. All rights reserved. 6 | // 7 | 8 | #import "SVRadialGradientLayer.h" 9 | 10 | @implementation SVRadialGradientLayer 11 | 12 | - (void)drawInContext:(CGContextRef)context { 13 | size_t locationsCount = 2; 14 | CGFloat locations[2] = {0.0f, 1.0f}; 15 | CGFloat colors[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f}; 16 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 17 | CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); 18 | CGColorSpaceRelease(colorSpace); 19 | 20 | float radius = MIN(self.bounds.size.width , self.bounds.size.height); 21 | CGContextDrawRadialGradient (context, gradient, self.gradientCenter, 0, self.gradientCenter, radius, kCGGradientDrawsAfterEndLocation); 22 | CGGradientRelease(gradient); 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/Constraint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | public final class Constraint { 31 | 32 | internal let sourceLocation: (String, UInt) 33 | internal let label: String? 34 | 35 | private let from: ConstraintItem 36 | private let to: ConstraintItem 37 | private let relation: ConstraintRelation 38 | private let multiplier: ConstraintMultiplierTarget 39 | private var constant: ConstraintConstantTarget { 40 | didSet { 41 | self.updateConstantAndPriorityIfNeeded() 42 | } 43 | } 44 | private var priority: ConstraintPriorityTarget { 45 | didSet { 46 | self.updateConstantAndPriorityIfNeeded() 47 | } 48 | } 49 | public var layoutConstraints: [LayoutConstraint] 50 | 51 | public var isActive: Bool { 52 | for layoutConstraint in self.layoutConstraints { 53 | if layoutConstraint.isActive { 54 | return true 55 | } 56 | } 57 | return false 58 | } 59 | 60 | // MARK: Initialization 61 | 62 | internal init(from: ConstraintItem, 63 | to: ConstraintItem, 64 | relation: ConstraintRelation, 65 | sourceLocation: (String, UInt), 66 | label: String?, 67 | multiplier: ConstraintMultiplierTarget, 68 | constant: ConstraintConstantTarget, 69 | priority: ConstraintPriorityTarget) { 70 | self.from = from 71 | self.to = to 72 | self.relation = relation 73 | self.sourceLocation = sourceLocation 74 | self.label = label 75 | self.multiplier = multiplier 76 | self.constant = constant 77 | self.priority = priority 78 | self.layoutConstraints = [] 79 | 80 | // get attributes 81 | let layoutFromAttributes = self.from.attributes.layoutAttributes 82 | let layoutToAttributes = self.to.attributes.layoutAttributes 83 | 84 | // get layout from 85 | let layoutFrom = self.from.layoutConstraintItem! 86 | 87 | // get relation 88 | let layoutRelation = self.relation.layoutRelation 89 | 90 | for layoutFromAttribute in layoutFromAttributes { 91 | // get layout to attribute 92 | let layoutToAttribute: LayoutAttribute 93 | #if os(iOS) || os(tvOS) 94 | if layoutToAttributes.count > 0 { 95 | if self.from.attributes == .edges && self.to.attributes == .margins { 96 | switch layoutFromAttribute { 97 | case .left: 98 | layoutToAttribute = .leftMargin 99 | case .right: 100 | layoutToAttribute = .rightMargin 101 | case .top: 102 | layoutToAttribute = .topMargin 103 | case .bottom: 104 | layoutToAttribute = .bottomMargin 105 | default: 106 | fatalError() 107 | } 108 | } else if self.from.attributes == .margins && self.to.attributes == .edges { 109 | switch layoutFromAttribute { 110 | case .leftMargin: 111 | layoutToAttribute = .left 112 | case .rightMargin: 113 | layoutToAttribute = .right 114 | case .topMargin: 115 | layoutToAttribute = .top 116 | case .bottomMargin: 117 | layoutToAttribute = .bottom 118 | default: 119 | fatalError() 120 | } 121 | } else if self.from.attributes == self.to.attributes { 122 | layoutToAttribute = layoutFromAttribute 123 | } else { 124 | layoutToAttribute = layoutToAttributes[0] 125 | } 126 | } else { 127 | if self.to.target == nil && (layoutFromAttribute == .centerX || layoutFromAttribute == .centerY) { 128 | layoutToAttribute = layoutFromAttribute == .centerX ? .left : .top 129 | } else { 130 | layoutToAttribute = layoutFromAttribute 131 | } 132 | } 133 | #else 134 | if self.from.attributes == self.to.attributes { 135 | layoutToAttribute = layoutFromAttribute 136 | } else if layoutToAttributes.count > 0 { 137 | layoutToAttribute = layoutToAttributes[0] 138 | } else { 139 | layoutToAttribute = layoutFromAttribute 140 | } 141 | #endif 142 | 143 | // get layout constant 144 | let layoutConstant: CGFloat = self.constant.constraintConstantTargetValueFor(layoutAttribute: layoutToAttribute) 145 | 146 | // get layout to 147 | var layoutTo: AnyObject? = self.to.target 148 | 149 | // use superview if possible 150 | if layoutTo == nil && layoutToAttribute != .width && layoutToAttribute != .height { 151 | layoutTo = layoutFrom.superview 152 | } 153 | 154 | // create layout constraint 155 | let layoutConstraint = LayoutConstraint( 156 | item: layoutFrom, 157 | attribute: layoutFromAttribute, 158 | relatedBy: layoutRelation, 159 | toItem: layoutTo, 160 | attribute: layoutToAttribute, 161 | multiplier: self.multiplier.constraintMultiplierTargetValue, 162 | constant: layoutConstant 163 | ) 164 | 165 | // set label 166 | layoutConstraint.label = self.label 167 | 168 | // set priority 169 | layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) 170 | 171 | // set constraint 172 | layoutConstraint.constraint = self 173 | 174 | // append 175 | self.layoutConstraints.append(layoutConstraint) 176 | } 177 | } 178 | 179 | // MARK: Public 180 | 181 | @available(*, deprecated:3.0, message:"Use activate().") 182 | public func install() { 183 | self.activate() 184 | } 185 | 186 | @available(*, deprecated:3.0, message:"Use deactivate().") 187 | public func uninstall() { 188 | self.deactivate() 189 | } 190 | 191 | public func activate() { 192 | self.activateIfNeeded() 193 | } 194 | 195 | public func deactivate() { 196 | self.deactivateIfNeeded() 197 | } 198 | 199 | @discardableResult 200 | public func update(offset: ConstraintOffsetTarget) -> Constraint { 201 | self.constant = offset.constraintOffsetTargetValue 202 | return self 203 | } 204 | 205 | @discardableResult 206 | public func update(inset: ConstraintInsetTarget) -> Constraint { 207 | self.constant = inset.constraintInsetTargetValue 208 | return self 209 | } 210 | 211 | @discardableResult 212 | public func update(priority: ConstraintPriorityTarget) -> Constraint { 213 | self.priority = priority.constraintPriorityTargetValue 214 | return self 215 | } 216 | 217 | @discardableResult 218 | public func update(priority: ConstraintPriority) -> Constraint { 219 | self.priority = priority.value 220 | return self 221 | } 222 | 223 | @available(*, deprecated:3.0, message:"Use update(offset: ConstraintOffsetTarget) instead.") 224 | public func updateOffset(amount: ConstraintOffsetTarget) -> Void { self.update(offset: amount) } 225 | 226 | @available(*, deprecated:3.0, message:"Use update(inset: ConstraintInsetTarget) instead.") 227 | public func updateInsets(amount: ConstraintInsetTarget) -> Void { self.update(inset: amount) } 228 | 229 | @available(*, deprecated:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") 230 | public func updatePriority(amount: ConstraintPriorityTarget) -> Void { self.update(priority: amount) } 231 | 232 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") 233 | public func updatePriorityRequired() -> Void {} 234 | 235 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") 236 | public func updatePriorityHigh() -> Void { fatalError("Must be implemented by Concrete subclass.") } 237 | 238 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") 239 | public func updatePriorityMedium() -> Void { fatalError("Must be implemented by Concrete subclass.") } 240 | 241 | @available(*, obsoleted:3.0, message:"Use update(priority: ConstraintPriorityTarget) instead.") 242 | public func updatePriorityLow() -> Void { fatalError("Must be implemented by Concrete subclass.") } 243 | 244 | // MARK: Internal 245 | 246 | internal func updateConstantAndPriorityIfNeeded() { 247 | for layoutConstraint in self.layoutConstraints { 248 | let attribute = (layoutConstraint.secondAttribute == .notAnAttribute) ? layoutConstraint.firstAttribute : layoutConstraint.secondAttribute 249 | layoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: attribute) 250 | 251 | let requiredPriority = ConstraintPriority.required.value 252 | if (layoutConstraint.priority.rawValue < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) { 253 | layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) 254 | } 255 | } 256 | } 257 | 258 | internal func activateIfNeeded(updatingExisting: Bool = false) { 259 | guard let item = self.from.layoutConstraintItem else { 260 | print("WARNING: SnapKit failed to get from item from constraint. Activate will be a no-op.") 261 | return 262 | } 263 | let layoutConstraints = self.layoutConstraints 264 | 265 | if updatingExisting { 266 | var existingLayoutConstraints: [LayoutConstraint] = [] 267 | for constraint in item.constraints { 268 | existingLayoutConstraints += constraint.layoutConstraints 269 | } 270 | 271 | for layoutConstraint in layoutConstraints { 272 | let existingLayoutConstraint = existingLayoutConstraints.first { $0 == layoutConstraint } 273 | guard let updateLayoutConstraint = existingLayoutConstraint else { 274 | fatalError("Updated constraint could not find existing matching constraint to update: \(layoutConstraint)") 275 | } 276 | 277 | let updateLayoutAttribute = (updateLayoutConstraint.secondAttribute == .notAnAttribute) ? updateLayoutConstraint.firstAttribute : updateLayoutConstraint.secondAttribute 278 | updateLayoutConstraint.constant = self.constant.constraintConstantTargetValueFor(layoutAttribute: updateLayoutAttribute) 279 | } 280 | } else { 281 | NSLayoutConstraint.activate(layoutConstraints) 282 | item.add(constraints: [self]) 283 | } 284 | } 285 | 286 | internal func deactivateIfNeeded() { 287 | guard let item = self.from.layoutConstraintItem else { 288 | print("WARNING: SnapKit failed to get from item from constraint. Deactivate will be a no-op.") 289 | return 290 | } 291 | let layoutConstraints = self.layoutConstraints 292 | NSLayoutConstraint.deactivate(layoutConstraints) 293 | item.remove(constraints: [self]) 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintAttributes.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | internal struct ConstraintAttributes : OptionSet { 32 | 33 | internal init(rawValue: UInt) { 34 | self.rawValue = rawValue 35 | } 36 | internal init(_ rawValue: UInt) { 37 | self.init(rawValue: rawValue) 38 | } 39 | internal init(nilLiteral: ()) { 40 | self.rawValue = 0 41 | } 42 | 43 | internal private(set) var rawValue: UInt 44 | internal static var allZeros: ConstraintAttributes { return self.init(0) } 45 | internal static func convertFromNilLiteral() -> ConstraintAttributes { return self.init(0) } 46 | internal var boolValue: Bool { return self.rawValue != 0 } 47 | 48 | internal func toRaw() -> UInt { return self.rawValue } 49 | internal static func fromRaw(_ raw: UInt) -> ConstraintAttributes? { return self.init(raw) } 50 | internal static func fromMask(_ raw: UInt) -> ConstraintAttributes { return self.init(raw) } 51 | 52 | // normal 53 | 54 | internal static var none: ConstraintAttributes { return self.init(0) } 55 | internal static var left: ConstraintAttributes { return self.init(1) } 56 | internal static var top: ConstraintAttributes { return self.init(2) } 57 | internal static var right: ConstraintAttributes { return self.init(4) } 58 | internal static var bottom: ConstraintAttributes { return self.init(8) } 59 | internal static var leading: ConstraintAttributes { return self.init(16) } 60 | internal static var trailing: ConstraintAttributes { return self.init(32) } 61 | internal static var width: ConstraintAttributes { return self.init(64) } 62 | internal static var height: ConstraintAttributes { return self.init(128) } 63 | internal static var centerX: ConstraintAttributes { return self.init(256) } 64 | internal static var centerY: ConstraintAttributes { return self.init(512) } 65 | internal static var lastBaseline: ConstraintAttributes { return self.init(1024) } 66 | 67 | @available(iOS 8.0, OSX 10.11, *) 68 | internal static var firstBaseline: ConstraintAttributes { return self.init(2048) } 69 | 70 | @available(iOS 8.0, *) 71 | internal static var leftMargin: ConstraintAttributes { return self.init(4096) } 72 | 73 | @available(iOS 8.0, *) 74 | internal static var rightMargin: ConstraintAttributes { return self.init(8192) } 75 | 76 | @available(iOS 8.0, *) 77 | internal static var topMargin: ConstraintAttributes { return self.init(16384) } 78 | 79 | @available(iOS 8.0, *) 80 | internal static var bottomMargin: ConstraintAttributes { return self.init(32768) } 81 | 82 | @available(iOS 8.0, *) 83 | internal static var leadingMargin: ConstraintAttributes { return self.init(65536) } 84 | 85 | @available(iOS 8.0, *) 86 | internal static var trailingMargin: ConstraintAttributes { return self.init(131072) } 87 | 88 | @available(iOS 8.0, *) 89 | internal static var centerXWithinMargins: ConstraintAttributes { return self.init(262144) } 90 | 91 | @available(iOS 8.0, *) 92 | internal static var centerYWithinMargins: ConstraintAttributes { return self.init(524288) } 93 | 94 | // aggregates 95 | 96 | internal static var edges: ConstraintAttributes { return self.init(15) } 97 | internal static var size: ConstraintAttributes { return self.init(192) } 98 | internal static var center: ConstraintAttributes { return self.init(768) } 99 | 100 | @available(iOS 8.0, *) 101 | internal static var margins: ConstraintAttributes { return self.init(61440) } 102 | 103 | @available(iOS 8.0, *) 104 | internal static var centerWithinMargins: ConstraintAttributes { return self.init(786432) } 105 | 106 | internal var layoutAttributes:[LayoutAttribute] { 107 | var attrs = [LayoutAttribute]() 108 | if (self.contains(ConstraintAttributes.left)) { 109 | attrs.append(.left) 110 | } 111 | if (self.contains(ConstraintAttributes.top)) { 112 | attrs.append(.top) 113 | } 114 | if (self.contains(ConstraintAttributes.right)) { 115 | attrs.append(.right) 116 | } 117 | if (self.contains(ConstraintAttributes.bottom)) { 118 | attrs.append(.bottom) 119 | } 120 | if (self.contains(ConstraintAttributes.leading)) { 121 | attrs.append(.leading) 122 | } 123 | if (self.contains(ConstraintAttributes.trailing)) { 124 | attrs.append(.trailing) 125 | } 126 | if (self.contains(ConstraintAttributes.width)) { 127 | attrs.append(.width) 128 | } 129 | if (self.contains(ConstraintAttributes.height)) { 130 | attrs.append(.height) 131 | } 132 | if (self.contains(ConstraintAttributes.centerX)) { 133 | attrs.append(.centerX) 134 | } 135 | if (self.contains(ConstraintAttributes.centerY)) { 136 | attrs.append(.centerY) 137 | } 138 | if (self.contains(ConstraintAttributes.lastBaseline)) { 139 | attrs.append(.lastBaseline) 140 | } 141 | 142 | #if os(iOS) || os(tvOS) 143 | if (self.contains(ConstraintAttributes.firstBaseline)) { 144 | attrs.append(.firstBaseline) 145 | } 146 | if (self.contains(ConstraintAttributes.leftMargin)) { 147 | attrs.append(.leftMargin) 148 | } 149 | if (self.contains(ConstraintAttributes.rightMargin)) { 150 | attrs.append(.rightMargin) 151 | } 152 | if (self.contains(ConstraintAttributes.topMargin)) { 153 | attrs.append(.topMargin) 154 | } 155 | if (self.contains(ConstraintAttributes.bottomMargin)) { 156 | attrs.append(.bottomMargin) 157 | } 158 | if (self.contains(ConstraintAttributes.leadingMargin)) { 159 | attrs.append(.leadingMargin) 160 | } 161 | if (self.contains(ConstraintAttributes.trailingMargin)) { 162 | attrs.append(.trailingMargin) 163 | } 164 | if (self.contains(ConstraintAttributes.centerXWithinMargins)) { 165 | attrs.append(.centerXWithinMargins) 166 | } 167 | if (self.contains(ConstraintAttributes.centerYWithinMargins)) { 168 | attrs.append(.centerYWithinMargins) 169 | } 170 | #endif 171 | 172 | return attrs 173 | } 174 | } 175 | 176 | internal func + (left: ConstraintAttributes, right: ConstraintAttributes) -> ConstraintAttributes { 177 | return left.union(right) 178 | } 179 | 180 | internal func +=(left: inout ConstraintAttributes, right: ConstraintAttributes) { 181 | left.formUnion(right) 182 | } 183 | 184 | internal func -=(left: inout ConstraintAttributes, right: ConstraintAttributes) { 185 | left.subtract(right) 186 | } 187 | 188 | internal func ==(left: ConstraintAttributes, right: ConstraintAttributes) -> Bool { 189 | return left.rawValue == right.rawValue 190 | } 191 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintConfig.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | public typealias ConstraintInterfaceLayoutDirection = UIUserInterfaceLayoutDirection 27 | #else 28 | import AppKit 29 | public typealias ConstraintInterfaceLayoutDirection = NSUserInterfaceLayoutDirection 30 | #endif 31 | 32 | 33 | public struct ConstraintConfig { 34 | 35 | public static var interfaceLayoutDirection: ConstraintInterfaceLayoutDirection = .leftToRight 36 | 37 | } 38 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintConstantTarget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintConstantTarget { 32 | } 33 | 34 | extension CGPoint: ConstraintConstantTarget { 35 | } 36 | 37 | extension CGSize: ConstraintConstantTarget { 38 | } 39 | 40 | extension ConstraintInsets: ConstraintConstantTarget { 41 | } 42 | 43 | extension ConstraintConstantTarget { 44 | 45 | internal func constraintConstantTargetValueFor(layoutAttribute: LayoutAttribute) -> CGFloat { 46 | if let value = self as? CGFloat { 47 | return value 48 | } 49 | 50 | if let value = self as? Float { 51 | return CGFloat(value) 52 | } 53 | 54 | if let value = self as? Double { 55 | return CGFloat(value) 56 | } 57 | 58 | if let value = self as? Int { 59 | return CGFloat(value) 60 | } 61 | 62 | if let value = self as? UInt { 63 | return CGFloat(value) 64 | } 65 | 66 | if let value = self as? CGSize { 67 | if layoutAttribute == .width { 68 | return value.width 69 | } else if layoutAttribute == .height { 70 | return value.height 71 | } else { 72 | return 0.0 73 | } 74 | } 75 | 76 | if let value = self as? CGPoint { 77 | #if os(iOS) || os(tvOS) 78 | switch layoutAttribute { 79 | case .left, .right, .leading, .trailing, .centerX, .leftMargin, .rightMargin, .leadingMargin, .trailingMargin, .centerXWithinMargins: 80 | return value.x 81 | case .top, .bottom, .centerY, .topMargin, .bottomMargin, .centerYWithinMargins, .lastBaseline, .firstBaseline: 82 | return value.y 83 | case .width, .height, .notAnAttribute: 84 | return 0.0 85 | } 86 | #else 87 | switch layoutAttribute { 88 | case .left, .right, .leading, .trailing, .centerX: 89 | return value.x 90 | case .top, .bottom, .centerY, .lastBaseline, .firstBaseline: 91 | return value.y 92 | case .width, .height, .notAnAttribute: 93 | return 0.0 94 | } 95 | #endif 96 | } 97 | 98 | if let value = self as? ConstraintInsets { 99 | #if os(iOS) || os(tvOS) 100 | switch layoutAttribute { 101 | case .left, .leftMargin, .centerX, .centerXWithinMargins: 102 | return value.left 103 | case .top, .topMargin, .centerY, .centerYWithinMargins, .lastBaseline, .firstBaseline: 104 | return value.top 105 | case .right, .rightMargin: 106 | return -value.right 107 | case .bottom, .bottomMargin: 108 | return -value.bottom 109 | case .leading, .leadingMargin: 110 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right 111 | case .trailing, .trailingMargin: 112 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left 113 | case .width: 114 | return -(value.left + value.right) 115 | case .height: 116 | return -(value.top + value.bottom) 117 | case .notAnAttribute: 118 | return 0.0 119 | } 120 | #else 121 | switch layoutAttribute { 122 | case .left, .centerX: 123 | return value.left 124 | case .top, .centerY, .lastBaseline, .firstBaseline: 125 | return value.top 126 | case .right: 127 | return -value.right 128 | case .bottom: 129 | return -value.bottom 130 | case .leading: 131 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right 132 | case .trailing: 133 | return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left 134 | case .width: 135 | return -(value.left + value.right) 136 | case .height: 137 | return -(value.top + value.bottom) 138 | case .notAnAttribute: 139 | return 0.0 140 | } 141 | #endif 142 | } 143 | 144 | return 0.0 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintDSL.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintDSL { 32 | 33 | var target: AnyObject? { get } 34 | 35 | func setLabel(_ value: String?) 36 | func label() -> String? 37 | 38 | } 39 | extension ConstraintDSL { 40 | 41 | public func setLabel(_ value: String?) { 42 | objc_setAssociatedObject(self.target as Any, &labelKey, value, .OBJC_ASSOCIATION_COPY_NONATOMIC) 43 | } 44 | public func label() -> String? { 45 | return objc_getAssociatedObject(self.target as Any, &labelKey) as? String 46 | } 47 | 48 | } 49 | private var labelKey: UInt8 = 0 50 | 51 | 52 | public protocol ConstraintBasicAttributesDSL : ConstraintDSL { 53 | } 54 | extension ConstraintBasicAttributesDSL { 55 | 56 | // MARK: Basics 57 | 58 | public var left: ConstraintItem { 59 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.left) 60 | } 61 | 62 | public var top: ConstraintItem { 63 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top) 64 | } 65 | 66 | public var right: ConstraintItem { 67 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.right) 68 | } 69 | 70 | public var bottom: ConstraintItem { 71 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom) 72 | } 73 | 74 | public var leading: ConstraintItem { 75 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leading) 76 | } 77 | 78 | public var trailing: ConstraintItem { 79 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailing) 80 | } 81 | 82 | public var width: ConstraintItem { 83 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.width) 84 | } 85 | 86 | public var height: ConstraintItem { 87 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height) 88 | } 89 | 90 | public var centerX: ConstraintItem { 91 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerX) 92 | } 93 | 94 | public var centerY: ConstraintItem { 95 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerY) 96 | } 97 | 98 | public var edges: ConstraintItem { 99 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.edges) 100 | } 101 | 102 | public var size: ConstraintItem { 103 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.size) 104 | } 105 | 106 | public var center: ConstraintItem { 107 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.center) 108 | } 109 | 110 | } 111 | 112 | public protocol ConstraintAttributesDSL : ConstraintBasicAttributesDSL { 113 | } 114 | extension ConstraintAttributesDSL { 115 | 116 | // MARK: Baselines 117 | 118 | @available(*, deprecated:3.0, message:"Use .lastBaseline instead") 119 | public var baseline: ConstraintItem { 120 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline) 121 | } 122 | 123 | @available(iOS 8.0, OSX 10.11, *) 124 | public var lastBaseline: ConstraintItem { 125 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.lastBaseline) 126 | } 127 | 128 | @available(iOS 8.0, OSX 10.11, *) 129 | public var firstBaseline: ConstraintItem { 130 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.firstBaseline) 131 | } 132 | 133 | // MARK: Margins 134 | 135 | @available(iOS 8.0, *) 136 | public var leftMargin: ConstraintItem { 137 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leftMargin) 138 | } 139 | 140 | @available(iOS 8.0, *) 141 | public var topMargin: ConstraintItem { 142 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.topMargin) 143 | } 144 | 145 | @available(iOS 8.0, *) 146 | public var rightMargin: ConstraintItem { 147 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.rightMargin) 148 | } 149 | 150 | @available(iOS 8.0, *) 151 | public var bottomMargin: ConstraintItem { 152 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottomMargin) 153 | } 154 | 155 | @available(iOS 8.0, *) 156 | public var leadingMargin: ConstraintItem { 157 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.leadingMargin) 158 | } 159 | 160 | @available(iOS 8.0, *) 161 | public var trailingMargin: ConstraintItem { 162 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.trailingMargin) 163 | } 164 | 165 | @available(iOS 8.0, *) 166 | public var centerXWithinMargins: ConstraintItem { 167 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerXWithinMargins) 168 | } 169 | 170 | @available(iOS 8.0, *) 171 | public var centerYWithinMargins: ConstraintItem { 172 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerYWithinMargins) 173 | } 174 | 175 | @available(iOS 8.0, *) 176 | public var margins: ConstraintItem { 177 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.margins) 178 | } 179 | 180 | @available(iOS 8.0, *) 181 | public var centerWithinMargins: ConstraintItem { 182 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.centerWithinMargins) 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintDescription.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class ConstraintDescription { 32 | 33 | internal let item: LayoutConstraintItem 34 | internal var attributes: ConstraintAttributes 35 | internal var relation: ConstraintRelation? = nil 36 | internal var sourceLocation: (String, UInt)? = nil 37 | internal var label: String? = nil 38 | internal var related: ConstraintItem? = nil 39 | internal var multiplier: ConstraintMultiplierTarget = 1.0 40 | internal var constant: ConstraintConstantTarget = 0.0 41 | internal var priority: ConstraintPriorityTarget = 1000.0 42 | internal lazy var constraint: Constraint? = { 43 | guard let relation = self.relation, 44 | let related = self.related, 45 | let sourceLocation = self.sourceLocation else { 46 | return nil 47 | } 48 | let from = ConstraintItem(target: self.item, attributes: self.attributes) 49 | 50 | return Constraint( 51 | from: from, 52 | to: related, 53 | relation: relation, 54 | sourceLocation: sourceLocation, 55 | label: self.label, 56 | multiplier: self.multiplier, 57 | constant: self.constant, 58 | priority: self.priority 59 | ) 60 | }() 61 | 62 | // MARK: Initialization 63 | 64 | internal init(item: LayoutConstraintItem, attributes: ConstraintAttributes) { 65 | self.item = item 66 | self.attributes = attributes 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintInsetTarget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintInsetTarget: ConstraintConstantTarget { 32 | } 33 | 34 | extension Int: ConstraintInsetTarget { 35 | } 36 | 37 | extension UInt: ConstraintInsetTarget { 38 | } 39 | 40 | extension Float: ConstraintInsetTarget { 41 | } 42 | 43 | extension Double: ConstraintInsetTarget { 44 | } 45 | 46 | extension CGFloat: ConstraintInsetTarget { 47 | } 48 | 49 | extension ConstraintInsets: ConstraintInsetTarget { 50 | } 51 | 52 | extension ConstraintInsetTarget { 53 | 54 | internal var constraintInsetTargetValue: ConstraintInsets { 55 | if let amount = self as? ConstraintInsets { 56 | return amount 57 | } else if let amount = self as? Float { 58 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) 59 | } else if let amount = self as? Double { 60 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) 61 | } else if let amount = self as? CGFloat { 62 | return ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount) 63 | } else if let amount = self as? Int { 64 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) 65 | } else if let amount = self as? UInt { 66 | return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount)) 67 | } else { 68 | return ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0) 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintInsets.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | #if os(iOS) || os(tvOS) 32 | public typealias ConstraintInsets = UIEdgeInsets 33 | #else 34 | public typealias ConstraintInsets = NSEdgeInsets 35 | #endif 36 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintItem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public final class ConstraintItem { 32 | 33 | internal weak var target: AnyObject? 34 | internal let attributes: ConstraintAttributes 35 | 36 | internal init(target: AnyObject?, attributes: ConstraintAttributes) { 37 | self.target = target 38 | self.attributes = attributes 39 | } 40 | 41 | internal var layoutConstraintItem: LayoutConstraintItem? { 42 | return self.target as? LayoutConstraintItem 43 | } 44 | 45 | } 46 | 47 | public func ==(lhs: ConstraintItem, rhs: ConstraintItem) -> Bool { 48 | // pointer equality 49 | guard lhs !== rhs else { 50 | return true 51 | } 52 | 53 | // must both have valid targets and identical attributes 54 | guard let target1 = lhs.target, 55 | let target2 = rhs.target, 56 | target1 === target2 && lhs.attributes == rhs.attributes else { 57 | return false 58 | } 59 | 60 | return true 61 | } 62 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintLayoutGuide+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #endif 27 | 28 | 29 | @available(iOS 9.0, OSX 10.11, *) 30 | public extension ConstraintLayoutGuide { 31 | 32 | public var snp: ConstraintLayoutGuideDSL { 33 | return ConstraintLayoutGuideDSL(guide: self) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintLayoutGuide.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | #if os(iOS) || os(tvOS) 32 | @available(iOS 9.0, *) 33 | public typealias ConstraintLayoutGuide = UILayoutGuide 34 | #else 35 | @available(OSX 10.11, *) 36 | public typealias ConstraintLayoutGuide = NSLayoutGuide 37 | #endif 38 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintLayoutGuideDSL.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | @available(iOS 9.0, OSX 10.11, *) 32 | public struct ConstraintLayoutGuideDSL: ConstraintAttributesDSL { 33 | 34 | @discardableResult 35 | public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { 36 | return ConstraintMaker.prepareConstraints(item: self.guide, closure: closure) 37 | } 38 | 39 | public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 40 | ConstraintMaker.makeConstraints(item: self.guide, closure: closure) 41 | } 42 | 43 | public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 44 | ConstraintMaker.remakeConstraints(item: self.guide, closure: closure) 45 | } 46 | 47 | public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 48 | ConstraintMaker.updateConstraints(item: self.guide, closure: closure) 49 | } 50 | 51 | public func removeConstraints() { 52 | ConstraintMaker.removeConstraints(item: self.guide) 53 | } 54 | 55 | public var target: AnyObject? { 56 | return self.guide 57 | } 58 | 59 | internal let guide: ConstraintLayoutGuide 60 | 61 | internal init(guide: ConstraintLayoutGuide) { 62 | self.guide = guide 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintLayoutSupport.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | #if os(iOS) || os(tvOS) 32 | @available(iOS 8.0, *) 33 | public typealias ConstraintLayoutSupport = UILayoutSupport 34 | #else 35 | public class ConstraintLayoutSupport {} 36 | #endif 37 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintLayoutSupportDSL.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | @available(iOS 8.0, *) 32 | public struct ConstraintLayoutSupportDSL: ConstraintDSL { 33 | 34 | public var target: AnyObject? { 35 | return self.support 36 | } 37 | 38 | internal let support: ConstraintLayoutSupport 39 | 40 | internal init(support: ConstraintLayoutSupport) { 41 | self.support = support 42 | 43 | } 44 | 45 | public var top: ConstraintItem { 46 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.top) 47 | } 48 | 49 | public var bottom: ConstraintItem { 50 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.bottom) 51 | } 52 | 53 | public var height: ConstraintItem { 54 | return ConstraintItem(target: self.target, attributes: ConstraintAttributes.height) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMaker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | public class ConstraintMaker { 31 | 32 | public var left: ConstraintMakerExtendable { 33 | return self.makeExtendableWithAttributes(.left) 34 | } 35 | 36 | public var top: ConstraintMakerExtendable { 37 | return self.makeExtendableWithAttributes(.top) 38 | } 39 | 40 | public var bottom: ConstraintMakerExtendable { 41 | return self.makeExtendableWithAttributes(.bottom) 42 | } 43 | 44 | public var right: ConstraintMakerExtendable { 45 | return self.makeExtendableWithAttributes(.right) 46 | } 47 | 48 | public var leading: ConstraintMakerExtendable { 49 | return self.makeExtendableWithAttributes(.leading) 50 | } 51 | 52 | public var trailing: ConstraintMakerExtendable { 53 | return self.makeExtendableWithAttributes(.trailing) 54 | } 55 | 56 | public var width: ConstraintMakerExtendable { 57 | return self.makeExtendableWithAttributes(.width) 58 | } 59 | 60 | public var height: ConstraintMakerExtendable { 61 | return self.makeExtendableWithAttributes(.height) 62 | } 63 | 64 | public var centerX: ConstraintMakerExtendable { 65 | return self.makeExtendableWithAttributes(.centerX) 66 | } 67 | 68 | public var centerY: ConstraintMakerExtendable { 69 | return self.makeExtendableWithAttributes(.centerY) 70 | } 71 | 72 | @available(*, deprecated:3.0, message:"Use lastBaseline instead") 73 | public var baseline: ConstraintMakerExtendable { 74 | return self.makeExtendableWithAttributes(.lastBaseline) 75 | } 76 | 77 | public var lastBaseline: ConstraintMakerExtendable { 78 | return self.makeExtendableWithAttributes(.lastBaseline) 79 | } 80 | 81 | @available(iOS 8.0, OSX 10.11, *) 82 | public var firstBaseline: ConstraintMakerExtendable { 83 | return self.makeExtendableWithAttributes(.firstBaseline) 84 | } 85 | 86 | @available(iOS 8.0, *) 87 | public var leftMargin: ConstraintMakerExtendable { 88 | return self.makeExtendableWithAttributes(.leftMargin) 89 | } 90 | 91 | @available(iOS 8.0, *) 92 | public var rightMargin: ConstraintMakerExtendable { 93 | return self.makeExtendableWithAttributes(.rightMargin) 94 | } 95 | 96 | @available(iOS 8.0, *) 97 | public var topMargin: ConstraintMakerExtendable { 98 | return self.makeExtendableWithAttributes(.topMargin) 99 | } 100 | 101 | @available(iOS 8.0, *) 102 | public var bottomMargin: ConstraintMakerExtendable { 103 | return self.makeExtendableWithAttributes(.bottomMargin) 104 | } 105 | 106 | @available(iOS 8.0, *) 107 | public var leadingMargin: ConstraintMakerExtendable { 108 | return self.makeExtendableWithAttributes(.leadingMargin) 109 | } 110 | 111 | @available(iOS 8.0, *) 112 | public var trailingMargin: ConstraintMakerExtendable { 113 | return self.makeExtendableWithAttributes(.trailingMargin) 114 | } 115 | 116 | @available(iOS 8.0, *) 117 | public var centerXWithinMargins: ConstraintMakerExtendable { 118 | return self.makeExtendableWithAttributes(.centerXWithinMargins) 119 | } 120 | 121 | @available(iOS 8.0, *) 122 | public var centerYWithinMargins: ConstraintMakerExtendable { 123 | return self.makeExtendableWithAttributes(.centerYWithinMargins) 124 | } 125 | 126 | public var edges: ConstraintMakerExtendable { 127 | return self.makeExtendableWithAttributes(.edges) 128 | } 129 | public var size: ConstraintMakerExtendable { 130 | return self.makeExtendableWithAttributes(.size) 131 | } 132 | public var center: ConstraintMakerExtendable { 133 | return self.makeExtendableWithAttributes(.center) 134 | } 135 | 136 | @available(iOS 8.0, *) 137 | public var margins: ConstraintMakerExtendable { 138 | return self.makeExtendableWithAttributes(.margins) 139 | } 140 | 141 | @available(iOS 8.0, *) 142 | public var centerWithinMargins: ConstraintMakerExtendable { 143 | return self.makeExtendableWithAttributes(.centerWithinMargins) 144 | } 145 | 146 | private let item: LayoutConstraintItem 147 | private var descriptions = [ConstraintDescription]() 148 | 149 | internal init(item: LayoutConstraintItem) { 150 | self.item = item 151 | self.item.prepare() 152 | } 153 | 154 | internal func makeExtendableWithAttributes(_ attributes: ConstraintAttributes) -> ConstraintMakerExtendable { 155 | let description = ConstraintDescription(item: self.item, attributes: attributes) 156 | self.descriptions.append(description) 157 | return ConstraintMakerExtendable(description) 158 | } 159 | 160 | internal static func prepareConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { 161 | let maker = ConstraintMaker(item: item) 162 | closure(maker) 163 | var constraints: [Constraint] = [] 164 | for description in maker.descriptions { 165 | guard let constraint = description.constraint else { 166 | continue 167 | } 168 | constraints.append(constraint) 169 | } 170 | return constraints 171 | } 172 | 173 | internal static func makeConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) { 174 | let maker = ConstraintMaker(item: item) 175 | closure(maker) 176 | var constraints: [Constraint] = [] 177 | for description in maker.descriptions { 178 | guard let constraint = description.constraint else { 179 | continue 180 | } 181 | constraints.append(constraint) 182 | } 183 | for constraint in constraints { 184 | constraint.activateIfNeeded(updatingExisting: false) 185 | } 186 | } 187 | 188 | internal static func remakeConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) { 189 | self.removeConstraints(item: item) 190 | self.makeConstraints(item: item, closure: closure) 191 | } 192 | 193 | internal static func updateConstraints(item: LayoutConstraintItem, closure: (_ make: ConstraintMaker) -> Void) { 194 | guard item.constraints.count > 0 else { 195 | self.makeConstraints(item: item, closure: closure) 196 | return 197 | } 198 | 199 | let maker = ConstraintMaker(item: item) 200 | closure(maker) 201 | var constraints: [Constraint] = [] 202 | for description in maker.descriptions { 203 | guard let constraint = description.constraint else { 204 | continue 205 | } 206 | constraints.append(constraint) 207 | } 208 | for constraint in constraints { 209 | constraint.activateIfNeeded(updatingExisting: true) 210 | } 211 | } 212 | 213 | internal static func removeConstraints(item: LayoutConstraintItem) { 214 | let constraints = item.constraints 215 | for constraint in constraints { 216 | constraint.deactivateIfNeeded() 217 | } 218 | } 219 | 220 | } 221 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMakerEditable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class ConstraintMakerEditable: ConstraintMakerPriortizable { 32 | 33 | @discardableResult 34 | public func multipliedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { 35 | self.description.multiplier = amount 36 | return self 37 | } 38 | 39 | @discardableResult 40 | public func dividedBy(_ amount: ConstraintMultiplierTarget) -> ConstraintMakerEditable { 41 | return self.multipliedBy(1.0 / amount.constraintMultiplierTargetValue) 42 | } 43 | 44 | @discardableResult 45 | public func offset(_ amount: ConstraintOffsetTarget) -> ConstraintMakerEditable { 46 | self.description.constant = amount.constraintOffsetTargetValue 47 | return self 48 | } 49 | 50 | @discardableResult 51 | public func inset(_ amount: ConstraintInsetTarget) -> ConstraintMakerEditable { 52 | self.description.constant = amount.constraintInsetTargetValue 53 | return self 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMakerExtendable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class ConstraintMakerExtendable: ConstraintMakerRelatable { 32 | 33 | public var left: ConstraintMakerExtendable { 34 | self.description.attributes += .left 35 | return self 36 | } 37 | 38 | public var top: ConstraintMakerExtendable { 39 | self.description.attributes += .top 40 | return self 41 | } 42 | 43 | public var bottom: ConstraintMakerExtendable { 44 | self.description.attributes += .bottom 45 | return self 46 | } 47 | 48 | public var right: ConstraintMakerExtendable { 49 | self.description.attributes += .right 50 | return self 51 | } 52 | 53 | public var leading: ConstraintMakerExtendable { 54 | self.description.attributes += .leading 55 | return self 56 | } 57 | 58 | public var trailing: ConstraintMakerExtendable { 59 | self.description.attributes += .trailing 60 | return self 61 | } 62 | 63 | public var width: ConstraintMakerExtendable { 64 | self.description.attributes += .width 65 | return self 66 | } 67 | 68 | public var height: ConstraintMakerExtendable { 69 | self.description.attributes += .height 70 | return self 71 | } 72 | 73 | public var centerX: ConstraintMakerExtendable { 74 | self.description.attributes += .centerX 75 | return self 76 | } 77 | 78 | public var centerY: ConstraintMakerExtendable { 79 | self.description.attributes += .centerY 80 | return self 81 | } 82 | 83 | @available(*, deprecated:3.0, message:"Use lastBaseline instead") 84 | public var baseline: ConstraintMakerExtendable { 85 | self.description.attributes += .lastBaseline 86 | return self 87 | } 88 | 89 | public var lastBaseline: ConstraintMakerExtendable { 90 | self.description.attributes += .lastBaseline 91 | return self 92 | } 93 | 94 | @available(iOS 8.0, OSX 10.11, *) 95 | public var firstBaseline: ConstraintMakerExtendable { 96 | self.description.attributes += .firstBaseline 97 | return self 98 | } 99 | 100 | @available(iOS 8.0, *) 101 | public var leftMargin: ConstraintMakerExtendable { 102 | self.description.attributes += .leftMargin 103 | return self 104 | } 105 | 106 | @available(iOS 8.0, *) 107 | public var rightMargin: ConstraintMakerExtendable { 108 | self.description.attributes += .rightMargin 109 | return self 110 | } 111 | 112 | @available(iOS 8.0, *) 113 | public var topMargin: ConstraintMakerExtendable { 114 | self.description.attributes += .topMargin 115 | return self 116 | } 117 | 118 | @available(iOS 8.0, *) 119 | public var bottomMargin: ConstraintMakerExtendable { 120 | self.description.attributes += .bottomMargin 121 | return self 122 | } 123 | 124 | @available(iOS 8.0, *) 125 | public var leadingMargin: ConstraintMakerExtendable { 126 | self.description.attributes += .leadingMargin 127 | return self 128 | } 129 | 130 | @available(iOS 8.0, *) 131 | public var trailingMargin: ConstraintMakerExtendable { 132 | self.description.attributes += .trailingMargin 133 | return self 134 | } 135 | 136 | @available(iOS 8.0, *) 137 | public var centerXWithinMargins: ConstraintMakerExtendable { 138 | self.description.attributes += .centerXWithinMargins 139 | return self 140 | } 141 | 142 | @available(iOS 8.0, *) 143 | public var centerYWithinMargins: ConstraintMakerExtendable { 144 | self.description.attributes += .centerYWithinMargins 145 | return self 146 | } 147 | 148 | public var edges: ConstraintMakerExtendable { 149 | self.description.attributes += .edges 150 | return self 151 | } 152 | public var size: ConstraintMakerExtendable { 153 | self.description.attributes += .size 154 | return self 155 | } 156 | 157 | @available(iOS 8.0, *) 158 | public var margins: ConstraintMakerExtendable { 159 | self.description.attributes += .margins 160 | return self 161 | } 162 | 163 | @available(iOS 8.0, *) 164 | public var centerWithinMargins: ConstraintMakerExtendable { 165 | self.description.attributes += .centerWithinMargins 166 | return self 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMakerFinalizable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class ConstraintMakerFinalizable { 32 | 33 | internal let description: ConstraintDescription 34 | 35 | internal init(_ description: ConstraintDescription) { 36 | self.description = description 37 | } 38 | 39 | @discardableResult 40 | public func labeled(_ label: String) -> ConstraintMakerFinalizable { 41 | self.description.label = label 42 | return self 43 | } 44 | 45 | public var constraint: Constraint { 46 | return self.description.constraint! 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMakerPriortizable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { 32 | 33 | @discardableResult 34 | public func priority(_ amount: ConstraintPriority) -> ConstraintMakerFinalizable { 35 | self.description.priority = amount.value 36 | return self 37 | } 38 | 39 | @discardableResult 40 | public func priority(_ amount: ConstraintPriorityTarget) -> ConstraintMakerFinalizable { 41 | self.description.priority = amount 42 | return self 43 | } 44 | 45 | @available(*, deprecated:3.0, message:"Use priority(.required) instead.") 46 | @discardableResult 47 | public func priorityRequired() -> ConstraintMakerFinalizable { 48 | return self.priority(.required) 49 | } 50 | 51 | @available(*, deprecated:3.0, message:"Use priority(.high) instead.") 52 | @discardableResult 53 | public func priorityHigh() -> ConstraintMakerFinalizable { 54 | return self.priority(.high) 55 | } 56 | 57 | @available(*, deprecated:3.0, message:"Use priority(.medium) instead.") 58 | @discardableResult 59 | public func priorityMedium() -> ConstraintMakerFinalizable { 60 | return self.priority(.medium) 61 | } 62 | 63 | @available(*, deprecated:3.0, message:"Use priority(.low) instead.") 64 | @discardableResult 65 | public func priorityLow() -> ConstraintMakerFinalizable { 66 | return self.priority(.low) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMakerRelatable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class ConstraintMakerRelatable { 32 | 33 | internal let description: ConstraintDescription 34 | 35 | internal init(_ description: ConstraintDescription) { 36 | self.description = description 37 | } 38 | 39 | internal func relatedTo(_ other: ConstraintRelatableTarget, relation: ConstraintRelation, file: String, line: UInt) -> ConstraintMakerEditable { 40 | let related: ConstraintItem 41 | let constant: ConstraintConstantTarget 42 | 43 | if let other = other as? ConstraintItem { 44 | guard other.attributes == ConstraintAttributes.none || 45 | other.attributes.layoutAttributes.count <= 1 || 46 | other.attributes.layoutAttributes == self.description.attributes.layoutAttributes || 47 | other.attributes == .edges && self.description.attributes == .margins || 48 | other.attributes == .margins && self.description.attributes == .edges else { 49 | fatalError("Cannot constraint to multiple non identical attributes. (\(file), \(line))"); 50 | } 51 | 52 | related = other 53 | constant = 0.0 54 | } else if let other = other as? ConstraintView { 55 | related = ConstraintItem(target: other, attributes: ConstraintAttributes.none) 56 | constant = 0.0 57 | } else if let other = other as? ConstraintConstantTarget { 58 | related = ConstraintItem(target: nil, attributes: ConstraintAttributes.none) 59 | constant = other 60 | } else if #available(iOS 9.0, OSX 10.11, *), let other = other as? ConstraintLayoutGuide { 61 | related = ConstraintItem(target: other, attributes: ConstraintAttributes.none) 62 | constant = 0.0 63 | } else { 64 | fatalError("Invalid constraint. (\(file), \(line))") 65 | } 66 | 67 | let editable = ConstraintMakerEditable(self.description) 68 | editable.description.sourceLocation = (file, line) 69 | editable.description.relation = relation 70 | editable.description.related = related 71 | editable.description.constant = constant 72 | return editable 73 | } 74 | 75 | @discardableResult 76 | public func equalTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { 77 | return self.relatedTo(other, relation: .equal, file: file, line: line) 78 | } 79 | 80 | @discardableResult 81 | public func equalToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { 82 | guard let other = self.description.item.superview else { 83 | fatalError("Expected superview but found nil when attempting make constraint `equalToSuperview`.") 84 | } 85 | return self.relatedTo(other, relation: .equal, file: file, line: line) 86 | } 87 | 88 | @discardableResult 89 | public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { 90 | return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) 91 | } 92 | 93 | @discardableResult 94 | public func lessThanOrEqualToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable { 95 | guard let other = self.description.item.superview else { 96 | fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperview`.") 97 | } 98 | return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line) 99 | } 100 | 101 | @discardableResult 102 | public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { 103 | return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) 104 | } 105 | 106 | @discardableResult 107 | public func greaterThanOrEqualToSuperview(_ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable { 108 | guard let other = self.description.item.superview else { 109 | fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperview`.") 110 | } 111 | return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintMultiplierTarget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintMultiplierTarget { 32 | 33 | var constraintMultiplierTargetValue: CGFloat { get } 34 | 35 | } 36 | 37 | extension Int: ConstraintMultiplierTarget { 38 | 39 | public var constraintMultiplierTargetValue: CGFloat { 40 | return CGFloat(self) 41 | } 42 | 43 | } 44 | 45 | extension UInt: ConstraintMultiplierTarget { 46 | 47 | public var constraintMultiplierTargetValue: CGFloat { 48 | return CGFloat(self) 49 | } 50 | 51 | } 52 | 53 | extension Float: ConstraintMultiplierTarget { 54 | 55 | public var constraintMultiplierTargetValue: CGFloat { 56 | return CGFloat(self) 57 | } 58 | 59 | } 60 | 61 | extension Double: ConstraintMultiplierTarget { 62 | 63 | public var constraintMultiplierTargetValue: CGFloat { 64 | return CGFloat(self) 65 | } 66 | 67 | } 68 | 69 | extension CGFloat: ConstraintMultiplierTarget { 70 | 71 | public var constraintMultiplierTargetValue: CGFloat { 72 | return self 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintOffsetTarget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintOffsetTarget: ConstraintConstantTarget { 32 | } 33 | 34 | extension Int: ConstraintOffsetTarget { 35 | } 36 | 37 | extension UInt: ConstraintOffsetTarget { 38 | } 39 | 40 | extension Float: ConstraintOffsetTarget { 41 | } 42 | 43 | extension Double: ConstraintOffsetTarget { 44 | } 45 | 46 | extension CGFloat: ConstraintOffsetTarget { 47 | } 48 | 49 | extension ConstraintOffsetTarget { 50 | 51 | internal var constraintOffsetTargetValue: CGFloat { 52 | let offset: CGFloat 53 | if let amount = self as? Float { 54 | offset = CGFloat(amount) 55 | } else if let amount = self as? Double { 56 | offset = CGFloat(amount) 57 | } else if let amount = self as? CGFloat { 58 | offset = CGFloat(amount) 59 | } else if let amount = self as? Int { 60 | offset = CGFloat(amount) 61 | } else if let amount = self as? UInt { 62 | offset = CGFloat(amount) 63 | } else { 64 | offset = 0.0 65 | } 66 | return offset 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintPriority.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | public struct ConstraintPriority : ExpressibleByFloatLiteral, Equatable, Strideable { 31 | public typealias FloatLiteralType = Float 32 | 33 | public let value: Float 34 | 35 | public init(floatLiteral value: Float) { 36 | self.value = value 37 | } 38 | 39 | public init(_ value: Float) { 40 | self.value = value 41 | } 42 | 43 | public static var required: ConstraintPriority { 44 | return 1000.0 45 | } 46 | 47 | public static var high: ConstraintPriority { 48 | return 750.0 49 | } 50 | 51 | public static var medium: ConstraintPriority { 52 | #if os(OSX) 53 | return 501.0 54 | #else 55 | return 500.0 56 | #endif 57 | 58 | } 59 | 60 | public static var low: ConstraintPriority { 61 | return 250.0 62 | } 63 | 64 | public static func ==(lhs: ConstraintPriority, rhs: ConstraintPriority) -> Bool { 65 | return lhs.value == rhs.value 66 | } 67 | 68 | // MARK: Strideable 69 | 70 | public func advanced(by n: FloatLiteralType) -> ConstraintPriority { 71 | return ConstraintPriority(floatLiteral: value + n) 72 | } 73 | 74 | public func distance(to other: ConstraintPriority) -> FloatLiteralType { 75 | return other.value - value 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintPriorityTarget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintPriorityTarget { 32 | 33 | var constraintPriorityTargetValue: Float { get } 34 | 35 | } 36 | 37 | extension Int: ConstraintPriorityTarget { 38 | 39 | public var constraintPriorityTargetValue: Float { 40 | return Float(self) 41 | } 42 | 43 | } 44 | 45 | extension UInt: ConstraintPriorityTarget { 46 | 47 | public var constraintPriorityTargetValue: Float { 48 | return Float(self) 49 | } 50 | 51 | } 52 | 53 | extension Float: ConstraintPriorityTarget { 54 | 55 | public var constraintPriorityTargetValue: Float { 56 | return self 57 | } 58 | 59 | } 60 | 61 | extension Double: ConstraintPriorityTarget { 62 | 63 | public var constraintPriorityTargetValue: Float { 64 | return Float(self) 65 | } 66 | 67 | } 68 | 69 | extension CGFloat: ConstraintPriorityTarget { 70 | 71 | public var constraintPriorityTargetValue: Float { 72 | return Float(self) 73 | } 74 | 75 | } 76 | 77 | #if os(iOS) || os(tvOS) 78 | extension UILayoutPriority: ConstraintPriorityTarget { 79 | 80 | public var constraintPriorityTargetValue: Float { 81 | return self.rawValue 82 | } 83 | 84 | } 85 | #endif 86 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintRelatableTarget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol ConstraintRelatableTarget { 32 | } 33 | 34 | extension Int: ConstraintRelatableTarget { 35 | } 36 | 37 | extension UInt: ConstraintRelatableTarget { 38 | } 39 | 40 | extension Float: ConstraintRelatableTarget { 41 | } 42 | 43 | extension Double: ConstraintRelatableTarget { 44 | } 45 | 46 | extension CGFloat: ConstraintRelatableTarget { 47 | } 48 | 49 | extension CGSize: ConstraintRelatableTarget { 50 | } 51 | 52 | extension CGPoint: ConstraintRelatableTarget { 53 | } 54 | 55 | extension ConstraintInsets: ConstraintRelatableTarget { 56 | } 57 | 58 | extension ConstraintItem: ConstraintRelatableTarget { 59 | } 60 | 61 | extension ConstraintView: ConstraintRelatableTarget { 62 | } 63 | 64 | @available(iOS 9.0, OSX 10.11, *) 65 | extension ConstraintLayoutGuide: ConstraintRelatableTarget { 66 | } 67 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintRelation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | internal enum ConstraintRelation : Int { 32 | case equal = 1 33 | case lessThanOrEqual 34 | case greaterThanOrEqual 35 | 36 | internal var layoutRelation: LayoutRelation { 37 | get { 38 | switch(self) { 39 | case .equal: 40 | return .equal 41 | case .lessThanOrEqual: 42 | return .lessThanOrEqual 43 | case .greaterThanOrEqual: 44 | return .greaterThanOrEqual 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintView+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public extension ConstraintView { 32 | 33 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 34 | public var snp_left: ConstraintItem { return self.snp.left } 35 | 36 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 37 | public var snp_top: ConstraintItem { return self.snp.top } 38 | 39 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 40 | public var snp_right: ConstraintItem { return self.snp.right } 41 | 42 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 43 | public var snp_bottom: ConstraintItem { return self.snp.bottom } 44 | 45 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 46 | public var snp_leading: ConstraintItem { return self.snp.leading } 47 | 48 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 49 | public var snp_trailing: ConstraintItem { return self.snp.trailing } 50 | 51 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 52 | public var snp_width: ConstraintItem { return self.snp.width } 53 | 54 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 55 | public var snp_height: ConstraintItem { return self.snp.height } 56 | 57 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 58 | public var snp_centerX: ConstraintItem { return self.snp.centerX } 59 | 60 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 61 | public var snp_centerY: ConstraintItem { return self.snp.centerY } 62 | 63 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 64 | public var snp_baseline: ConstraintItem { return self.snp.baseline } 65 | 66 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 67 | @available(iOS 8.0, OSX 10.11, *) 68 | public var snp_lastBaseline: ConstraintItem { return self.snp.lastBaseline } 69 | 70 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 71 | @available(iOS 8.0, OSX 10.11, *) 72 | public var snp_firstBaseline: ConstraintItem { return self.snp.firstBaseline } 73 | 74 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 75 | @available(iOS 8.0, *) 76 | public var snp_leftMargin: ConstraintItem { return self.snp.leftMargin } 77 | 78 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 79 | @available(iOS 8.0, *) 80 | public var snp_topMargin: ConstraintItem { return self.snp.topMargin } 81 | 82 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 83 | @available(iOS 8.0, *) 84 | public var snp_rightMargin: ConstraintItem { return self.snp.rightMargin } 85 | 86 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 87 | @available(iOS 8.0, *) 88 | public var snp_bottomMargin: ConstraintItem { return self.snp.bottomMargin } 89 | 90 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 91 | @available(iOS 8.0, *) 92 | public var snp_leadingMargin: ConstraintItem { return self.snp.leadingMargin } 93 | 94 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 95 | @available(iOS 8.0, *) 96 | public var snp_trailingMargin: ConstraintItem { return self.snp.trailingMargin } 97 | 98 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 99 | @available(iOS 8.0, *) 100 | public var snp_centerXWithinMargins: ConstraintItem { return self.snp.centerXWithinMargins } 101 | 102 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 103 | @available(iOS 8.0, *) 104 | public var snp_centerYWithinMargins: ConstraintItem { return self.snp.centerYWithinMargins } 105 | 106 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 107 | public var snp_edges: ConstraintItem { return self.snp.edges } 108 | 109 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 110 | public var snp_size: ConstraintItem { return self.snp.size } 111 | 112 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 113 | public var snp_center: ConstraintItem { return self.snp.center } 114 | 115 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 116 | @available(iOS 8.0, *) 117 | public var snp_margins: ConstraintItem { return self.snp.margins } 118 | 119 | @available(iOS, deprecated:3.0, message:"Use newer snp.* syntax.") 120 | @available(iOS 8.0, *) 121 | public var snp_centerWithinMargins: ConstraintItem { return self.snp.centerWithinMargins } 122 | 123 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 124 | public func snp_prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { 125 | return self.snp.prepareConstraints(closure) 126 | } 127 | 128 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 129 | public func snp_makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 130 | self.snp.makeConstraints(closure) 131 | } 132 | 133 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 134 | public func snp_remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 135 | self.snp.remakeConstraints(closure) 136 | } 137 | 138 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 139 | public func snp_updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 140 | self.snp.updateConstraints(closure) 141 | } 142 | 143 | @available(*, deprecated:3.0, message:"Use newer snp.* syntax.") 144 | public func snp_removeConstraints() { 145 | self.snp.removeConstraints() 146 | } 147 | 148 | public var snp: ConstraintViewDSL { 149 | return ConstraintViewDSL(view: self) 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | #if os(iOS) || os(tvOS) 32 | public typealias ConstraintView = UIView 33 | #else 34 | public typealias ConstraintView = NSView 35 | #endif 36 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/ConstraintViewDSL.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public struct ConstraintViewDSL: ConstraintAttributesDSL { 32 | 33 | @discardableResult 34 | public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] { 35 | return ConstraintMaker.prepareConstraints(item: self.view, closure: closure) 36 | } 37 | 38 | public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 39 | ConstraintMaker.makeConstraints(item: self.view, closure: closure) 40 | } 41 | 42 | public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 43 | ConstraintMaker.remakeConstraints(item: self.view, closure: closure) 44 | } 45 | 46 | public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) { 47 | ConstraintMaker.updateConstraints(item: self.view, closure: closure) 48 | } 49 | 50 | public func removeConstraints() { 51 | ConstraintMaker.removeConstraints(item: self.view) 52 | } 53 | 54 | public var contentHuggingHorizontalPriority: Float { 55 | get { 56 | return self.view.contentHuggingPriority(for: .horizontal).rawValue 57 | } 58 | set { 59 | self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .horizontal) 60 | } 61 | } 62 | 63 | public var contentHuggingVerticalPriority: Float { 64 | get { 65 | return self.view.contentHuggingPriority(for: .vertical).rawValue 66 | } 67 | set { 68 | self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .vertical) 69 | } 70 | } 71 | 72 | public var contentCompressionResistanceHorizontalPriority: Float { 73 | get { 74 | return self.view.contentCompressionResistancePriority(for: .horizontal).rawValue 75 | } 76 | set { 77 | self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .horizontal) 78 | } 79 | } 80 | 81 | public var contentCompressionResistanceVerticalPriority: Float { 82 | get { 83 | return self.view.contentCompressionResistancePriority(for: .vertical).rawValue 84 | } 85 | set { 86 | self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .vertical) 87 | } 88 | } 89 | 90 | public var target: AnyObject? { 91 | return self.view 92 | } 93 | 94 | internal let view: ConstraintView 95 | 96 | internal init(view: ConstraintView) { 97 | self.view = view 98 | 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/Debugging.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | public extension LayoutConstraint { 31 | 32 | override public var description: String { 33 | var description = "<" 34 | 35 | description += descriptionForObject(self) 36 | 37 | if let firstItem = conditionalOptional(from: self.firstItem) { 38 | description += " \(descriptionForObject(firstItem))" 39 | } 40 | 41 | if self.firstAttribute != .notAnAttribute { 42 | description += ".\(descriptionForAttribute(self.firstAttribute))" 43 | } 44 | 45 | description += " \(descriptionForRelation(self.relation))" 46 | 47 | if let secondItem = self.secondItem { 48 | description += " \(descriptionForObject(secondItem))" 49 | } 50 | 51 | if self.secondAttribute != .notAnAttribute { 52 | description += ".\(descriptionForAttribute(self.secondAttribute))" 53 | } 54 | 55 | if self.multiplier != 1.0 { 56 | description += " * \(self.multiplier)" 57 | } 58 | 59 | if self.secondAttribute == .notAnAttribute { 60 | description += " \(self.constant)" 61 | } else { 62 | if self.constant > 0.0 { 63 | description += " + \(self.constant)" 64 | } else if self.constant < 0.0 { 65 | description += " - \(abs(self.constant))" 66 | } 67 | } 68 | 69 | if self.priority.rawValue != 1000.0 { 70 | description += " ^\(self.priority)" 71 | } 72 | 73 | description += ">" 74 | 75 | return description 76 | } 77 | 78 | } 79 | 80 | private func descriptionForRelation(_ relation: LayoutRelation) -> String { 81 | switch relation { 82 | case .equal: return "==" 83 | case .greaterThanOrEqual: return ">=" 84 | case .lessThanOrEqual: return "<=" 85 | } 86 | } 87 | 88 | private func descriptionForAttribute(_ attribute: LayoutAttribute) -> String { 89 | #if os(iOS) || os(tvOS) 90 | switch attribute { 91 | case .notAnAttribute: return "notAnAttribute" 92 | case .top: return "top" 93 | case .left: return "left" 94 | case .bottom: return "bottom" 95 | case .right: return "right" 96 | case .leading: return "leading" 97 | case .trailing: return "trailing" 98 | case .width: return "width" 99 | case .height: return "height" 100 | case .centerX: return "centerX" 101 | case .centerY: return "centerY" 102 | case .lastBaseline: return "lastBaseline" 103 | case .firstBaseline: return "firstBaseline" 104 | case .topMargin: return "topMargin" 105 | case .leftMargin: return "leftMargin" 106 | case .bottomMargin: return "bottomMargin" 107 | case .rightMargin: return "rightMargin" 108 | case .leadingMargin: return "leadingMargin" 109 | case .trailingMargin: return "trailingMargin" 110 | case .centerXWithinMargins: return "centerXWithinMargins" 111 | case .centerYWithinMargins: return "centerYWithinMargins" 112 | } 113 | #else 114 | switch attribute { 115 | case .notAnAttribute: return "notAnAttribute" 116 | case .top: return "top" 117 | case .left: return "left" 118 | case .bottom: return "bottom" 119 | case .right: return "right" 120 | case .leading: return "leading" 121 | case .trailing: return "trailing" 122 | case .width: return "width" 123 | case .height: return "height" 124 | case .centerX: return "centerX" 125 | case .centerY: return "centerY" 126 | case .lastBaseline: return "lastBaseline" 127 | case .firstBaseline: return "firstBaseline" 128 | } 129 | #endif 130 | } 131 | 132 | private func conditionalOptional(from object: Optional) -> Optional { 133 | return object 134 | } 135 | 136 | private func conditionalOptional(from object: T) -> Optional { 137 | return Optional.some(object) 138 | } 139 | 140 | private func descriptionForObject(_ object: AnyObject) -> String { 141 | let pointerDescription = String(format: "%p", UInt(bitPattern: ObjectIdentifier(object))) 142 | var desc = "" 143 | 144 | desc += type(of: object).description() 145 | 146 | if let object = object as? ConstraintView { 147 | desc += ":\(object.snp.label() ?? pointerDescription)" 148 | } else if let object = object as? LayoutConstraint { 149 | desc += ":\(object.label ?? pointerDescription)" 150 | } else { 151 | desc += ":\(pointerDescription)" 152 | } 153 | 154 | if let object = object as? LayoutConstraint, let file = object.constraint?.sourceLocation.0, let line = object.constraint?.sourceLocation.1 { 155 | desc += "@\((file as NSString).lastPathComponent)#\(line)" 156 | } 157 | 158 | desc += "" 159 | return desc 160 | } 161 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/LayoutConstraint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public class LayoutConstraint : NSLayoutConstraint { 32 | 33 | public var label: String? { 34 | get { 35 | return self.identifier 36 | } 37 | set { 38 | self.identifier = newValue 39 | } 40 | } 41 | 42 | internal weak var constraint: Constraint? = nil 43 | 44 | } 45 | 46 | internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool { 47 | guard lhs.firstItem === rhs.firstItem && 48 | lhs.secondItem === rhs.secondItem && 49 | lhs.firstAttribute == rhs.firstAttribute && 50 | lhs.secondAttribute == rhs.secondAttribute && 51 | lhs.relation == rhs.relation && 52 | lhs.priority == rhs.priority && 53 | lhs.multiplier == rhs.multiplier else { 54 | return false 55 | } 56 | return true 57 | } 58 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/LayoutConstraintItem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #else 27 | import AppKit 28 | #endif 29 | 30 | 31 | public protocol LayoutConstraintItem: class { 32 | } 33 | 34 | @available(iOS 9.0, OSX 10.11, *) 35 | extension ConstraintLayoutGuide : LayoutConstraintItem { 36 | } 37 | 38 | extension ConstraintView : LayoutConstraintItem { 39 | } 40 | 41 | 42 | extension LayoutConstraintItem { 43 | 44 | internal func prepare() { 45 | if let view = self as? ConstraintView { 46 | view.translatesAutoresizingMaskIntoConstraints = false 47 | } 48 | } 49 | 50 | internal var superview: ConstraintView? { 51 | if let view = self as? ConstraintView { 52 | return view.superview 53 | } 54 | 55 | if #available(iOS 9.0, OSX 10.11, *), let guide = self as? ConstraintLayoutGuide { 56 | return guide.owningView 57 | } 58 | 59 | return nil 60 | } 61 | internal var constraints: [Constraint] { 62 | return self.constraintsSet.allObjects as! [Constraint] 63 | } 64 | 65 | internal func add(constraints: [Constraint]) { 66 | let constraintsSet = self.constraintsSet 67 | for constraint in constraints { 68 | constraintsSet.add(constraint) 69 | } 70 | } 71 | 72 | internal func remove(constraints: [Constraint]) { 73 | let constraintsSet = self.constraintsSet 74 | for constraint in constraints { 75 | constraintsSet.remove(constraint) 76 | } 77 | } 78 | 79 | private var constraintsSet: NSMutableSet { 80 | let constraintsSet: NSMutableSet 81 | 82 | if let existing = objc_getAssociatedObject(self, &constraintsKey) as? NSMutableSet { 83 | constraintsSet = existing 84 | } else { 85 | constraintsSet = NSMutableSet() 86 | objc_setAssociatedObject(self, &constraintsKey, constraintsSet, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 87 | } 88 | return constraintsSet 89 | 90 | } 91 | 92 | } 93 | private var constraintsKey: UInt8 = 0 94 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/SnapKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import 25 | 26 | FOUNDATION_EXPORT double SnapKitVersionNumber; 27 | FOUNDATION_EXPORT const unsigned char SnapKitVersionString[]; -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/Typealiases.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | import Foundation 25 | 26 | #if os(iOS) || os(tvOS) 27 | import UIKit 28 | typealias LayoutRelation = NSLayoutRelation 29 | typealias LayoutAttribute = NSLayoutAttribute 30 | typealias LayoutPriority = UILayoutPriority 31 | #else 32 | import AppKit 33 | typealias LayoutRelation = NSLayoutConstraint.Relation 34 | typealias LayoutAttribute = NSLayoutConstraint.Attribute 35 | typealias LayoutPriority = NSLayoutConstraint.Priority 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/Source/UILayoutSupport+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SnapKit 3 | // 4 | // Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(iOS) || os(tvOS) 25 | import UIKit 26 | #endif 27 | 28 | 29 | @available(iOS 8.0, *) 30 | public extension ConstraintLayoutSupport { 31 | 32 | public var snp: ConstraintLayoutSupportDSL { 33 | return ConstraintLayoutSupportDSL(support: self) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // shoppingcart 4 | // 5 | // Created by 澜海利奥 on 2018/2/5. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | var model = GoodsModel() 13 | 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | model.imageId = "1.jpg" 18 | model.goodsNo = "商品名" 19 | model.title = "商品标题" 20 | model.totalStock = "100" 21 | //价格信息 22 | model.price = GoodsPriceModel() 23 | model.price.minPrice = "150" 24 | model.price.maxPrice = "158" 25 | model.price.minOriginalPrice = "155" 26 | model.price.maxOriginalPrice = "160" 27 | //属性-应该从服务器获取属性列表 28 | let type1 = GoodsTypeModel() 29 | type1.selectIndex = -1 30 | type1.typeName = "尺码" 31 | type1.typeArray = ["XL", "XXL"] 32 | let type2 = GoodsTypeModel() 33 | type2.selectIndex = -1 34 | type2.typeName = "颜色" 35 | type2.typeArray = ["黑色", "白色", "黑色", "白色", "黑色", "白色", "黑色"] 36 | let type3 = GoodsTypeModel() 37 | type3.selectIndex = -1 38 | type3.typeName = "日期" 39 | type3.typeArray = ["2016", "2017", "2018"] 40 | model.itemsList = [type1, type2, type3] 41 | //属性组合数组-有时候不同的属性组合价格库存都会有差异,选择完之后要对应修改商品的价格、库存图片等信息,可能是获得商品信息时将属性数组一并返回,也可能属性选择后再请求服务器获得属性组合对应的商品信息,根据自己的实际情况调整 42 | model.sizeAttribute = NSMutableArray() 43 | var valueArr = ["XL、黑色、2016", "XXL、黑色、2016", "XL、白色、2016", "XXL、白色、2016", "XL、黑色、2017", "XXL、黑色、2017", "XL、白色、2017", "XXL、白色、2017", "XL、黑色、2018", "XXL、黑色、2018", "XL、白色、2018", "XXL、白色、2018"] 44 | for i in 0.. Void in 67 | //sizeModel 选择的属性模型 68 | SVProgressHUD.showSuccess(withStatus: "选择了:"+sizeModel.value) 69 | 70 | } 71 | alert.initData(goodsModel: model) 72 | alert.showView() 73 | } 74 | 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/shoppingcart.h: -------------------------------------------------------------------------------- 1 | // 2 | // shoppingcart.h 3 | // shoppingcart 4 | // 5 | // Created by 澜海利奥 on 2018/2/7. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | #ifndef shoppingcart_h 10 | #define shoppingcart_h 11 | #import "SVProgressHUD.h" 12 | 13 | #endif /* shoppingcart_h */ 14 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/Models/GoodsModel.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // GoodsModel.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class GoodsModel: NSObject { 13 | var goodsNo = "" //编号 14 | var title = "" //商品标题 15 | var imageId = "" //缩略图id 16 | var totalStock = "" //总库存 17 | 18 | var itemsList = NSArray() //属性列表 19 | var banners = NSArray() //商品轮播图 20 | var sizeAttribute : NSMutableArray! //属性组合列表 21 | var price : GoodsPriceModel! //价格信息-一般商品不同属性组合价格不同,会有个价格范围 22 | } 23 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/Models/GoodsPriceModel.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // GoodsPriceModel.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class GoodsPriceModel: NSObject { 13 | var minPrice = "" //现价 14 | var maxPrice = "" 15 | var minOriginalPrice = "" //原价 16 | var maxOriginalPrice = "" 17 | } 18 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/Models/GoodsTypeModel.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // GoodsTypeModel.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class GoodsTypeModel: NSObject { 13 | var selectIndex = -1 14 | var typeName = "" 15 | var typeArray = NSArray() 16 | 17 | } 18 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/Models/SizeAttributeModel.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // SizeAttributeModel.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class SizeAttributeModel: NSObject { 13 | var goodsNo = "" //商品编号 14 | var sizeid = "" //属性组合id 15 | var imageId = "" //缩略图id 16 | var price = "" //现价 17 | var originalPrice = "" //原价 18 | var stock = "" //库存 19 | var count = "" //数量 20 | var value = "" //可能规格不同商品图片也不同 21 | } 22 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/views/ChoosTypeTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChoosTypeTableViewCell.swift 3 | // shoppingcart 4 | // 5 | // Created by 澜海利奥 on 2018/2/6. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ChoosTypeTableViewCell: UITableViewCell { 12 | var typeView :TypeView! 13 | var _model : GoodsTypeModel! 14 | 15 | override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 16 | super.init(style: style, reuseIdentifier: reuseIdentifier) 17 | backgroundColor = UIColor.white 18 | typeView = TypeView(frame: CGRect(x:0,y:100,width:kWidth,height:10)) 19 | addSubview(typeView) 20 | } 21 | 22 | required init?(coder aDecoder: NSCoder) { 23 | fatalError("init(coder:) has not been implemented") 24 | } 25 | 26 | func setData(model:GoodsTypeModel) -> CGFloat { 27 | _model = model 28 | typeView.initWith(arr: model.typeArray, typeName: model.typeName, index: model.selectIndex) 29 | return (typeView?.height)! 30 | } 31 | 32 | override func awakeFromNib() { 33 | super.awakeFromNib() 34 | // Initialization code 35 | } 36 | 37 | override func setSelected(_ selected: Bool, animated: Bool) { 38 | super.setSelected(selected, animated: animated) 39 | 40 | // Configure the view for the selected state 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/views/ChoseGoodsTypeAlert.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // ChoseGoodsTypeAlert.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/6. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class ChoseGoodsTypeAlert: UIView , UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate{ 13 | 14 | var tableview: UITableView! 15 | var sureButton: UIButton! 16 | var view: UIView! 17 | var bgView: UIView! 18 | var countView: CountView! 19 | var goodsInfo: GoodsinfoView! 20 | var sizeModel: SizeAttributeModel! 21 | 22 | var dataSource = NSMutableArray() 23 | var model: GoodsModel! 24 | var selectSize: ((_ sizeModelBlock: SizeAttributeModel) -> Void)? = nil 25 | 26 | init(frame: CGRect, andHeight height: CGFloat) { 27 | super.init(frame: frame) 28 | backgroundColor = UIColor.clear 29 | view = UIView.init(frame: self.bounds) 30 | view?.backgroundColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.4) 31 | addSubview(view) 32 | let tap = UITapGestureRecognizer.init(target: self, action: #selector(self.hideView)) 33 | view.addGestureRecognizer(tap) 34 | 35 | bgView = UIView.init(frame: CGRect(x:0,y:kHeight,width:kWidth,height:height)) 36 | bgView.backgroundColor = UIColor.white 37 | bgView.isUserInteractionEnabled = true 38 | addSubview(bgView) 39 | 40 | goodsInfo = GoodsinfoView.init(frame: CGRect(x:0,y:0,width:kWidth,height:kSize(width: 110))) 41 | goodsInfo.closeButton.addTarget(self, action: #selector(hideView), for: UIControlEvents.touchUpInside) 42 | bgView.addSubview(goodsInfo) 43 | 44 | sureButton = UIButton.init(type: UIButtonType.custom) 45 | sureButton.titleLabel?.font = UIFont.systemFont(ofSize: 13) 46 | sureButton.setTitle("确定", for: UIControlState.normal) 47 | sureButton.setTitleColor(UIColor.white, for: UIControlState.normal) 48 | sureButton.backgroundColor = UIColor.red 49 | sureButton.addTarget(self, action: #selector(sure), for: .touchUpInside) 50 | bgView.addSubview(sureButton) 51 | sureButton.snp.makeConstraints { (mark) in 52 | mark.width.equalTo(kWidth) 53 | mark.height.equalTo(kSize(width: 49)) 54 | mark.left.equalTo(0) 55 | mark.bottom.equalTo(0) 56 | } 57 | 58 | tableview = UITableView.init(frame: CGRect(x:0,y:0,width:kWidth,height:0), style: UITableViewStyle.plain) 59 | tableview.sectionHeaderHeight = 0 60 | tableview.delegate = self 61 | tableview.dataSource = self 62 | addSubview(tableview) 63 | tableview.snp.makeConstraints { (mark) in 64 | mark.width.equalTo(kWidth) 65 | mark.top.equalTo(goodsInfo.snp.bottom) 66 | mark.left.equalTo(0) 67 | mark.bottom.equalTo(sureButton.snp.top) 68 | } 69 | 70 | countView = CountView.init(frame: CGRect(x:0,y:0,width:kWidth,height:kSize(width: 50))) 71 | countView.countTextField.delegate = self 72 | countView.addButton.addTarget(self, action: #selector(add), for: .touchUpInside) 73 | countView.reduceButton.addTarget(self, action: #selector(reduce), for: .touchUpInside) 74 | countView.textFieldDownButton.addTarget(self, action: #selector(tfresignFirstResponder), for: .touchUpInside) 75 | tableview.tableFooterView = countView 76 | } 77 | 78 | required init?(coder aDecoder: NSCoder) { 79 | fatalError("init(coder:) has not been implemented") 80 | } 81 | //消失 82 | 83 | @objc func hideView() { 84 | self.tfresignFirstResponder() 85 | UIView.animate(withDuration: 0.25, animations: { 86 | self.bgView.center.y = self.bgView.center.y+self.bgView.frame.height 87 | }) { (true) in 88 | self.removeFromSuperview() 89 | } 90 | } 91 | //出现 92 | func showView() { 93 | self.alpha = 1 94 | tableview.alpha = 0 95 | UIView.animate(withDuration: 0.25, animations: { 96 | self.bgView.center.y = self.bgView.center.y-self.bgView.frame.height 97 | }) { (true) in 98 | self.tableview.alpha = 1 99 | } 100 | 101 | } 102 | func initData(goodsModel: GoodsModel) { 103 | model = goodsModel 104 | goodsInfo.initData(model: goodsModel) 105 | dataSource.removeAllObjects() 106 | //传入数据源创建多个属性 107 | dataSource.addObjects(from: model.itemsList as! [GoodsTypeModel]) 108 | //此方法必须在_dataSource赋值后方可调用 109 | self.reloadGoodsInfo() 110 | tableview.reloadData() 111 | } 112 | 113 | //拼接属性字符串 114 | func getSizeStr() -> NSString { 115 | var str = "" 116 | for typemodel:GoodsTypeModel in dataSource as! [GoodsTypeModel] { 117 | if typemodel.selectIndex >= 0 { 118 | if str.count == 0 119 | { 120 | str = typemodel.typeArray[typemodel.selectIndex] as! String 121 | }else 122 | { 123 | str = "\(str)、\(typemodel.typeArray[typemodel.selectIndex])" 124 | } 125 | 126 | } 127 | } 128 | return str as NSString 129 | } 130 | func reloadGoodsInfo() { 131 | for typemodel:GoodsTypeModel in dataSource as! [GoodsTypeModel] { 132 | if typemodel.selectIndex < 0 { 133 | goodsInfo.promatLabel.text = "请选择\(typemodel.typeName)" 134 | break 135 | } 136 | } 137 | let str = self.getSizeStr() 138 | sizeModel = nil 139 | for sizemodel:SizeAttributeModel in model.sizeAttribute as! [SizeAttributeModel] { 140 | //遍历属性组合跟用户当前选择的是否一致 141 | if sizemodel.value == str as String { 142 | sizeModel = sizemodel 143 | if Int(countView.countTextField.text!)! > Int(sizeModel.stock)! { 144 | countView.countTextField.text = sizeModel.stock 145 | } 146 | else if Int(countView.countTextField.text!)! < Int(sizeModel.stock)! { 147 | if Int(countView.countTextField.text!)! == 0 { 148 | countView.countTextField.text = "1" 149 | } 150 | } 151 | 152 | goodsInfo.promatLabel.text = "已选\(sizemodel.value)" 153 | goodsInfo.resetData(sizeModel: sizemodel) 154 | return 155 | } 156 | } 157 | //没找到匹配的,显示默认数据 158 | goodsInfo.initData(model: model) 159 | } 160 | //MARK: 点击方法 161 | @objc func add() { 162 | let count: Int = Int(countView.countTextField.text!)! 163 | //如果有选好的属性就根据选好的属性库存判断,没选择就按总库存判断,数量不能超过库存 164 | if sizeModel != nil { 165 | if count < Int(sizeModel.stock)! { 166 | print(count + 1) 167 | countView.countTextField.text = "\(count + 1)" 168 | } 169 | } 170 | else { 171 | if count < Int(model.totalStock)! { 172 | countView.countTextField.text = "\(count + 1)" 173 | } 174 | } 175 | 176 | } 177 | 178 | @objc func reduce() { 179 | let count: Int = Int(countView.countTextField.text!)! 180 | if count>1 181 | { 182 | countView.countTextField.text = "\(count - 1)" 183 | } 184 | } 185 | 186 | @objc func sure() { 187 | for typemodel: GoodsTypeModel in dataSource as! [GoodsTypeModel]{ 188 | if typemodel.selectIndex < 0 { 189 | SVProgressHUD.show(with: "请选择\(typemodel.typeName)") 190 | 191 | return 192 | } 193 | } 194 | if dataSource.count == 0 { 195 | //该商品无规格 196 | SVProgressHUD.show(with:"该商品无规格") 197 | hideView() 198 | return 199 | } 200 | //判断库存 201 | if Int(sizeModel.stock)! > 0 { 202 | if selectSize != nil { 203 | sizeModel.count = (countView.countTextField.text! as NSString) as String 204 | if self.selectSize != nil{ 205 | selectSize!(sizeModel) 206 | } 207 | } 208 | hideView() 209 | } 210 | else { 211 | SVProgressHUD.show(with:"该规格商品暂无库存无法加入购物车") 212 | } 213 | } 214 | 215 | // MARK: - tf 216 | @objc func tfresignFirstResponder() { 217 | self.tableview.setContentOffset(CGPoint.init(x: 0, y: 0), animated: true) 218 | countView.countTextField.resignFirstResponder() 219 | } 220 | func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { 221 | 222 | tableview.setContentOffset(CGPoint.init(x: 0, y: countView.frame.origin.y), animated: true) 223 | return true 224 | } 225 | func textFieldDidEndEditing(_ textField: UITextField) { 226 | let count: Int = Int(countView.countTextField.text!)! 227 | if sizeModel != nil 228 | { 229 | if count>Int(sizeModel.stock)! 230 | { 231 | SVProgressHUD.show(with:"数量超出库存") 232 | countView.countTextField.text = sizeModel.stock 233 | } 234 | 235 | }else 236 | { 237 | if count>Int(model.totalStock)! 238 | { 239 | SVProgressHUD.show(with:"数量超出库存") 240 | countView.countTextField.text = model.totalStock 241 | } 242 | } 243 | } 244 | // MARK: - 代理 245 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 246 | return dataSource.count 247 | } 248 | 249 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 250 | let ID = "ChoosTypeTableViewCell" 251 | var cell = tableView.dequeueReusableCell(withIdentifier: ID) 252 | if cell == nil { 253 | cell = ChoosTypeTableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: ID) 254 | } 255 | cell?.selectionStyle = UITableViewCellSelectionStyle.none 256 | if indexPath.row Void in 262 | //sizeModel 选择的属性模型 263 | typemodel?.selectIndex = selectIndex 264 | self.reloadGoodsInfo() 265 | } 266 | } 267 | 268 | 269 | return cell! 270 | } 271 | 272 | /* 273 | // Only override draw() if you perform custom drawing. 274 | // An empty implementation adversely affects performance during animation. 275 | override func draw(_ rect: CGRect) { 276 | // Drawing code 277 | } 278 | */ 279 | 280 | } 281 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/views/CountView.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // CountView.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class CountView: UIView { 13 | var label:UILabel! 14 | var reduceButton:UIButton! 15 | var countTextField:UITextField! 16 | var textFieldDownButton:UIButton! 17 | var addButton:UIButton! = nil 18 | 19 | override init(frame: CGRect) { 20 | super.init(frame: frame) 21 | label = UILabel.init() 22 | label.text = "购买数量" 23 | label.font = UIFont.systemFont(ofSize: 14) 24 | addSubview(label) 25 | label.snp.makeConstraints { (mark) in 26 | mark.width.equalTo(kSize(width:100)) 27 | mark.height.equalTo(kSize(width:30)) 28 | mark.left.equalTo(kSize(width:15)) 29 | mark.top.equalTo(kSize(width:10)) 30 | } 31 | //加 32 | addButton = UIButton.init(type: UIButtonType.custom) 33 | addButton.setTitleColor(UIColor.black, for: UIControlState.normal) 34 | addButton.setTitle("+", for: UIControlState.normal) 35 | addButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) 36 | addButton.backgroundColor = UIColor.white 37 | cutCorner(cornerRadius: 4, borderWidth: 1, borderColor: UIColor.lightGray, view: addButton) 38 | addSubview(addButton) 39 | addButton.snp.makeConstraints { (mark) in 40 | mark.width.equalTo(kSize(width:30)) 41 | mark.height.equalTo(kSize(width:30)) 42 | mark.right.equalTo(kSize(width:-15)) 43 | mark.centerY.equalTo(self) 44 | } 45 | //输入框 46 | countTextField = UITextField.init() 47 | countTextField.font = UIFont.systemFont(ofSize: 15) 48 | countTextField.text = "1" 49 | countTextField.textAlignment = NSTextAlignment.center 50 | countTextField.keyboardType = UIKeyboardType.numberPad 51 | cutCorner(cornerRadius: 4, borderWidth: 1, borderColor: UIColor.lightGray, view: countTextField) 52 | addSubview(countTextField) 53 | countTextField.snp.makeConstraints { (mark) in 54 | mark.width.equalTo(kSize(width:60)) 55 | mark.height.equalTo(kSize(width:30)) 56 | mark.right.equalTo(addButton.snp.left).offset(kSize(width:-5)) 57 | mark.centerY.equalTo(self) 58 | } 59 | //添加让键盘下去的按钮 60 | let view = UIView(frame: CGRect(x: 0, y: 0, width: kWidth, height: 40)) 61 | view.backgroundColor = UIColor.white 62 | textFieldDownButton = UIButton.init(type: UIButtonType.custom) 63 | textFieldDownButton.setImage(UIImage.init(named: "jiantou_down"), for: UIControlState.normal) 64 | textFieldDownButton.frame = CGRect(x: kWidth-50, y: 0, width: 50, height: 40) 65 | view.addSubview(textFieldDownButton) 66 | countTextField.inputAccessoryView = view 67 | 68 | //减 69 | reduceButton = UIButton.init(type: UIButtonType.custom) 70 | reduceButton.setTitleColor(UIColor.black, for: UIControlState.normal) 71 | reduceButton.setTitle("-", for: UIControlState.normal) 72 | reduceButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) 73 | reduceButton.backgroundColor = UIColor.white 74 | cutCorner(cornerRadius: 4, borderWidth: 1, borderColor: UIColor.lightGray, view: reduceButton) 75 | addSubview(reduceButton) 76 | reduceButton.snp.makeConstraints { (mark) in 77 | mark.width.equalTo(kSize(width:30)) 78 | mark.height.equalTo(kSize(width:30)) 79 | mark.right.equalTo(countTextField.snp.left).offset(kSize(width:-5)) 80 | mark.centerY.equalTo(self) 81 | } 82 | } 83 | 84 | required init?(coder aDecoder: NSCoder) { 85 | fatalError("init(coder:) has not been implemented") 86 | } 87 | /* 88 | // Only override draw() if you perform custom drawing. 89 | // An empty implementation adversely affects performance during animation. 90 | override func draw(_ rect: CGRect) { 91 | // Drawing code 92 | } 93 | */ 94 | 95 | } 96 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/views/GoodsinfoView.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // GoodsinfoView.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | class GoodsinfoView: UIView { 13 | var promatLabel:UILabel! 14 | var goodsImage:UIImageView! 15 | var goodsTitleLabel:UILabel! 16 | var goodsCountLabel:UILabel! 17 | var goodsPriceLabel:UILabel! 18 | var closeButton:UIButton! 19 | 20 | var _model:GoodsModel! 21 | 22 | override init(frame: CGRect) { 23 | super.init(frame: frame) 24 | //图片 25 | goodsImage = UIImageView.init() 26 | goodsImage.image = UIImage.init(named: "1") 27 | goodsImage.contentMode = UIViewContentMode.scaleAspectFill 28 | goodsImage.clipsToBounds = true 29 | addSubview(goodsImage) 30 | goodsImage.snp.makeConstraints { (mark) in 31 | mark.width.equalTo(kSize(width: 80)) 32 | mark.height.equalTo(kSize(width: 80)) 33 | mark.left.equalTo(kSize(width: 15)) 34 | mark.top.equalTo(kSize(width: 15)) 35 | } 36 | //关闭按钮 37 | closeButton = UIButton.init(type: UIButtonType.custom) 38 | closeButton.setImage(UIImage.init(named: "guanbi"), for: UIControlState.normal) 39 | addSubview(closeButton) 40 | closeButton.snp.makeConstraints { (mark) in 41 | mark.width.equalTo(kSize(width: 40)) 42 | mark.height.equalTo(kSize(width: 40)) 43 | mark.right.equalTo(kSize(width: -10)) 44 | mark.top.equalTo(kSize(width: 10)) 45 | } 46 | //标题 47 | goodsTitleLabel = UILabel.init() 48 | goodsTitleLabel.text = "" 49 | goodsTitleLabel.font = UIFont.systemFont(ofSize: 15) 50 | addSubview(goodsTitleLabel) 51 | goodsTitleLabel.snp.makeConstraints { (mark) in 52 | mark.right.equalTo(kSize(width: -60)) 53 | mark.height.equalTo(kSize(width: 20)) 54 | mark.left.equalTo(goodsImage.snp.right).offset(kSize(width: 10)) 55 | mark.top.equalTo(goodsImage.snp.top) 56 | } 57 | //价格 58 | goodsPriceLabel = UILabel.init() 59 | goodsPriceLabel.text = "" 60 | goodsPriceLabel.font = UIFont.systemFont(ofSize: 14) 61 | goodsPriceLabel.textColor = UIColor.red 62 | addSubview(goodsPriceLabel) 63 | goodsPriceLabel.snp.makeConstraints { (mark) in 64 | mark.right.equalTo(kSize(width: -10)) 65 | mark.height.equalTo(kSize(width: 20)) 66 | mark.left.equalTo(goodsImage.snp.right).offset(kSize(width: 10)) 67 | mark.top.equalTo(goodsTitleLabel.snp.bottom) 68 | } 69 | //库存 70 | goodsCountLabel = UILabel.init() 71 | goodsCountLabel.text = "dd" 72 | goodsCountLabel.font = UIFont.systemFont(ofSize: 14) 73 | goodsCountLabel.textColor = UIColor.lightGray 74 | addSubview(goodsCountLabel) 75 | goodsCountLabel.snp.makeConstraints { (mark) in 76 | mark.right.equalTo(kSize(width: -10)) 77 | mark.height.equalTo(kSize(width: 20)) 78 | mark.left.equalTo(goodsImage.snp.right).offset(kSize(width: 10)) 79 | mark.top.equalTo(goodsPriceLabel.snp.bottom) 80 | } 81 | //提示文字 82 | promatLabel = UILabel.init() 83 | promatLabel.text = "" 84 | promatLabel.font = UIFont.systemFont(ofSize: 14) 85 | promatLabel.textColor = UIColor.gray 86 | addSubview(promatLabel) 87 | promatLabel.snp.makeConstraints { (mark) in 88 | mark.right.equalTo(kSize(width: -10)) 89 | mark.height.equalTo(kSize(width: 20)) 90 | mark.left.equalTo(goodsImage.snp.right).offset(kSize(width: 10)) 91 | mark.top.equalTo(goodsCountLabel.snp.bottom) 92 | } 93 | } 94 | 95 | required init?(coder aDecoder: NSCoder) { 96 | fatalError("init(coder:) has not been implemented") 97 | } 98 | 99 | func initData(model:GoodsModel){ 100 | _model = model 101 | goodsImage.image = UIImage.init(named: model.imageId) 102 | goodsTitleLabel.text = model.title 103 | goodsCountLabel.text = "库存:\(model.totalStock)" 104 | goodsPriceLabel.text = "¥\(model.price.minPrice) ¥\(model.price.minOriginalPrice) " 105 | 106 | //let attributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.lightText,NSAttributedStringKey.font: UIFont.systemFont(ofSize: 13),NSAttributedStringKey.underlineStyle.hashValue:1] as! [NSAttributedStringKey : Any] 107 | let attritu = NSMutableAttributedString(string: goodsPriceLabel.text!) 108 | let range = (goodsPriceLabel.text! as NSString).range(of: "¥\(model.price.minOriginalPrice)") 109 | attritu.addAttributes([NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.lightGray,NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12),NSAttributedStringKey(rawValue: NSAttributedStringKey.baselineOffset.rawValue):0,NSAttributedStringKey(rawValue: NSAttributedStringKey.strikethroughStyle.rawValue):1], range: range) 110 | goodsPriceLabel.attributedText = attritu 111 | } 112 | 113 | //根据选择的属性组合刷新商品信息 114 | func resetData(sizeModel:SizeAttributeModel) { 115 | //判断图片id是否为空 116 | if sizeModel.imageId.isEmpty 117 | { 118 | goodsImage.image = UIImage(named: sizeModel.imageId) 119 | } 120 | else { 121 | goodsImage.image = UIImage(named: _model.imageId) 122 | } 123 | 124 | goodsCountLabel.text = "库存:\(sizeModel.stock)" 125 | goodsPriceLabel.text = "¥\(sizeModel.price) ¥\(sizeModel.originalPrice) " 126 | 127 | let attritu = NSMutableAttributedString(string: goodsPriceLabel.text!) 128 | let range = (goodsPriceLabel.text! as NSString).range(of: "¥\(sizeModel.originalPrice)") 129 | attritu.addAttributes([NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.lightGray,NSAttributedStringKey.font: UIFont.systemFont(ofSize: 12),NSAttributedStringKey(rawValue: NSAttributedStringKey.baselineOffset.rawValue):0,NSAttributedStringKey(rawValue: NSAttributedStringKey.strikethroughStyle.rawValue):1], range: range) 130 | goodsPriceLabel.attributedText = attritu 131 | } 132 | /* 133 | // Only override draw() if you perform custom drawing. 134 | // An empty implementation adversely affects performance during animation. 135 | override func draw(_ rect: CGRect) { 136 | // Drawing code 137 | } 138 | */ 139 | 140 | } 141 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcart/规格选择/views/TypeView.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // TypeView.swift 4 | // shoppingcart 5 | // 6 | // Created by 澜海利奥 on 2018/2/5. 7 | // Copyright © 2018年 江萧. All rights reserved. 8 | // 9 | import Foundation 10 | import UIKit 11 | 12 | class TypeView: UIView { 13 | var height = CGFloat(0) 14 | //定义block 15 | typealias textBlock = (_ selectIndex:Int)->() 16 | var selectButton:textBlock? 17 | 18 | var selectIndex = 0 19 | var typeArray:NSArray! 20 | override init(frame: CGRect) { 21 | super.init(frame: frame) 22 | } 23 | 24 | required init?(coder aDecoder: NSCoder) { 25 | fatalError("init(coder:) has not been implemented") 26 | } 27 | func initWith(arr:NSArray,typeName:String,index:Int) 28 | { 29 | while self.subviews.last != nil { 30 | self.subviews.last?.removeFromSuperview() 31 | } 32 | selectIndex = index 33 | typeArray = arr 34 | 35 | let lab = UILabel.init(frame: CGRect(x: 10, y: 10, width: 200, height: 20)) 36 | lab.text = typeName 37 | lab.textColor = UIColor.black 38 | lab.font = UIFont.systemFont(ofSize: 14) 39 | addSubview(lab) 40 | 41 | var upX = 10,upY = 40 42 | for i:Int in 0.. Int(self.frame.size.width-20-size.width-40){ 56 | upX = 10 57 | upY += 30 58 | } 59 | btn.frame = CGRect(x: upX, y: upY, width: Int(size.width+30.0), height: Int(24)) 60 | cutCorner(cornerRadius: 12, borderWidth: 1, borderColor: UIColor.white, view: btn) 61 | self.addSubview(btn) 62 | btn.tag = 100+i 63 | btn.addTarget(self, action: #selector(self.touchbtn), for: UIControlEvents.touchUpInside) 64 | upX += Int(size.width+40) 65 | if selectIndex == i 66 | { 67 | btn.isSelected = true 68 | btn.backgroundColor = KBtncol 69 | } 70 | } 71 | upY += 30 72 | let line = UILabel.init(frame: CGRect(x: 0, y: CGFloat(upY+10), width: self.frame.size.width, height: 0.5)) 73 | line.backgroundColor = UIColor.lightGray 74 | addSubview(line) 75 | height = CGFloat(upY+11) 76 | self.frame = CGRect(x:0,y:0,width:Int(kWidth),height:Int(self.height)) 77 | } 78 | 79 | @objc func touchbtn(button:UIButton) { 80 | if button.isSelected == false 81 | { 82 | selectIndex = button.tag-100 83 | }else 84 | { 85 | selectIndex = -1 86 | } 87 | for i:Int in 0.. 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcartTests/shoppingcartTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // shoppingcartTests.swift 3 | // shoppingcartTests 4 | // 5 | // Created by 澜海利奥 on 2018/2/5. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import shoppingcart 11 | 12 | class shoppingcartTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcartUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /shoppingcart/shoppingcartUITests/shoppingcartUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // shoppingcartUITests.swift 3 | // shoppingcartUITests 4 | // 5 | // Created by 澜海利奥 on 2018/2/5. 6 | // Copyright © 2018年 江萧. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class shoppingcartUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // 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. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------