Skip to content

Commit 293002f

Browse files
committed
Add .question preset
1 parent 76d3230 commit 293002f

File tree

9 files changed

+159
-2
lines changed

9 files changed

+159
-2
lines changed
Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

3.59 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ViewController: UITableViewController {
1212
Alert(key: "Star", preset: .star, title: "Added to favorite", subtitle: nil),
1313
Alert(key: "Flag", preset: .flag, title: "Message Flaged", subtitle: nil),
1414
Alert(key: "Exclamation", preset: .exclamation, title: "Oops", subtitle: "Something went wrong"),
15+
Alert(key: "Question", preset: .question, title: "Oops", subtitle: "Form not complete"),
1516
Alert(key: "Message", preset: .message, title: "Message sended", subtitle: "You can check history"),
1617
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
1718
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
@@ -18,6 +18,7 @@ And other
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">
2020
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
21+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Question.svg" width="55">
2122
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2223
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="55">
2324
<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.12"
4+
s.version = "2.0.14"
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
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
706F894A2383277500ECF5D1 /* SPAlertIconErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706F89492383277500ECF5D1 /* SPAlertIconErrorView.swift */; };
11+
F40FB62A239ADF940090BA57 /* SPAlertIconQuestionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40FB629239ADF940090BA57 /* SPAlertIconQuestionView.swift */; };
1112
F41204E92382AC9B009C2AC7 /* SPAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204DF2382AC9B009C2AC7 /* SPAlertView.swift */; };
1213
F41204EA2382AC9B009C2AC7 /* SPAlertPreset.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204E02382AC9B009C2AC7 /* SPAlertPreset.swift */; };
1314
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204E22382AC9B009C2AC7 /* SPAlertIconHeartView.swift */; };
@@ -61,6 +62,7 @@
6162

