Skip to content

Commit 76d3230

Browse files
committed
Add .flag preset
1 parent 6821fa4 commit 76d3230

File tree

8 files changed

+142
-1
lines changed

8 files changed

+142
-1
lines changed

Assets/Readme/Miniature - Flag.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

1.71 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ViewController: UITableViewController {
1010
Alert(key: "Bookmark", preset: .bookmark, title: "Added to bookmark", subtitle: "See bookmarks screen"),
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),
13+
Alert(key: "Flag", preset: .flag, title: "Message Flaged", subtitle: nil),
1314
Alert(key: "Exclamation", preset: .exclamation, title: "Oops", subtitle: "Something went wrong"),
1415
Alert(key: "Message", preset: .message, title: "Message sended", subtitle: "You can check history"),
1516
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ And other
1515
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Bookmark.svg" width="55">
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">
18+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Flag.svg" width="55">
1819
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Exclamation.svg" width="55">
1920
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Message.svg" width="55">
2021
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.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.11"
4+
s.version = "2.0.12"
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+
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */; };
2627
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
2728
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
2829
F47EE19F23959AE500B02DF2 /* SPAlertIconRepeatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */; };
@@ -83,6 +84,7 @@
8384
F41205182382AD8B009C2AC7 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
8485
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
8586
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
87+
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconFlagView.swift; sourceTree = "<group>"; };
8688
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
8789
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
8890
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRepeatView.swift; sourceTree = "<group>"; };
@@ -181,6 +183,7 @@
181183
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */,
182184
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */,
183185
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */,
186+
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */,
184187
);
185188
path = Icons;
186189
sourceTree = "<group>";
@@ -383,6 +386,7 @@
383386
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */,
384387
F41204EC2382AC9B009C2AC7 /* SPAlertIconDoneView.swift in Sources */,
385388
F41204E92382AC9B009C2AC7 /* SPAlertView.swift in Sources */,
389+
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */,
386390
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */,
387391
F4D3CD58238DA9FE006C3DE2 /* SPAlertIconMoonView.swift in Sources */,
388392
F4D3CD5A238DAA49006C3DE2 /* SPAlertIconStarView.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 flag
3637
case message
3738
case add
3839
case error
@@ -68,6 +69,8 @@ public enum SPAlertPreset {
6869
return SPAlertIconShuffleView()
6970
case .repeat:
7071
return SPAlertIconRepeatView()
72+
case .flag:
73+
return SPAlertIconFlagView()
7174
}
7275
}
7376

@@ -116,6 +119,14 @@ public enum SPAlertPreset {
116119
layout.iconHeight = 77
117120
layout.bottomIconSpace = 35
118121
return layout
122+
case .flag:
123+
var layout = SPAlertLayout()
124+
layout.topSpace = 49
125+
layout.bottomSpace = 31
126+
layout.iconWidth = 112
127+
layout.iconHeight = 88
128+
layout.bottomIconSpace = 35
129+
return layout
119130
case .bookmark:
120131
var layout = SPAlertLayout()
121132
layout.topSpace = 57
@@ -204,6 +215,8 @@ public enum SPAlertPreset {
204215
return .success
205216
case .repeat:
206217
return .success
218+
case .flag:
219+
return .success
207220
}
208221
}
209222
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 SPAlertIconFlagView: 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: 51, height: 55), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 51, y: resizedFrame.height / 55)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 3.94, y: 53))
50+
bezierPath.addCurve(to: CGPoint(x: 2, y: 51.09), controlPoint1: CGPoint(x: 2.89, y: 53), controlPoint2: CGPoint(x: 2, y: 52.13))
51+
bezierPath.addLine(to: CGPoint(x: 2, y: 8.73))
52+
bezierPath.addCurve(to: CGPoint(x: 4.91, y: 4.3), controlPoint1: CGPoint(x: 2, y: 6.41), controlPoint2: CGPoint(x: 3.15, y: 5.09))
53+
bezierPath.addLine(to: CGPoint(x: 5.25, y: 4.15))
54+
bezierPath.addCurve(to: CGPoint(x: 12.32, y: 3), controlPoint1: CGPoint(x: 7.03, y: 3.38), controlPoint2: CGPoint(x: 8.59, y: 3))
55+
bezierPath.addCurve(to: CGPoint(x: 36.63, y: 7.61), controlPoint1: CGPoint(x: 21.78, y: 3), controlPoint2: CGPoint(x: 27.66, y: 7.61))
56+
bezierPath.addCurve(to: CGPoint(x: 44.61, y: 6.54), controlPoint1: CGPoint(x: 41.02, y: 7.61), controlPoint2: CGPoint(x: 43.36, y: 6.54))
57+
bezierPath.addCurve(to: CGPoint(x: 47.26, y: 8.71), controlPoint1: CGPoint(x: 46.09, y: 6.54), controlPoint2: CGPoint(x: 47.26, y: 7.33))
58+
bezierPath.addLine(to: CGPoint(x: 47.26, y: 34.57))
59+
bezierPath.addCurve(to: CGPoint(x: 44.35, y: 39.03), controlPoint1: CGPoint(x: 47.26, y: 36.92), controlPoint2: CGPoint(x: 46.11, y: 38.24))
60+
bezierPath.addLine(to: CGPoint(x: 44.01, y: 39.19))
61+
bezierPath.addCurve(to: CGPoint(x: 36.96, y: 40.33), controlPoint1: CGPoint(x: 42.23, y: 39.95), controlPoint2: CGPoint(x: 40.7, y: 40.33))
62+
bezierPath.addCurve(to: CGPoint(x: 12.65, y: 35.72), controlPoint1: CGPoint(x: 27.99, y: 40.33), controlPoint2: CGPoint(x: 22.08, y: 35.72))
63+
bezierPath.addCurve(to: CGPoint(x: 5.87, y: 36.92), controlPoint1: CGPoint(x: 8.91, y: 35.72), controlPoint2: CGPoint(x: 6.51, y: 36.64))
64+
bezierPath.addLine(to: CGPoint(x: 5.87, y: 51.09))
65+
bezierPath.addCurve(to: CGPoint(x: 3.94, y: 53), controlPoint1: CGPoint(x: 5.87, y: 52.16), controlPoint2: CGPoint(x: 5.01, y: 53))
66+
bezierPath.close()
67+
fillColor.setFill()
68+
bezierPath.fill()
69+
context.restoreGState()
70+
}
71+
72+
@objc(StyleKitNameResizingBehavior)
73+
public enum ResizingBehavior: Int {
74+
75+
case aspectFit
76+
case aspectFill
77+
case stretch
78+
case center
79+
80+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
81+
if rect == target || target == CGRect.zero {
82+
return rect
83+
}
84+
85+
var scales = CGSize.zero
86+
scales.width = abs(target.width / rect.width)
87+
scales.height = abs(target.height / rect.height)
88+
89+
switch self {
90+
case .aspectFit:
91+
scales.width = min(scales.width, scales.height)
92+
scales.height = scales.width
93+
case .aspectFill:
94+
scales.width = max(scales.width, scales.height)
95+
scales.height = scales.width
96+
case .stretch:
97+
break
98+
case .center:
99+
scales.width = 1
100+
scales.height = 1
101+
}
102+
103+
var result = rect.standardized
104+
result.size.width *= scales.width
105+
result.size.height *= scales.height
106+
result.origin.x = target.minX + (target.width - result.width) / 2
107+
result.origin.y = target.minY + (target.height - result.height) / 2
108+
return result
109+
}
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)