Skip to content

Commit d6d8b1c

Browse files
committed
Add .message preset
1 parent 5bc1b57 commit d6d8b1c

File tree

8 files changed

+165
-1
lines changed

8 files changed

+165
-1
lines changed

Assets/Readme/Miniature - Message.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

2.59 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ViewController: UITableViewController {
1111
Alert(key: "Moon", preset: .moon, title: "Night Mode", subtitle: "You can disable it in settings"),
1212
Alert(key: "Star", preset: .star, title: "Added to favorite", subtitle: nil),
1313
Alert(key: "Exclamation", preset: .exclamation, title: "Oops", subtitle: "Something went wrong"),
14+
Alert(key: "Message", preset: .message, title: "Message sended", subtitle: "You can check history"),
1415
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
1516
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),
1617
Alert(key: "Message", preset: nil, title: nil, subtitle: "Email required")

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ And other
1616
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Moon.svg" width="55">
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-%20Exclamation.svg" width="55">
19+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
1920
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2021
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="55">
2122
</p>

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.8"
4+
s.version = "2.0.10"
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
@@ -23,6 +23,7 @@
2323
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */; };
2424
F412052A2382AF64009C2AC7 /* SPAlertHaptic.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204E42382AC9B009C2AC7 /* SPAlertHaptic.swift */; };
2525
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */; };
26+
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
2627
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */; };
2728
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */; };
2829
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4CA67B4238ABD0100E72F79 /* SPAlertIconAddView.swift */; };
@@ -80,6 +81,7 @@
8081
F41205182382AD8B009C2AC7 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
8182
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
8283
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
84+
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
8385
F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBookmarkView.swift; sourceTree = "<group>"; };
8486
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconDocView.swift; sourceTree = "<group>"; };
8587
F4CA67B4238ABD0100E72F79 /* SPAlertIconAddView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAddView.swift; sourceTree = "<group>"; };
@@ -172,6 +174,7 @@
172174
F4D3CD57238DA9FE006C3DE2 /* SPAlertIconMoonView.swift */,
173175
F4D3CD59238DAA49006C3DE2 /* SPAlertIconStarView.swift */,
174176
F4E4459C2390524A0067FF5C /* SPAlertIconExclamationView.swift */,
177+
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */,
175178
);
176179
path = Icons;
177180
sourceTree = "<group>";
@@ -378,6 +381,7 @@
378381
F4D3CD5A238DAA49006C3DE2 /* SPAlertIconStarView.swift in Sources */,
379382
706F894A2383277500ECF5D1 /* SPAlertIconErrorView.swift in Sources */,
380383
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */,
384+
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */,
381385
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */,
382386
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */,
383387
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum SPAlertPreset {
3333
case moon
3434
case star
3535
case exclamation
36+
case message
3637
case add
3738
case error
3839

@@ -53,6 +54,8 @@ public enum SPAlertPreset {
5354
return SPAlertIconAddView()
5455
case .moon:
5556
return SPAlertIconMoonView()
57+
case .message:
58+
return SPAlertIconMessageView()
5659
case .exclamation:
5760
return SPAlertIconExclamationView()
5861
case .star:
@@ -91,6 +94,14 @@ public enum SPAlertPreset {
9194
layout.iconHeight = 90
9295
layout.bottomIconSpace = 31
9396
return layout
97+
case .message:
98+
var layout = SPAlertLayout()
99+
layout.topSpace = 46
100+
layout.bottomSpace = 33
101+
layout.iconWidth = 112
102+
layout.iconHeight = 90
103+
layout.bottomIconSpace = 31
104+
return layout
94105
case .doc:
95106
var layout = SPAlertLayout()
96107
layout.topSpace = 49
@@ -153,6 +164,8 @@ public enum SPAlertPreset {
153164
return .success
154165
case .doc:
155166
return .success
167+
case .message:
168+
return .success
156169
case .bookmark:
157170
return .success
158171
case .add:
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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 SPAlertIconMessageView: 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+
MessageDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class MessageDraw: 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: 56), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 60, y: resizedFrame.height / 56)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 17.07, y: 54.63))
50+
bezierPath.addCurve(to: CGPoint(x: 19.56, y: 53.4), controlPoint1: CGPoint(x: 17.93, y: 54.63), controlPoint2: CGPoint(x: 18.6, y: 54.24))
51+
bezierPath.addLine(to: CGPoint(x: 29.14, y: 44.64))
52+
bezierPath.addLine(to: CGPoint(x: 46.29, y: 44.66))
53+
bezierPath.addCurve(to: CGPoint(x: 57.9, y: 33.05), controlPoint1: CGPoint(x: 53.85, y: 44.69), controlPoint2: CGPoint(x: 57.9, y: 40.48))
54+
bezierPath.addLine(to: CGPoint(x: 57.9, y: 13.62))
55+
bezierPath.addCurve(to: CGPoint(x: 46.29, y: 2), controlPoint1: CGPoint(x: 57.9, y: 6.19), controlPoint2: CGPoint(x: 53.85, y: 2))
56+
bezierPath.addLine(to: CGPoint(x: 13.62, y: 2))
57+
bezierPath.addCurve(to: CGPoint(x: 2, y: 13.62), controlPoint1: CGPoint(x: 6.06, y: 2), controlPoint2: CGPoint(x: 2, y: 6.16))
58+
bezierPath.addLine(to: CGPoint(x: 2, y: 33.05))
59+
bezierPath.addCurve(to: CGPoint(x: 13.62, y: 44.64), controlPoint1: CGPoint(x: 2, y: 40.5), controlPoint2: CGPoint(x: 6.06, y: 44.66))
60+
bezierPath.addLine(to: CGPoint(x: 14.81, y: 44.64))
61+
bezierPath.addLine(to: CGPoint(x: 14.81, y: 52.02))
62+
bezierPath.addCurve(to: CGPoint(x: 17.07, y: 54.63), controlPoint1: CGPoint(x: 14.81, y: 53.59), controlPoint2: CGPoint(x: 15.62, y: 54.63))
63+
bezierPath.close()
64+
bezierPath.move(to: CGPoint(x: 15.75, y: 16.2))
65+
bezierPath.addCurve(to: CGPoint(x: 14.12, y: 14.56), controlPoint1: CGPoint(x: 14.86, y: 16.2), controlPoint2: CGPoint(x: 14.12, y: 15.49))
66+
bezierPath.addCurve(to: CGPoint(x: 15.75, y: 12.98), controlPoint1: CGPoint(x: 14.12, y: 13.72), controlPoint2: CGPoint(x: 14.86, y: 12.98))
67+
bezierPath.addLine(to: CGPoint(x: 44.16, y: 12.98))
68+
bezierPath.addCurve(to: CGPoint(x: 45.78, y: 14.56), controlPoint1: CGPoint(x: 45.04, y: 12.98), controlPoint2: CGPoint(x: 45.78, y: 13.72))
69+
bezierPath.addCurve(to: CGPoint(x: 44.16, y: 16.2), controlPoint1: CGPoint(x: 45.78, y: 15.49), controlPoint2: CGPoint(x: 45.04, y: 16.2))
70+
bezierPath.addLine(to: CGPoint(x: 15.75, y: 16.2))
71+
bezierPath.close()
72+
bezierPath.move(to: CGPoint(x: 15.75, y: 25.29))
73+
bezierPath.addCurve(to: CGPoint(x: 14.12, y: 23.66), controlPoint1: CGPoint(x: 14.86, y: 25.29), controlPoint2: CGPoint(x: 14.12, y: 24.58))
74+
bezierPath.addCurve(to: CGPoint(x: 15.75, y: 22.06), controlPoint1: CGPoint(x: 14.12, y: 22.8), controlPoint2: CGPoint(x: 14.86, y: 22.06))
75+
bezierPath.addLine(to: CGPoint(x: 44.16, y: 22.06))
76+
bezierPath.addCurve(to: CGPoint(x: 45.78, y: 23.66), controlPoint1: CGPoint(x: 45.04, y: 22.06), controlPoint2: CGPoint(x: 45.78, y: 22.8))
77+
bezierPath.addCurve(to: CGPoint(x: 44.16, y: 25.29), controlPoint1: CGPoint(x: 45.78, y: 24.58), controlPoint2: CGPoint(x: 45.04, y: 25.29))
78+
bezierPath.addLine(to: CGPoint(x: 15.75, y: 25.29))
79+
bezierPath.close()
80+
bezierPath.move(to: CGPoint(x: 15.75, y: 34.39))
81+
bezierPath.addCurve(to: CGPoint(x: 14.12, y: 32.77), controlPoint1: CGPoint(x: 14.86, y: 34.39), controlPoint2: CGPoint(x: 14.12, y: 33.66))
82+
bezierPath.addCurve(to: CGPoint(x: 15.75, y: 31.14), controlPoint1: CGPoint(x: 14.12, y: 31.83), controlPoint2: CGPoint(x: 14.86, y: 31.14))
83+
bezierPath.addLine(to: CGPoint(x: 34.24, y: 31.14))
84+
bezierPath.addCurve(to: CGPoint(x: 35.84, y: 32.77), controlPoint1: CGPoint(x: 35.1, y: 31.14), controlPoint2: CGPoint(x: 35.84, y: 31.83))
85+
bezierPath.addCurve(to: CGPoint(x: 34.24, y: 34.39), controlPoint1: CGPoint(x: 35.84, y: 33.66), controlPoint2: CGPoint(x: 35.1, y: 34.39))
86+
bezierPath.addLine(to: CGPoint(x: 15.75, y: 34.39))
87+
bezierPath.close()
88+
fillColor.setFill()
89+
bezierPath.fill()
90+
91+
context.restoreGState()
92+
93+
}
94+
95+
@objc(StyleKitNameResizingBehavior)
96+
public enum ResizingBehavior: Int {
97+
98+
case aspectFit
99+
case aspectFill
100+
case stretch
101+
case center
102+
103+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
104+
if rect == target || target == CGRect.zero {
105+
return rect
106+
}
107+
108+
var scales = CGSize.zero
109+
scales.width = abs(target.width / rect.width)
110+
scales.height = abs(target.height / rect.height)
111+
112+
switch self {
113+
case .aspectFit:
114+
scales.width = min(scales.width, scales.height)
115+
scales.height = scales.width
116+
case .aspectFill:
117+
scales.width = max(scales.width, scales.height)
118+
scales.height = scales.width
119+
case .stretch:
120+
break
121+
case .center:
122+
scales.width = 1
123+
scales.height = 1
124+
}
125+
126+
var result = rect.standardized
127+
result.size.width *= scales.width
128+
result.size.height *= scales.height
129+
result.origin.x = target.minX + (target.width - result.width) / 2
130+
result.origin.y = target.minY + (target.height - result.height) / 2
131+
return result
132+
}
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)