6263
/* Begin PBXFileReference section */
6364
706F89492383277500ECF5D1 /* SPAlertIconErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconErrorView.swift; sourceTree = "<group>"; };
65+
F40FB629239ADF940090BA57 /* SPAlertIconQuestionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconQuestionView.swift; sourceTree = "<group>"; };
6466
F41204D02382ABE9009C2AC7 /* SPAlert.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SPAlert.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6567
F41204DF2382AC9B009C2AC7 /* SPAlertView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SPAlertView.swift; sourceTree = "<group>"; };
6668
F41204E02382AC9B009C2AC7 /* SPAlertPreset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SPAlertPreset.swift; sourceTree = "<group>"; };
@@ -184,6 +186,7 @@
184186
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */,
185187
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */,
186188
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */,
189+
F40FB629239ADF940090BA57 /* SPAlertIconQuestionView.swift */,
187190
);
188191
path = Icons;
189192
sourceTree = "<group>";
@@ -381,6 +384,7 @@
381384
files = (
382385
F412052A2382AF64009C2AC7 /* SPAlertHaptic.swift in Sources */,
383386
F41204EE2382AC9B009C2AC7 /* SPAlert.swift in Sources */,
387+
F40FB62A239ADF940090BA57 /* SPAlertIconQuestionView.swift in Sources */,
384388
F4E4459D2390524A0067FF5C /* SPAlertIconExclamationView.swift in Sources */,
385389
F41204EA2382AC9B009C2AC7 /* SPAlertPreset.swift in Sources */,
386390
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */,

Source/SPAlert/Models/SPAlertLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import UIKit
2323

2424
/**
25-
Layout for alert.
25+
Layout for alert. Basic width is `250`. Height calculate automatically.
2626
*/
2727
public struct SPAlertLayout {
2828

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum SPAlertPreset {
3535
case exclamation
3636
case flag
3737
case message
38+
case question
3839
case add
3940
case error
4041
case shuffle
@@ -71,6 +72,8 @@ public enum SPAlertPreset {
7172
return SPAlertIconRepeatView()
7273
case .flag:
7374
return SPAlertIconFlagView()
75+
case .question:
76+
return SPAlertIconQuestionView()
7477
}
7578
}
7679

@@ -111,6 +114,14 @@ public enum SPAlertPreset {
111114
layout.iconHeight = 90
112115
layout.bottomIconSpace = 31
113116
return layout
117+
case .question:
118+
var layout = SPAlertLayout()
119+
layout.topSpace = 46
120+
layout.bottomSpace = 33
121+
layout.iconWidth = 112
122+
layout.iconHeight = 102
123+
layout.bottomIconSpace = 31
124+
return layout
114125
case .doc:
115126
var layout = SPAlertLayout()
116127
layout.topSpace = 49
@@ -209,6 +220,8 @@ public enum SPAlertPreset {
209220
return .success
210221
case .exclamation:
211222
return .warning
223+
case .question:
224+
return .warning
212225
case .error:
213226
return .error
214227
case .shuffle:
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 (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 SPAlertIconQuestionView: 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+
QuestionDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class QuestionDraw: 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: 76, height: 74), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 76, y: resizedFrame.height / 74)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 30.56, y: 68.4))
50+
bezierPath.addCurve(to: CGPoint(x: 43.85, y: 68.34), controlPoint1: CGPoint(x: 34.48, y: 72.31), controlPoint2: CGPoint(x: 39.94, y: 72.25))
51+
bezierPath.addLine(to: CGPoint(x: 68.34, y: 43.85))
52+
bezierPath.addCurve(to: CGPoint(x: 68.4, y: 30.56), controlPoint1: CGPoint(x: 72.25, y: 39.94), controlPoint2: CGPoint(x: 72.31, y: 34.45))
53+
bezierPath.addLine(to: CGPoint(x: 43.73, y: 5.86))
54+
bezierPath.addCurve(to: CGPoint(x: 30.44, y: 5.99), controlPoint1: CGPoint(x: 39.81, y: 1.98), controlPoint2: CGPoint(x: 34.36, y: 2.07))
55+
bezierPath.addLine(to: CGPoint(x: 5.99, y: 30.44))
56+
bezierPath.addCurve(to: CGPoint(x: 5.86, y: 43.73), controlPoint1: CGPoint(x: 2.07, y: 34.36), controlPoint2: CGPoint(x: 1.98, y: 39.81))
57+
bezierPath.addLine(to: CGPoint(x: 30.56, y: 68.4))
58+
bezierPath.close()
59+
bezierPath.move(to: CGPoint(x: 36.21, y: 45.43))
60+
bezierPath.addCurve(to: CGPoint(x: 33.62, y: 42.9), controlPoint1: CGPoint(x: 34.54, y: 45.43), controlPoint2: CGPoint(x: 33.62, y: 44.56))
61+
bezierPath.addLine(to: CGPoint(x: 33.62, y: 42.47))
62+
bezierPath.addCurve(to: CGPoint(x: 37.66, y: 35.96), controlPoint1: CGPoint(x: 33.62, y: 39.29), controlPoint2: CGPoint(x: 35.34, y: 37.56))
63+
bezierPath.addLine(to: CGPoint(x: 38.47, y: 35.4))
64+
bezierPath.addCurve(to: CGPoint(x: 41.88, y: 30.69), controlPoint1: CGPoint(x: 40.78, y: 33.78), controlPoint2: CGPoint(x: 41.88, y: 32.69))
65+
bezierPath.addCurve(to: CGPoint(x: 37.01, y: 26.59), controlPoint1: CGPoint(x: 41.88, y: 28.25), controlPoint2: CGPoint(x: 39.97, y: 26.59))
66+
bezierPath.addCurve(to: CGPoint(x: 32.23, y: 29.42), controlPoint1: CGPoint(x: 34.85, y: 26.59), controlPoint2: CGPoint(x: 33.22, y: 27.67))
67+
bezierPath.addCurve(to: CGPoint(x: 29.05, y: 31.61), controlPoint1: CGPoint(x: 31.18, y: 30.66), controlPoint2: CGPoint(x: 30.9, y: 31.61))
68+
bezierPath.addCurve(to: CGPoint(x: 26.83, y: 29.39), controlPoint1: CGPoint(x: 27.97, y: 31.61), controlPoint2: CGPoint(x: 26.83, y: 30.84))
69+
bezierPath.addCurve(to: CGPoint(x: 27.08, y: 27.79), controlPoint1: CGPoint(x: 26.83, y: 28.84), controlPoint2: CGPoint(x: 26.92, y: 28.31))
70+
bezierPath.addCurve(to: CGPoint(x: 37.19, y: 22.18), controlPoint1: CGPoint(x: 27.91, y: 24.8), controlPoint2: CGPoint(x: 31.64, y: 22.18))
71+
bezierPath.addCurve(to: CGPoint(x: 47.49, y: 30.44), controlPoint1: CGPoint(x: 42.71, y: 22.18), controlPoint2: CGPoint(x: 47.49, y: 25.07))
72+
bezierPath.addCurve(to: CGPoint(x: 42.13, y: 38.3), controlPoint1: CGPoint(x: 47.49, y: 34.33), controlPoint2: CGPoint(x: 45.24, y: 36.18))
73+
bezierPath.addCurve(to: CGPoint(x: 38.8, y: 42.74), controlPoint1: CGPoint(x: 39.88, y: 39.81), controlPoint2: CGPoint(x: 38.8, y: 40.92))
74+
bezierPath.addLine(to: CGPoint(x: 38.8, y: 43.14))
75+
bezierPath.addCurve(to: CGPoint(x: 36.21, y: 45.43), controlPoint1: CGPoint(x: 38.8, y: 44.41), controlPoint2: CGPoint(x: 37.84, y: 45.43))
76+
bezierPath.close()
77+
bezierPath.move(to: CGPoint(x: 36.33, y: 54.71))
78+
bezierPath.addCurve(to: CGPoint(x: 32.85, y: 51.38), controlPoint1: CGPoint(x: 34.54, y: 54.71), controlPoint2: CGPoint(x: 32.85, y: 53.29))
79+
bezierPath.addCurve(to: CGPoint(x: 36.33, y: 48.05), controlPoint1: CGPoint(x: 32.85, y: 49.47), controlPoint2: CGPoint(x: 34.51, y: 48.05))
80+
bezierPath.addCurve(to: CGPoint(x: 39.78, y: 51.38), controlPoint1: CGPoint(x: 38.12, y: 48.05), controlPoint2: CGPoint(x: 39.78, y: 49.43))
81+
bezierPath.addCurve(to: CGPoint(x: 36.33, y: 54.71), controlPoint1: CGPoint(x: 39.78, y: 53.32), controlPoint2: CGPoint(x: 38.09, y: 54.71))
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)