Skip to content

Commit 6dd6de9

Browse files
committed
Add .bolt preset
1 parent 99408f6 commit 6dd6de9

File tree

8 files changed

+139
-2
lines changed

8 files changed

+139
-2
lines changed

Assets/Readme/Miniature - Bolt.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

2.21 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ViewController: UITableViewController {
1414
Alert(key: "Exclamation", preset: .exclamation, title: "Oops", subtitle: "Something went wrong"),
1515
Alert(key: "Question", preset: .question, title: "Oops", subtitle: "Form not complete"),
1616
Alert(key: "Message", preset: .message, title: "Message sended", subtitle: "You can check history"),
17+
Alert(key: "Bolt", preset: .bolt, title: "Power", subtitle: "Now turned on"),
1718
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
1819
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),
1920
Alert(key: "Shuffle", preset: .shuffle, title: "Songs Shuffled", subtitle: nil),

Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ And other
1717
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Star.svg" width="55">
1818
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Flag.svg" width="55">
1919
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Exclamation.svg" width="55">
20-
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
2120
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Question.svg" width="55">
21+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
22+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Bolt.svg" width="55">
2223
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2324
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="55">
2425
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Shuffle.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.14"
4+
s.version = "2.0.15"
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
@@ -26,6 +26,7 @@
2626
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */; };
2727
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */; };
2828
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
29+
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */; };
2930
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
3031
F47EE19F23959AE500B02DF2 /* SPAlertIconRepeatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */; };
3132
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */; };
@@ -88,6 +89,7 @@
8889
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
8990
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconFlagView.swift; sourceTree = "<group>"; };
9091
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
92+
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBoltView.swift; sourceTree = "<group>"; };
9193
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
9294
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRepeatView.swift; sourceTree = "<group>"; };
9395
F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBookmarkView.swift; sourceTree = "<group>"; };
@@ -187,6 +189,7 @@
187189
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */,
188190
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */,
189191
F40FB629239ADF940090BA57 /* SPAlertIconQuestionView.swift */,
192+
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */,
190193
);
191194
path = Icons;
192195
sourceTree = "<group>";
@@ -388,6 +391,7 @@
388391
F4E4459D2390524A0067FF5C /* SPAlertIconExclamationView.swift in Sources */,
389392
F41204EA2382AC9B009C2AC7 /* SPAlertPreset.swift in Sources */,
390393
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */,
394+
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */,
391395
F41204EC2382AC9B009C2AC7 /* SPAlertIconDoneView.swift in Sources */,
392396
F41204E92382AC9B009C2AC7 /* SPAlertView.swift in Sources */,
393397
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public enum SPAlertPreset {
3636
case flag
3737
case message
3838
case question
39+
case bolt
3940
case add
4041
case error
4142
case shuffle
@@ -74,6 +75,8 @@ public enum SPAlertPreset {
7475
return SPAlertIconFlagView()
7576
case .question:
7677
return SPAlertIconQuestionView()
78+
case .bolt:
79+
return SPAlertIconBoltView()
7780
}
7881
}
7982

@@ -146,6 +149,14 @@ public enum SPAlertPreset {
146149
layout.iconHeight = 90
147150
layout.bottomIconSpace = 36
148151
return layout
152+
case .bolt:
153+
var layout = SPAlertLayout()
154+
layout.topSpace = 45
155+
layout.bottomSpace = 27
156+
layout.iconWidth = 116
157+
layout.iconHeight = 116
158+
layout.bottomIconSpace = 34
159+
return layout
149160
case .moon:
150161
var layout = SPAlertLayout()
151162
layout.topSpace = 49
@@ -230,6 +241,8 @@ public enum SPAlertPreset {
230241
return .success
231242
case .flag:
232243
return .success
244+
case .bolt:
245+
return .success
233246
}
234247
}
235248
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2019 Ivan Vorobei (ivanvorobei@icloud.com)
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 SPAlertIconBoltView: 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+
BoltDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class BoltDraw: 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: 47, height: 71), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 47, y: resizedFrame.height / 71)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 4.16, y: 42.19))
50+
bezierPath.addCurve(to: CGPoint(x: 2, y: 40.16), controlPoint1: CGPoint(x: 2.9, y: 42.19), controlPoint2: CGPoint(x: 2, y: 41.33))
51+
bezierPath.addCurve(to: CGPoint(x: 2.81, y: 38.24), controlPoint1: CGPoint(x: 2, y: 39.5), controlPoint2: CGPoint(x: 2.3, y: 38.9))
52+
bezierPath.addLine(to: CGPoint(x: 30, y: 4.25))
53+
bezierPath.addCurve(to: CGPoint(x: 34.07, y: 6.44), controlPoint1: CGPoint(x: 32.04, y: 1.71), controlPoint2: CGPoint(x: 35.21, y: 3.35))
54+
bezierPath.addLine(to: CGPoint(x: 25.12, y: 30.69))
55+
bezierPath.addLine(to: CGPoint(x: 42.07, y: 30.69))
56+
bezierPath.addCurve(to: CGPoint(x: 44.2, y: 32.73), controlPoint1: CGPoint(x: 43.33, y: 30.69), controlPoint2: CGPoint(x: 44.2, y: 31.59))
57+
bezierPath.addCurve(to: CGPoint(x: 43.42, y: 34.65), controlPoint1: CGPoint(x: 44.2, y: 33.42), controlPoint2: CGPoint(x: 43.93, y: 34.02))
58+
bezierPath.addLine(to: CGPoint(x: 16.23, y: 68.67))
59+
bezierPath.addCurve(to: CGPoint(x: 12.15, y: 66.45), controlPoint1: CGPoint(x: 14.19, y: 71.18), controlPoint2: CGPoint(x: 10.98, y: 69.54))
60+
bezierPath.addLine(to: CGPoint(x: 21.11, y: 42.19))
61+
bezierPath.addLine(to: CGPoint(x: 4.16, y: 42.19))
62+
bezierPath.close()
63+
fillColor.setFill()
64+
bezierPath.fill()
65+
context.restoreGState()
66+
}
67+
68+
@objc(StyleKitNameResizingBehavior)
69+
public enum ResizingBehavior: Int {
70+
71+
case aspectFit
72+
case aspectFill
73+
case stretch
74+
case center
75+
76+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
77+
if rect == target || target == CGRect.zero {
78+
return rect
79+
}
80+
81+
var scales = CGSize.zero
82+
scales.width = abs(target.width / rect.width)
83+
scales.height = abs(target.height / rect.height)
84+
85+
switch self {
86+
case .aspectFit:
87+
scales.width = min(scales.width, scales.height)
88+
scales.height = scales.width
89+
case .aspectFill:
90+
scales.width = max(scales.width, scales.height)
91+
scales.height = scales.width
92+
case .stretch:
93+
break
94+
case .center:
95+
scales.width = 1
96+
scales.height = 1
97+
}
98+
99+
var result = rect.standardized
100+
result.size.width *= scales.width
101+
result.size.height *= scales.height
102+
result.origin.x = target.minX + (target.width - result.width) / 2
103+
result.origin.y = target.minY + (target.height - result.height) / 2
104+
return result
105+
}
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)