Skip to content

Commit 779c374

Browse files
committed
Add .card preset
1 parent 3637940 commit 779c374

File tree

8 files changed

+150
-1
lines changed

8 files changed

+150
-1
lines changed

Assets/Readme/Miniature - Card.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

1.81 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ViewController: UITableViewController {
1616
Alert(key: "Message", preset: .message, title: "Message sended", subtitle: "You can check history"),
1717
Alert(key: "Bolt", preset: .bolt, title: "Power", subtitle: "Now turned on"),
1818
Alert(key: "Eject", preset: .eject, title: "Eject complete", subtitle: nil),
19+
Alert(key: "Card", preset: .card, title: "Payment sent", subtitle: "Thanks for donate"),
1920
Alert(key: "Magic", preset: .magic, title: "Magic here! You see", subtitle: "Strange text, true?"),
2021
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
2122
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ And other
2121
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
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">
24+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Card.svg" width="55">
2425
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Magic.svg" width="55">
2526
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2627
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.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.19"
4+
s.version = "2.0.21"
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
@@ -25,6 +25,7 @@
2525
F412052A2382AF64009C2AC7 /* SPAlertHaptic.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204E42382AC9B009C2AC7 /* SPAlertHaptic.swift */; };
2626
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */; };
2727
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */; };
28+
F45970B423A578A50092CE7C /* SPAlertIconCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */; };
2829
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
2930
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */; };
3031
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
@@ -90,6 +91,7 @@
9091
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
9192
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
9293
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconFlagView.swift; sourceTree = "<group>"; };
94+
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconCardView.swift; sourceTree = "<group>"; };
9395
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
9496
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBoltView.swift; sourceTree = "<group>"; };
9597
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
@@ -196,6 +198,7 @@
196198
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */,
197199
F4CD29F323A037D00051EA23 /* SPAlertIconMagicView.swift */,
198200
F4D1623323A2E47200B5E3E9 /* SPAlertIconEjectView.swift */,
201+
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */,
199202
);
200203
path = Icons;
201204
sourceTree = "<group>";
@@ -412,6 +415,7 @@
412415
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */,
413416
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */,
414417
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */,
418+
F45970B423A578A50092CE7C /* SPAlertIconCardView.swift in Sources */,
415419
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */,
416420
F4CD29F423A037D00051EA23 /* SPAlertIconMagicView.swift in Sources */,
417421
);

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum SPAlertPreset {
4343
case `repeat`
4444
case magic
4545
case eject
46+
case card
4647

4748
/**
4849
View for preset. Wrap to `UIView`.
@@ -83,6 +84,8 @@ public enum SPAlertPreset {
8384
return SPAlertIconMagicView()
8485
case .eject:
8586
return SPAlertIconEjectView()
87+
case .card:
88+
return SPAlertIconCardView()
8689
}
8790
}
8891

@@ -148,6 +151,14 @@ public enum SPAlertPreset {
148151
layout.iconHeight = 77
149152
layout.bottomIconSpace = 32
150153
return layout
154+
case .card:
155+
var layout = SPAlertLayout()
156+
layout.topSpace = 45
157+
layout.bottomSpace = 31
158+
layout.iconWidth = 108
159+
layout.iconHeight = 108
160+
layout.bottomIconSpace = 25
161+
return layout
151162
case .flag:
152163
var layout = SPAlertLayout()
153164
layout.topSpace = 49
@@ -270,6 +281,8 @@ public enum SPAlertPreset {
270281
return .success
271282
case .bolt:
272283
return .success
284+
case .card:
285+
return .success
273286
}
274287
}
275288
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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 SPAlertIconCardView: 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+
CardDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class CardDraw: 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: 67, height: 59), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 67, y: resizedFrame.height / 59)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 3, y: 18.02))
50+
bezierPath.addLine(to: CGPoint(x: 63.06, y: 18.02))
51+
bezierPath.addLine(to: CGPoint(x: 63.06, y: 15.48))
52+
bezierPath.addCurve(to: CGPoint(x: 54.47, y: 7), controlPoint1: CGPoint(x: 63.06, y: 9.84), controlPoint2: CGPoint(x: 60.19, y: 7))
53+
bezierPath.addLine(to: CGPoint(x: 11.59, y: 7))
54+
bezierPath.addCurve(to: CGPoint(x: 3, y: 15.48), controlPoint1: CGPoint(x: 5.84, y: 7), controlPoint2: CGPoint(x: 3, y: 9.84))
55+
bezierPath.addLine(to: CGPoint(x: 3, y: 18.02))
56+
bezierPath.close()
57+
bezierPath.move(to: CGPoint(x: 3, y: 44.55))
58+
bezierPath.addCurve(to: CGPoint(x: 11.59, y: 53), controlPoint1: CGPoint(x: 3, y: 50.18), controlPoint2: CGPoint(x: 5.84, y: 53))
59+
bezierPath.addLine(to: CGPoint(x: 54.47, y: 53))
60+
bezierPath.addCurve(to: CGPoint(x: 63.06, y: 44.55), controlPoint1: CGPoint(x: 60.19, y: 53), controlPoint2: CGPoint(x: 63.06, y: 50.18))
61+
bezierPath.addLine(to: CGPoint(x: 63.06, y: 24.23))
62+
bezierPath.addLine(to: CGPoint(x: 3, y: 24.23))
63+
bezierPath.addLine(to: CGPoint(x: 3, y: 44.55))
64+
bezierPath.close()
65+
bezierPath.move(to: CGPoint(x: 12.13, y: 37.88))
66+
bezierPath.addLine(to: CGPoint(x: 12.13, y: 32.82))
67+
bezierPath.addCurve(to: CGPoint(x: 14.81, y: 30.19), controlPoint1: CGPoint(x: 12.13, y: 31.29), controlPoint2: CGPoint(x: 13.2, y: 30.19))
68+
bezierPath.addLine(to: CGPoint(x: 21.51, y: 30.19))
69+
bezierPath.addCurve(to: CGPoint(x: 24.2, y: 32.82), controlPoint1: CGPoint(x: 23.13, y: 30.19), controlPoint2: CGPoint(x: 24.2, y: 31.29))
70+
bezierPath.addLine(to: CGPoint(x: 24.2, y: 37.88))
71+
bezierPath.addCurve(to: CGPoint(x: 21.51, y: 40.5), controlPoint1: CGPoint(x: 24.2, y: 39.44), controlPoint2: CGPoint(x: 23.13, y: 40.5))
72+
bezierPath.addLine(to: CGPoint(x: 14.81, y: 40.5))
73+
bezierPath.addCurve(to: CGPoint(x: 12.13, y: 37.88), controlPoint1: CGPoint(x: 13.2, y: 40.5), controlPoint2: CGPoint(x: 12.13, y: 39.44))
74+
bezierPath.close()
75+
fillColor.setFill()
76+
bezierPath.fill()
77+
context.restoreGState()
78+
}
79+
80+
@objc(StyleKitNameResizingBehavior)
81+
public enum ResizingBehavior: Int {
82+
83+
case aspectFit
84+
case aspectFill
85+
case stretch
86+
case center
87+
88+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
89+
if rect == target || target == CGRect.zero {
90+
return rect
91+
}
92+
93+
var scales = CGSize.zero
94+
scales.width = abs(target.width / rect.width)
95+
scales.height = abs(target.height / rect.height)
96+
97+
switch self {
98+
case .aspectFit:
99+
scales.width = min(scales.width, scales.height)
100+
scales.height = scales.width
101+
case .aspectFill:
102+
scales.width = max(scales.width, scales.height)
103+
scales.height = scales.width
104+
case .stretch:
105+
break
106+
case .center:
107+
scales.width = 1
108+
scales.height = 1
109+
}
110+
111+
var result = rect.standardized
112+
result.size.width *= scales.width
113+
result.size.height *= scales.height
114+
result.origin.x = target.minX + (target.width - result.width) / 2
115+
result.origin.y = target.minY + (target.height - result.height) / 2
116+
return result
117+
}
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)