Skip to content

Commit c6f83a2

Browse files
committed
Add .shuffle and .repeat presets
1 parent 99ad55d commit c6f83a2

File tree

11 files changed

+333
-3
lines changed

11 files changed

+333
-3
lines changed

Assets/Readme/Miniature - Repeat.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Readme/Miniature - Shuffle.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

7.77 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class ViewController: UITableViewController {
1414
Alert(key: "Message", preset: .message, title: "Message sended", subtitle: "You can check history"),
1515
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
1616
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),
17+
Alert(key: "Shuffle", preset: .shuffle, title: "Songs Shuffled", subtitle: nil),
18+
Alert(key: "Repeat", preset: .repeat, title: "Songs Repeat", subtitle: nil),
1719
Alert(key: "Message", preset: nil, title: nil, subtitle: "Email required")
1820
]
1921

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ And other
1919
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
2020
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2121
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="55">
22+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Shuffle.svg" width="55">
23+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Repeat.svg" width="55">
2224
</p>
2325

2426
If you like the project, do not forget to `put star ★` and follow me on GitHub. For help project, see [Сooperation](#сooperation) section.

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.10"
4+
s.version = "2.0.11"
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
F412052A2382AF64009C2AC7 /* SPAlertHaptic.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204E42382AC9B009C2AC7 /* SPAlertHaptic.swift */; };
2525
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */; };
2626
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
27+
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
28+
F47EE19F23959AE500B02DF2 /* SPAlertIconRepeatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */; };
2729
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */; };
2830
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */; };
2931
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CA67B4238ABD0100E72F79 /* SPAlertIconAddView.swift */; };
@@ -82,6 +84,8 @@
8284
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
8385
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
8486
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
87+
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
88+
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRepeatView.swift; sourceTree = "<group>"; };
8589
F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBookmarkView.swift; sourceTree = "<group>"; };
8690
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconDocView.swift; sourceTree = "<group>"; };
8791
F4CA67B4238ABD0100E72F79 /* SPAlertIconAddView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAddView.swift; sourceTree = "<group>"; };
@@ -175,6 +179,8 @@
175179
F4D3CD59238DAA49006C3DE2 /* SPAlertIconStarView.swift */,
176180
F4E4459C2390524A0067FF5C /* SPAlertIconExclamationView.swift */,
177181
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */,
182+
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */,
183+
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */,
178184
);
179185
path = Icons;
180186
sourceTree = "<group>";
@@ -377,8 +383,10 @@
377383
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */,
378384
F41204EC2382AC9B009C2AC7 /* SPAlertIconDoneView.swift in Sources */,
379385
F41204E92382AC9B009C2AC7 /* SPAlertView.swift in Sources */,
386+
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */,
380387
F4D3CD58238DA9FE006C3DE2 /* SPAlertIconMoonView.swift in Sources */,
381388
F4D3CD5A238DAA49006C3DE2 /* SPAlertIconStarView.swift in Sources */,
389+
F47EE19F23959AE500B02DF2 /* SPAlertIconRepeatView.swift in Sources */,
382390
706F894A2383277500ECF5D1 /* SPAlertIconErrorView.swift in Sources */,
383391
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */,
384392
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public enum SPAlertPreset {
3636
case message
3737
case add
3838
case error
39+
case shuffle
40+
case `repeat`
3941

4042
/**
4143
View for preset.
@@ -62,6 +64,10 @@ public enum SPAlertPreset {
6264
return SPAlertIconStarView()
6365
case .error:
6466
return SPAlertIconErrorView()
67+
case .shuffle:
68+
return SPAlertIconShuffleView()
69+
case .repeat:
70+
return SPAlertIconRepeatView()
6571
}
6672
}
6773

@@ -150,6 +156,22 @@ public enum SPAlertPreset {
150156
layout.iconHeight = 100
151157
layout.bottomIconSpace = 37
152158
return layout
159+
case .shuffle:
160+
var layout = SPAlertLayout()
161+
layout.topSpace = 63
162+
layout.bottomSpace = 29
163+
layout.iconWidth = 86
164+
layout.iconHeight = 86
165+
layout.bottomIconSpace = 39
166+
return layout
167+
case .repeat:
168+
var layout = SPAlertLayout()
169+
layout.topSpace = 63
170+
layout.bottomSpace = 29
171+
layout.iconWidth = 86
172+
layout.iconHeight = 86
173+
layout.bottomIconSpace = 39
174+
return layout
153175
}
154176
}
155177

@@ -178,6 +200,10 @@ public enum SPAlertPreset {
178200
return .warning
179201
case .error:
180202
return .error
203+
case .shuffle:
204+
return .success
205+
case .repeat:
206+
return .success
181207
}
182208
}
183209
}

Source/SPAlert/Views/Icons/SPAlertIconMessageView.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ public class SPAlertIconMessageView: UIView {
8787
bezierPath.close()
8888
fillColor.setFill()
8989
bezierPath.fill()
90-
9190
context.restoreGState()
92-
9391
}
9492

9593
@objc(StyleKitNameResizingBehavior)
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 SPAlertIconRepeatView: 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+
ShuffleDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class ShuffleDraw: 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: 73, height: 64), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 73, y: resizedFrame.height / 64)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 1, y: 29.76))
50+
bezierPath.addCurve(to: CGPoint(x: 4.49, y: 33.25), controlPoint1: CGPoint(x: 1, y: 31.69), controlPoint2: CGPoint(x: 2.56, y: 33.25))
51+
bezierPath.addCurve(to: CGPoint(x: 7.98, y: 29.76), controlPoint1: CGPoint(x: 6.43, y: 33.25), controlPoint2: CGPoint(x: 7.98, y: 31.69))
52+
bezierPath.addLine(to: CGPoint(x: 7.98, y: 27.66))
53+
bezierPath.addCurve(to: CGPoint(x: 16.68, y: 19.28), controlPoint1: CGPoint(x: 7.98, y: 22.61), controlPoint2: CGPoint(x: 11.47, y: 19.28))
54+
bezierPath.addLine(to: CGPoint(x: 40.61, y: 19.28))
55+
bezierPath.addLine(to: CGPoint(x: 40.61, y: 25.92))
56+
bezierPath.addCurve(to: CGPoint(x: 43.47, y: 28.71), controlPoint1: CGPoint(x: 40.61, y: 27.63), controlPoint2: CGPoint(x: 41.72, y: 28.71))
57+
bezierPath.addCurve(to: CGPoint(x: 45.62, y: 27.91), controlPoint1: CGPoint(x: 44.23, y: 28.71), controlPoint2: CGPoint(x: 45.02, y: 28.42))
58+
bezierPath.addLine(to: CGPoint(x: 57.62, y: 18.01))
59+
bezierPath.addCurve(to: CGPoint(x: 57.62, y: 13.76), controlPoint1: CGPoint(x: 59.05, y: 16.87), controlPoint2: CGPoint(x: 59.02, y: 14.97))
60+
bezierPath.addLine(to: CGPoint(x: 45.62, y: 3.79))
61+
bezierPath.addCurve(to: CGPoint(x: 43.47, y: 3), controlPoint1: CGPoint(x: 45.02, y: 3.32), controlPoint2: CGPoint(x: 44.23, y: 3))
62+
bezierPath.addCurve(to: CGPoint(x: 40.61, y: 5.82), controlPoint1: CGPoint(x: 41.72, y: 3), controlPoint2: CGPoint(x: 40.61, y: 4.11))
63+
bezierPath.addLine(to: CGPoint(x: 40.61, y: 12.39))
64+
bezierPath.addLine(to: CGPoint(x: 17.35, y: 12.39))
65+
bezierPath.addCurve(to: CGPoint(x: 1, y: 27.15), controlPoint1: CGPoint(x: 7.35, y: 12.39), controlPoint2: CGPoint(x: 1, y: 18.14))
66+
bezierPath.addLine(to: CGPoint(x: 1, y: 29.76))
67+
bezierPath.close()
68+
bezierPath.move(to: CGPoint(x: 30.74, y: 38.26))
69+
bezierPath.addLine(to: CGPoint(x: 30.74, y: 44.83))
70+
bezierPath.addLine(to: CGPoint(x: 54.67, y: 44.83))
71+
bezierPath.addCurve(to: CGPoint(x: 63.37, y: 36.45), controlPoint1: CGPoint(x: 59.87, y: 44.83), controlPoint2: CGPoint(x: 63.37, y: 41.47))
72+
bezierPath.addLine(to: CGPoint(x: 63.37, y: 34.36))
73+
bezierPath.addCurve(to: CGPoint(x: 66.86, y: 30.83), controlPoint1: CGPoint(x: 63.37, y: 32.39), controlPoint2: CGPoint(x: 64.92, y: 30.83))
74+
bezierPath.addCurve(to: CGPoint(x: 70.35, y: 34.36), controlPoint1: CGPoint(x: 68.79, y: 30.83), controlPoint2: CGPoint(x: 70.35, y: 32.39))
75+
bezierPath.addLine(to: CGPoint(x: 70.35, y: 36.96))
76+
bezierPath.addCurve(to: CGPoint(x: 54, y: 51.72), controlPoint1: CGPoint(x: 70.35, y: 45.94), controlPoint2: CGPoint(x: 64, y: 51.72))
77+
bezierPath.addLine(to: CGPoint(x: 30.74, y: 51.72))
78+
bezierPath.addLine(to: CGPoint(x: 30.74, y: 58.35))
79+
bezierPath.addCurve(to: CGPoint(x: 27.88, y: 61.14), controlPoint1: CGPoint(x: 30.74, y: 60.07), controlPoint2: CGPoint(x: 29.66, y: 61.14))
80+
bezierPath.addCurve(to: CGPoint(x: 25.92, y: 60.48), controlPoint1: CGPoint(x: 27.19, y: 61.14), controlPoint2: CGPoint(x: 26.47, y: 60.91))
81+
bezierPath.addLine(to: CGPoint(x: 13.76, y: 50.39))
82+
bezierPath.addCurve(to: CGPoint(x: 13.76, y: 46.13), controlPoint1: CGPoint(x: 12.3, y: 49.18), controlPoint2: CGPoint(x: 12.33, y: 47.31))
83+
bezierPath.addLine(to: CGPoint(x: 25.76, y: 36.23))
84+
bezierPath.addCurve(to: CGPoint(x: 27.88, y: 35.47), controlPoint1: CGPoint(x: 26.33, y: 35.75), controlPoint2: CGPoint(x: 27.12, y: 35.47))
85+
bezierPath.addCurve(to: CGPoint(x: 30.74, y: 38.26), controlPoint1: CGPoint(x: 29.66, y: 35.47), controlPoint2: CGPoint(x: 30.74, y: 36.55))
86+
bezierPath.close()
87+
fillColor.setFill()
88+
bezierPath.fill()
89+
context.restoreGState()
90+
}
91+
92+
@objc(StyleKitNameResizingBehavior)
93+
public enum ResizingBehavior: Int {
94+
95+
case aspectFit
96+
case aspectFill
97+
case stretch
98+
case center
99+
100+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
101+
if rect == target || target == CGRect.zero {
102+
return rect
103+
}
104+
105+
var scales = CGSize.zero
106+
scales.width = abs(target.width / rect.width)
107+
scales.height = abs(target.height / rect.height)
108+
109+
switch self {
110+
case .aspectFit:
111+
scales.width = min(scales.width, scales.height)
112+
scales.height = scales.width
113+
case .aspectFill:
114+
scales.width = max(scales.width, scales.height)
115+
scales.height = scales.width
116+
case .stretch:
117+
break
118+
case .center:
119+
scales.width = 1
120+
scales.height = 1
121+
}
122+
123+
var result = rect.standardized
124+
result.size.width *= scales.width
125+
result.size.height *= scales.height
126+
result.origin.x = target.minX + (target.width - result.width) / 2
127+
result.origin.y = target.minY + (target.height - result.height) / 2
128+
return result
129+
}
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)