Skip to content

Commit 104f2ce

Browse files
committed
Add .cart preset
1 parent 5fa7cdf commit 104f2ce

File tree

8 files changed

+158
-1
lines changed

8 files changed

+158
-1
lines changed

Assets/Readme/Miniature - Cart.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

2.66 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ViewController: UITableViewController {
1717
Alert(key: "Bolt", preset: .bolt, title: "Power", subtitle: "Now turned on"),
1818
Alert(key: "Eject", preset: .eject, title: "Eject complete", subtitle: nil),
1919
Alert(key: "Card", preset: .card, title: "Payment sent", subtitle: "Thanks for donate"),
20+
Alert(key: "Cart", preset: .cart, title: "Add to order", subtitle: "It wait in cart"),
2021
Alert(key: "Like", preset: .like, title: "Thanks for feedback", subtitle: "It helped us"),
2122
Alert(key: "Dislike", preset: .dislike, title: "Thanks for feedback", subtitle: "It helped us"),
2223
Alert(key: "Privacy", preset: .privacy, title: "Privacy accepted", subtitle: "You privacy it important"),

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ And other
2222
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Bolt.svg" width="55">
2323
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Eject.svg" width="55">
2424
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Card.svg" width="55">
25+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Cart.svg" width="55">
2526
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Like.svg" width="55">
2627
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Dislike.svg" width="55">
2728
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Privacy.svg" width="55">

SPAlert.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "SPAlert"
4-
s.version = "2.0.25"
4+
s.version = "2.0.26"
55
s.summary = "Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets."
66
s.homepage = "https://github.com/IvanVorobei/SPAlert"
77
s.source = { :git => "https://github.com/IvanVorobei/SPAlert.git", :tag => s.version }

SPAlert.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
F42DE05623AD7D94007CCE29 /* SPAlertIconPrivacyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42DE05523AD7D94007CCE29 /* SPAlertIconPrivacyView.swift */; };
3131
F45970B423A578A50092CE7C /* SPAlertIconCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */; };
3232
F459720223A841C00092CE7C /* SPAlertIconRotateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */; };
33+
F45DDF2823AFFF3000CA3956 /* SPAlertIconCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45DDF2723AFFF3000CA3956 /* SPAlertIconCartView.swift */; };
3334
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
3435
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */; };
3536
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
@@ -100,6 +101,7 @@
100101
F42DE05523AD7D94007CCE29 /* SPAlertIconPrivacyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconPrivacyView.swift; sourceTree = "<group>"; };
101102
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconCardView.swift; sourceTree = "<group>"; };
102103
F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRotateView.swift; sourceTree = "<group>"; };
104+
F45DDF2723AFFF3000CA3956 /* SPAlertIconCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconCartView.swift; sourceTree = "<group>"; };
103105
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
104106
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBoltView.swift; sourceTree = "<group>"; };
105107
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
@@ -211,6 +213,7 @@
211213
F4146EB123AAA18100AE7658 /* SPAlertIconLikeView.swift */,
212214
F42DE05323AD7D8A007CCE29 /* SPAlertIconDislikeView.swift */,
213215
F42DE05523AD7D94007CCE29 /* SPAlertIconPrivacyView.swift */,
216+
F45DDF2723AFFF3000CA3956 /* SPAlertIconCartView.swift */,
214217
);
215218
path = Icons;
216219
sourceTree = "<group>";
@@ -418,6 +421,7 @@
418421
F41204EC2382AC9B009C2AC7 /* SPAlertIconDoneView.swift in Sources */,
419422
F41204E92382AC9B009C2AC7 /* SPAlertView.swift in Sources */,
420423
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */,
424+
F45DDF2823AFFF3000CA3956 /* SPAlertIconCartView.swift in Sources */,
421425
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */,
422426
F4D3CD58238DA9FE006C3DE2 /* SPAlertIconMoonView.swift in Sources */,
423427
F4D3CD5A238DAA49006C3DE2 /* SPAlertIconStarView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public enum SPAlertPreset {
4848
case like
4949
case dislike
5050
case privacy
51+
case cart
5152

5253
/**
5354
View for preset. Wrap to `UIView`.
@@ -98,6 +99,8 @@ public enum SPAlertPreset {
9899
return SPAlertIconDislikeView()
99100
case .privacy:
100101
return SPAlertIconPrivacyView()
102+
case .cart:
103+
return SPAlertIconCartView()
101104
}
102105
}
103106

@@ -179,6 +182,14 @@ public enum SPAlertPreset {
179182
layout.iconHeight = 108
180183
layout.bottomIconSpace = 25
181184
return layout
185+
case .cart:
186+
var layout = SPAlertLayout()
187+
layout.topSpace = 45
188+
layout.bottomSpace = 31
189+
layout.iconWidth = 108
190+
layout.iconHeight = 108
191+
layout.bottomIconSpace = 25
192+
return layout
182193
case .flag:
183194
var layout = SPAlertLayout()
184195
layout.topSpace = 49
@@ -335,6 +346,8 @@ public enum SPAlertPreset {
335346
return .error
336347
case .privacy:
337348
return .success
349+
case .cart:
350+
return .success
338351
}
339352
}
340353
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2019 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
import UIKit
23+
24+
public class SPAlertIconCartView: UIView {
25+
26+
init() {
27+
super.init(frame: .zero)
28+
self.backgroundColor = .clear
29+
}
30+
31+
required init?(coder aDecoder: NSCoder) {
32+
fatalError("init(coder:) has not been implemented")
33+
}
34+
35+
public override func draw(_ rect: CGRect) {
36+
super.draw(rect)
37+
CartDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class CartDraw: NSObject {
41+
42+
@objc dynamic public class func draw(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 60, height: 56), resizing: ResizingBehavior = .aspectFit, fillColor: UIColor = UIColor(red: 0.349, green: 0.345, blue: 0.353, alpha: 1.000)) {
43+
let context = UIGraphicsGetCurrentContext()!
44+
context.saveGState()
45+
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 72, height: 62), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 72, y: resizedFrame.height / 62)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 3, y: 6.12))
50+
bezierPath.addCurve(to: CGPoint(x: 5.09, y: 8.27), controlPoint1: CGPoint(x: 3, y: 7.28), controlPoint2: CGPoint(x: 3.96, y: 8.27))
51+
bezierPath.addLine(to: CGPoint(x: 14.65, y: 8.27))
52+
bezierPath.addLine(to: CGPoint(x: 19.18, y: 39.32))
53+
bezierPath.addCurve(to: CGPoint(x: 25.99, y: 45.85), controlPoint1: CGPoint(x: 19.77, y: 43.34), controlPoint2: CGPoint(x: 21.89, y: 45.85))
54+
bezierPath.addLine(to: CGPoint(x: 58.99, y: 45.85))
55+
bezierPath.addCurve(to: CGPoint(x: 61.06, y: 43.73), controlPoint1: CGPoint(x: 60.1, y: 45.85), controlPoint2: CGPoint(x: 61.06, y: 44.95))
56+
bezierPath.addCurve(to: CGPoint(x: 58.99, y: 41.61), controlPoint1: CGPoint(x: 61.06, y: 42.52), controlPoint2: CGPoint(x: 60.1, y: 41.61))
57+
bezierPath.addLine(to: CGPoint(x: 26.47, y: 41.61))
58+
bezierPath.addCurve(to: CGPoint(x: 23.62, y: 38.76), controlPoint1: CGPoint(x: 24.86, y: 41.61), controlPoint2: CGPoint(x: 23.87, y: 40.48))
59+
bezierPath.addLine(to: CGPoint(x: 23.16, y: 35.79))
60+
bezierPath.addLine(to: CGPoint(x: 59.05, y: 35.79))
61+
bezierPath.addCurve(to: CGPoint(x: 65.85, y: 29.46), controlPoint1: CGPoint(x: 63.09, y: 35.79), controlPoint2: CGPoint(x: 65.2, y: 33.35))
62+
bezierPath.addLine(to: CGPoint(x: 68.16, y: 14.24))
63+
bezierPath.addCurve(to: CGPoint(x: 68.27, y: 13.16), controlPoint1: CGPoint(x: 68.21, y: 13.87), controlPoint2: CGPoint(x: 68.27, y: 13.42))
64+
bezierPath.addCurve(to: CGPoint(x: 65.7, y: 10.87), controlPoint1: CGPoint(x: 68.27, y: 11.81), controlPoint2: CGPoint(x: 67.25, y: 10.87))
65+
bezierPath.addLine(to: CGPoint(x: 19.54, y: 10.87))
66+
bezierPath.addLine(to: CGPoint(x: 18.98, y: 7.28))
67+
bezierPath.addCurve(to: CGPoint(x: 15.02, y: 4), controlPoint1: CGPoint(x: 18.7, y: 5.1), controlPoint2: CGPoint(x: 17.9, y: 4))
68+
bezierPath.addLine(to: CGPoint(x: 5.09, y: 4))
69+
bezierPath.addCurve(to: CGPoint(x: 3, y: 6.12), controlPoint1: CGPoint(x: 3.96, y: 4), controlPoint2: CGPoint(x: 3, y: 4.99))
70+
bezierPath.close()
71+
bezierPath.move(to: CGPoint(x: 23.62, y: 55.02))
72+
bezierPath.addCurve(to: CGPoint(x: 28.23, y: 59.6), controlPoint1: CGPoint(x: 23.62, y: 57.59), controlPoint2: CGPoint(x: 25.65, y: 59.6))
73+
bezierPath.addCurve(to: CGPoint(x: 32.81, y: 55.02), controlPoint1: CGPoint(x: 30.77, y: 59.6), controlPoint2: CGPoint(x: 32.81, y: 57.59))
74+
bezierPath.addCurve(to: CGPoint(x: 28.23, y: 50.44), controlPoint1: CGPoint(x: 32.81, y: 52.47), controlPoint2: CGPoint(x: 30.77, y: 50.44))
75+
bezierPath.addCurve(to: CGPoint(x: 23.62, y: 55.02), controlPoint1: CGPoint(x: 25.65, y: 50.44), controlPoint2: CGPoint(x: 23.62, y: 52.47))
76+
bezierPath.close()
77+
bezierPath.move(to: CGPoint(x: 50.06, y: 55.02))
78+
bezierPath.addCurve(to: CGPoint(x: 54.67, y: 50.44), controlPoint1: CGPoint(x: 50.06, y: 52.47), controlPoint2: CGPoint(x: 52.12, y: 50.44))
79+
bezierPath.addCurve(to: CGPoint(x: 59.28, y: 55.02), controlPoint1: CGPoint(x: 57.24, y: 50.44), controlPoint2: CGPoint(x: 59.28, y: 52.47))
80+
bezierPath.addCurve(to: CGPoint(x: 54.67, y: 59.6), controlPoint1: CGPoint(x: 59.28, y: 57.59), controlPoint2: CGPoint(x: 57.24, y: 59.6))
81+
bezierPath.addCurve(to: CGPoint(x: 50.06, y: 55.02), controlPoint1: CGPoint(x: 52.12, y: 59.6), controlPoint2: CGPoint(x: 50.06, y: 57.59))
82+
bezierPath.close()
83+
fillColor.setFill()
84+
bezierPath.fill()
85+
context.restoreGState()
86+
}
87+
88+
@objc(StyleKitNameResizingBehavior)
89+
public enum ResizingBehavior: Int {
90+
91+
case aspectFit
92+
case aspectFill
93+
case stretch
94+
case center
95+
96+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
97+
if rect == target || target == CGRect.zero {
98+
return rect
99+
}
100+
101+
var scales = CGSize.zero
102+
scales.width = abs(target.width / rect.width)
103+
scales.height = abs(target.height / rect.height)
104+
105+
switch self {
106+
case .aspectFit:
107+
scales.width = min(scales.width, scales.height)
108+
scales.height = scales.width
109+
case .aspectFill:
110+
scales.width = max(scales.width, scales.height)
111+
scales.height = scales.width
112+
case .stretch:
113+
break
114+
case .center:
115+
scales.width = 1
116+
scales.height = 1
117+
}
118+
119+
var result = rect.standardized
120+
result.size.width *= scales.width
121+
result.size.height *= scales.height
122+
result.origin.x = target.minX + (target.width - result.width) / 2
123+
result.origin.y = target.minY + (target.height - result.height) / 2
124+
return result
125+
}
126+
}
127+
}
128+
}

0 commit comments

Comments
 (0)