Skip to content

Commit cce2967

Browse files
committed
Add .eject preset
1 parent 9e651c3 commit cce2967

File tree

8 files changed

+148
-3
lines changed

8 files changed

+148
-3
lines changed

Assets/Readme/Miniature - Eject.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

6.97 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ViewController: UITableViewController {
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"),
1717
Alert(key: "Bolt", preset: .bolt, title: "Power", subtitle: "Now turned on"),
18+
Alert(key: "Eject", preset: .eject, title: "Eject complete", subtitle: nil),
1819
Alert(key: "Magic", preset: .magic, title: "Magic here! You see", subtitle: "Strange text, true?"),
1920
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
2021
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
@@ -20,6 +20,7 @@ And other
2020
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Question.svg" width="55">
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">
23+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Eject.svg" width="55">
2324
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Magic.svg" width="55">
2425
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2526
<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.18"
4+
s.version = "2.0.19"
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
@@ -33,6 +33,7 @@
3333
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */; };
3434
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CA67B4238ABD0100E72F79 /* SPAlertIconAddView.swift */; };
3535
F4CD29F423A037D00051EA23 /* SPAlertIconMagicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CD29F323A037D00051EA23 /* SPAlertIconMagicView.swift */; };
36+
F4D1623423A2E47200B5E3E9 /* SPAlertIconEjectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D1623323A2E47200B5E3E9 /* SPAlertIconEjectView.swift */; };
3637
F4D3CD58238DA9FE006C3DE2 /* SPAlertIconMoonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D3CD57238DA9FE006C3DE2 /* SPAlertIconMoonView.swift */; };
3738
F4D3CD5A238DAA49006C3DE2 /* SPAlertIconStarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D3CD59238DAA49006C3DE2 /* SPAlertIconStarView.swift */; };
3839
F4E4459D2390524A0067FF5C /* SPAlertIconExclamationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E4459C2390524A0067FF5C /* SPAlertIconExclamationView.swift */; };
@@ -97,6 +98,7 @@
9798
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconDocView.swift; sourceTree = "<group>"; };
9899
F4CA67B4238ABD0100E72F79 /* SPAlertIconAddView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAddView.swift; sourceTree = "<group>"; };
99100
F4CD29F323A037D00051EA23 /* SPAlertIconMagicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMagicView.swift; sourceTree = "<group>"; };
101+
F4D1623323A2E47200B5E3E9 /* SPAlertIconEjectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconEjectView.swift; sourceTree = "<group>"; };
100102
F4D3CD57238DA9FE006C3DE2 /* SPAlertIconMoonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMoonView.swift; sourceTree = "<group>"; };
101103
F4D3CD59238DAA49006C3DE2 /* SPAlertIconStarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconStarView.swift; sourceTree = "<group>"; };
102104
F4E4459C2390524A0067FF5C /* SPAlertIconExclamationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconExclamationView.swift; sourceTree = "<group>"; };
@@ -193,6 +195,7 @@
193195
F40FB629239ADF940090BA57 /* SPAlertIconQuestionView.swift */,
194196
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */,
195197
F4CD29F323A037D00051EA23 /* SPAlertIconMagicView.swift */,
198+
F4D1623323A2E47200B5E3E9 /* SPAlertIconEjectView.swift */,
196199
);
197200
path = Icons;
198201
sourceTree = "<group>";
@@ -404,6 +407,7 @@
404407
F47EE19F23959AE500B02DF2 /* SPAlertIconRepeatView.swift in Sources */,
405408
706F894A2383277500ECF5D1 /* SPAlertIconErrorView.swift in Sources */,
406409
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */,
410+
F4D1623423A2E47200B5E3E9 /* SPAlertIconEjectView.swift in Sources */,
407411
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */,
408412
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */,
409413
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public enum SPAlertPreset {
4242
case shuffle
4343
case `repeat`
4444
case magic
45+
case eject
4546

4647
/**
47-
View for preset.
48+
View for preset. Wrap to `UIView`.
4849
*/
4950
var iconView: UIView {
5051
switch self {
@@ -80,11 +81,14 @@ public enum SPAlertPreset {
8081
return SPAlertIconBoltView()
8182
case .magic:
8283
return SPAlertIconMagicView()
84+
case .eject:
85+
return SPAlertIconEjectView()
8386
}
8487
}
8588

8689
/**
8790
Layout for preset. Include spacings and icon size.
91+
Size of frame `250` to `250`, it fix size. Not using proportional. Set fix in points.
8892
*/
8993
var layout: SPAlertLayout {
9094
switch self {
@@ -136,6 +140,14 @@ public enum SPAlertPreset {
136140
layout.iconHeight = 77
137141
layout.bottomIconSpace = 35
138142
return layout
143+
case .eject:
144+
var layout = SPAlertLayout()
145+
layout.topSpace = 48
146+
layout.bottomSpace = 31
147+
layout.iconWidth = 112
148+
layout.iconHeight = 77
149+
layout.bottomIconSpace = 32
150+
return layout
139151
case .flag:
140152
var layout = SPAlertLayout()
141153
layout.topSpace = 49
@@ -220,7 +232,7 @@ public enum SPAlertPreset {
220232
}
221233

222234
/**
223-
Default vibro. Can customize after create with preset.
235+
Default haptic. Can customize after create with preset.
224236
*/
225237
var haptic: SPAlertHaptic {
226238
switch self {
@@ -250,6 +262,8 @@ public enum SPAlertPreset {
250262
return .error
251263
case .shuffle:
252264
return .success
265+
case .eject:
266+
return .warning
253267
case .repeat:
254268
return .success
255269
case .flag:
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 SPAlertIconEjectView: 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+
EjectDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class EjectDraw: 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: 60, height: 60), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 60, y: resizedFrame.height / 60)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 52.91, y: 34.64))
50+
bezierPath.addCurve(to: CGPoint(x: 57.54, y: 30.39), controlPoint1: CGPoint(x: 55.73, y: 34.64), controlPoint2: CGPoint(x: 57.54, y: 32.88))
51+
bezierPath.addCurve(to: CGPoint(x: 56.01, y: 26.96), controlPoint1: CGPoint(x: 57.54, y: 29.26), controlPoint2: CGPoint(x: 56.98, y: 27.98))
52+
bezierPath.addLine(to: CGPoint(x: 34.16, y: 4.58))
53+
bezierPath.addCurve(to: CGPoint(x: 29.33, y: 2), controlPoint1: CGPoint(x: 32.35, y: 2.88), controlPoint2: CGPoint(x: 31.06, y: 2))
54+
bezierPath.addCurve(to: CGPoint(x: 24.53, y: 4.58), controlPoint1: CGPoint(x: 27.63, y: 2), controlPoint2: CGPoint(x: 26.28, y: 2.91))
55+
bezierPath.addLine(to: CGPoint(x: 2.85, y: 26.76))
56+
bezierPath.addCurve(to: CGPoint(x: 1.12, y: 30.39), controlPoint1: CGPoint(x: 1.76, y: 27.81), controlPoint2: CGPoint(x: 1.09, y: 29.19))
57+
bezierPath.addCurve(to: CGPoint(x: 5.75, y: 34.64), controlPoint1: CGPoint(x: 1.12, y: 32.88), controlPoint2: CGPoint(x: 2.93, y: 34.64))
58+
bezierPath.addLine(to: CGPoint(x: 52.91, y: 34.64))
59+
bezierPath.close()
60+
bezierPath.move(to: CGPoint(x: 51.86, y: 40.73))
61+
bezierPath.addCurve(to: CGPoint(x: 57.69, y: 46.41), controlPoint1: CGPoint(x: 55.49, y: 40.73), controlPoint2: CGPoint(x: 57.69, y: 42.87))
62+
bezierPath.addLine(to: CGPoint(x: 57.69, y: 52.42))
63+
bezierPath.addCurve(to: CGPoint(x: 51.86, y: 58.13), controlPoint1: CGPoint(x: 57.69, y: 56.11), controlPoint2: CGPoint(x: 55.49, y: 58.13))
64+
bezierPath.addLine(to: CGPoint(x: 6.86, y: 58.13))
65+
bezierPath.addCurve(to: CGPoint(x: 1, y: 52.42), controlPoint1: CGPoint(x: 3.23, y: 58.13), controlPoint2: CGPoint(x: 1, y: 56.08))
66+
bezierPath.addLine(to: CGPoint(x: 1, y: 46.41))
67+
bezierPath.addCurve(to: CGPoint(x: 6.86, y: 40.73), controlPoint1: CGPoint(x: 1, y: 42.87), controlPoint2: CGPoint(x: 3.23, y: 40.73))
68+
bezierPath.addLine(to: CGPoint(x: 51.86, y: 40.73))
69+
bezierPath.close()
70+
fillColor.setFill()
71+
bezierPath.fill()
72+
context.restoreGState()
73+
}
74+
75+
@objc(StyleKitNameResizingBehavior)
76+
public enum ResizingBehavior: Int {
77+
78+
case aspectFit
79+
case aspectFill
80+
case stretch
81+
case center
82+
83+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
84+
if rect == target || target == CGRect.zero {
85+
return rect
86+
}
87+
88+
var scales = CGSize.zero
89+
scales.width = abs(target.width / rect.width)
90+
scales.height = abs(target.height / rect.height)
91+
92+
switch self {
93+
case .aspectFit:
94+
scales.width = min(scales.width, scales.height)
95+
scales.height = scales.width
96+
case .aspectFill:
97+
scales.width = max(scales.width, scales.height)
98+
scales.height = scales.width
99+
case .stretch:
100+
break
101+
case .center:
102+
scales.width = 1
103+
scales.height = 1
104+
}
105+
106+
var result = rect.standardized
107+
result.size.width *= scales.width
108+
result.size.height *= scales.height
109+
result.origin.x = target.minX + (target.width - result.width) / 2
110+
result.origin.y = target.minY + (target.height - result.height) / 2
111+
return result
112+
}
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)