Skip to content

Commit e8b3fe1

Browse files
committed
Add .like preset
1 parent 1612b23 commit e8b3fe1

File tree

8 files changed

+166
-1
lines changed

8 files changed

+166
-1
lines changed

Assets/Readme/Miniature - Like.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

3.99 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ViewController: UITableViewController {
1717
Alert(key: "Bolt", preset: .bolt, title: "Power", subtitle: "Now turned on"),
1818
Alert(key: "Eject", preset: .eject, title: "Eject complete", subtitle: nil),
1919
Alert(key: "Card", preset: .card, title: "Payment sent", subtitle: "Thanks for donate"),
20+
Alert(key: "Like", preset: .like, title: "Thanks for feedback", subtitle: "It helped us"),
2021
Alert(key: "Rotate", preset: .rotate, title: "Portrait mode", subtitle: "You can change it in settings"),
2122
Alert(key: "Magic", preset: .magic, title: "Magic here! You see", subtitle: "Strange text, true?"),
2223
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
@@ -22,6 +22,7 @@ And other
2222
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Bolt.svg" width="55">
2323
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Eject.svg" width="55">
2424
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Card.svg" width="55">
25+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Like.svg" width="55">
2526
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Rotate.svg" width="55">
2627
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Magic.svg" width="55">
2728
<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.22"
4+
s.version = "2.0.24"
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
@@ -24,6 +24,7 @@
2424
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */; };
2525
F412052A2382AF64009C2AC7 /* SPAlertHaptic.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41204E42382AC9B009C2AC7 /* SPAlertHaptic.swift */; };
2626
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */; };
27+
F4146EB223AAA18100AE7658 /* SPAlertIconLikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4146EB123AAA18100AE7658 /* SPAlertIconLikeView.swift */; };
2728
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */; };
2829
F45970B423A578A50092CE7C /* SPAlertIconCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */; };
2930
F459720223A841C00092CE7C /* SPAlertIconRotateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */; };
@@ -91,6 +92,7 @@
9192
F41205182382AD8B009C2AC7 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
9293
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
9394
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
95+
F4146EB123AAA18100AE7658 /* SPAlertIconLikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconLikeView.swift; sourceTree = "<group>"; };
9496
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconFlagView.swift; sourceTree = "<group>"; };
9597
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconCardView.swift; sourceTree = "<group>"; };
9698
F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRotateView.swift; sourceTree = "<group>"; };
@@ -202,6 +204,7 @@
202204
F4D1623323A2E47200B5E3E9 /* SPAlertIconEjectView.swift */,
203205
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */,
204206
F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */,
207+
F4146EB123AAA18100AE7658 /* SPAlertIconLikeView.swift */,
205208
);
206209
path = Icons;
207210
sourceTree = "<group>";
@@ -419,6 +422,7 @@
419422
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */,
420423
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */,
421424
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */,
425+
F4146EB223AAA18100AE7658 /* SPAlertIconLikeView.swift in Sources */,
422426
F45970B423A578A50092CE7C /* SPAlertIconCardView.swift in Sources */,
423427
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */,
424428
F4CD29F423A037D00051EA23 /* SPAlertIconMagicView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum SPAlertPreset {
4545
case eject
4646
case card
4747
case rotate
48+
case like
4849

4950
/**
5051
View for preset. Wrap to `UIView`.
@@ -89,6 +90,8 @@ public enum SPAlertPreset {
8990
return SPAlertIconCardView()
9091
case .rotate:
9192
return SPAlertIconRotateView()
93+
case .like:
94+
return SPAlertIconLikeView()
9295
}
9396
}
9497

@@ -178,6 +181,14 @@ public enum SPAlertPreset {
178181
layout.iconHeight = 88
179182
layout.bottomIconSpace = 35
180183
return layout
184+
case .like:
185+
var layout = SPAlertLayout()
186+
layout.topSpace = 49
187+
layout.bottomSpace = 31
188+
layout.iconWidth = 112
189+
layout.iconHeight = 88
190+
layout.bottomIconSpace = 35
191+
return layout
181192
case .bookmark:
182193
var layout = SPAlertLayout()
183194
layout.topSpace = 57
@@ -296,6 +307,8 @@ public enum SPAlertPreset {
296307
return .success
297308
case .rotate:
298309
return .success
310+
case .like:
311+
return .success
299312
}
300313
}
301314
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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 SPAlertIconLikeView: 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+
LikeDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class LikeDraw: 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: 62, height: 65), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 62, y: resizedFrame.height / 65)
48+
context.saveGState()
49+
context.beginTransparencyLayer(auxiliaryInfo: nil)
50+
let clipPath = UIBezierPath()
51+
clipPath.move(to: CGPoint(x: 49.72, y: 61.4))
52+
clipPath.addLine(to: CGPoint(x: 49.9, y: 61.36))
53+
clipPath.addCurve(to: CGPoint(x: 54.26, y: 56.74), controlPoint1: CGPoint(x: 52.08, y: 60.85), controlPoint2: CGPoint(x: 54.26, y: 59.43))
54+
clipPath.addCurve(to: CGPoint(x: 53.68, y: 54.41), controlPoint1: CGPoint(x: 54.26, y: 55.74), controlPoint2: CGPoint(x: 54.02, y: 55.02))
55+
clipPath.addLine(to: CGPoint(x: 53.59, y: 54.26))
56+
clipPath.addCurve(to: CGPoint(x: 53.73, y: 53.47), controlPoint1: CGPoint(x: 53.37, y: 53.89), controlPoint2: CGPoint(x: 53.42, y: 53.61))
57+
clipPath.addCurve(to: CGPoint(x: 56.97, y: 48.86), controlPoint1: CGPoint(x: 55.49, y: 52.69), controlPoint2: CGPoint(x: 56.97, y: 51.13))
58+
clipPath.addCurve(to: CGPoint(x: 56.12, y: 45.83), controlPoint1: CGPoint(x: 56.97, y: 47.69), controlPoint2: CGPoint(x: 56.66, y: 46.62))
59+
clipPath.addLine(to: CGPoint(x: 55.99, y: 45.65))
60+
clipPath.addCurve(to: CGPoint(x: 56.25, y: 44.58), controlPoint1: CGPoint(x: 55.66, y: 45.23), controlPoint2: CGPoint(x: 55.74, y: 44.89))
61+
clipPath.addCurve(to: CGPoint(x: 58.37, y: 40.39), controlPoint1: CGPoint(x: 57.53, y: 43.86), controlPoint2: CGPoint(x: 58.37, y: 42.24))
62+
clipPath.addCurve(to: CGPoint(x: 57.17, y: 36.98), controlPoint1: CGPoint(x: 58.37, y: 39.11), controlPoint2: CGPoint(x: 57.95, y: 37.68))
63+
clipPath.addCurve(to: CGPoint(x: 57.34, y: 35.92), controlPoint1: CGPoint(x: 56.75, y: 36.59), controlPoint2: CGPoint(x: 56.83, y: 36.31))
64+
clipPath.addCurve(to: CGPoint(x: 58.73, y: 32.29), controlPoint1: CGPoint(x: 58.23, y: 35.22), controlPoint2: CGPoint(x: 58.73, y: 33.88))
65+
clipPath.addCurve(to: CGPoint(x: 53.84, y: 27.34), controlPoint1: CGPoint(x: 58.73, y: 29.55), controlPoint2: CGPoint(x: 56.61, y: 27.34))
66+
clipPath.addLine(to: CGPoint(x: 43.86, y: 27.34))
67+
clipPath.addCurve(to: CGPoint(x: 39.64, y: 23.96), controlPoint1: CGPoint(x: 41.32, y: 27.34), controlPoint2: CGPoint(x: 39.64, y: 26.03))
68+
clipPath.addCurve(to: CGPoint(x: 44.4, y: 8.16), controlPoint1: CGPoint(x: 39.64, y: 20.1), controlPoint2: CGPoint(x: 44.4, y: 13.17))
69+
clipPath.addCurve(to: CGPoint(x: 40.48, y: 4), controlPoint1: CGPoint(x: 44.4, y: 5.57), controlPoint2: CGPoint(x: 42.69, y: 4))
70+
clipPath.addCurve(to: CGPoint(x: 36.35, y: 7.52), controlPoint1: CGPoint(x: 38.47, y: 4), controlPoint2: CGPoint(x: 37.44, y: 5.4))
71+
clipPath.addCurve(to: CGPoint(x: 22.26, y: 28.04), controlPoint1: CGPoint(x: 32.21, y: 15.74), controlPoint2: CGPoint(x: 26.56, y: 22.36))
72+
clipPath.addCurve(to: CGPoint(x: 16.75, y: 43.69), controlPoint1: CGPoint(x: 18.62, y: 32.9), controlPoint2: CGPoint(x: 16.84, y: 36.98))
73+
clipPath.addCurve(to: CGPoint(x: 38.11, y: 61.97), controlPoint1: CGPoint(x: 16.61, y: 54), controlPoint2: CGPoint(x: 24.97, y: 61.86))
74+
clipPath.addLine(to: CGPoint(x: 41.99, y: 62))
75+
clipPath.addCurve(to: CGPoint(x: 49.72, y: 61.4), controlPoint1: CGPoint(x: 45.51, y: 62.02), controlPoint2: CGPoint(x: 48.13, y: 61.77))
76+
clipPath.addLine(to: CGPoint(x: 49.72, y: 61.4))
77+
clipPath.close()
78+
clipPath.move(to: CGPoint(x: 3, y: 43.89))
79+
clipPath.addCurve(to: CGPoint(x: 14.18, y: 28.37), controlPoint1: CGPoint(x: 3, y: 35.19), controlPoint2: CGPoint(x: 7.86, y: 28.37))
80+
clipPath.addLine(to: CGPoint(x: 18.29, y: 28.37))
81+
clipPath.addLine(to: CGPoint(x: 17.96, y: 28.79))
82+
clipPath.addCurve(to: CGPoint(x: 12.95, y: 43.61), controlPoint1: CGPoint(x: 15.56, y: 31.9), controlPoint2: CGPoint(x: 13.06, y: 36.82))
83+
clipPath.addCurve(to: CGPoint(x: 20.22, y: 59.29), controlPoint1: CGPoint(x: 12.84, y: 50.01), controlPoint2: CGPoint(x: 15.16, y: 55.6))
84+
clipPath.addLine(to: CGPoint(x: 15.21, y: 59.29))
85+
clipPath.addCurve(to: CGPoint(x: 3, y: 43.89), controlPoint1: CGPoint(x: 8.23, y: 59.29), controlPoint2: CGPoint(x: 3, y: 52.27))
86+
clipPath.close()
87+
clipPath.addClip()
88+
let rectanglePath = UIBezierPath(rect: CGRect(x: -2.02, y: -1, width: 65.75, height: 68))
89+
fillColor.setFill()
90+
rectanglePath.fill()
91+
context.endTransparencyLayer()
92+
context.restoreGState()
93+
context.restoreGState()
94+
}
95+
96+
@objc(StyleKitNameResizingBehavior)
97+
public enum ResizingBehavior: Int {
98+
99+
case aspectFit
100+
case aspectFill
101+
case stretch
102+
case center
103+
104+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
105+
if rect == target || target == CGRect.zero {
106+
return rect
107+
}
108+
109+
var scales = CGSize.zero
110+
scales.width = abs(target.width / rect.width)
111+
scales.height = abs(target.height / rect.height)
112+
113+
switch self {
114+
case .aspectFit:
115+
scales.width = min(scales.width, scales.height)
116+
scales.height = scales.width
117+
case .aspectFill:
118+
scales.width = max(scales.width, scales.height)
119+
scales.height = scales.width
120+
case .stretch:
121+
break
122+
case .center:
123+
scales.width = 1
124+
scales.height = 1
125+
}
126+
127+
var result = rect.standardized
128+
result.size.width *= scales.width
129+
result.size.height *= scales.height
130+
result.origin.x = target.minX + (target.width - result.width) / 2
131+
result.origin.y = target.minY + (target.height - result.height) / 2
132+
return result
133+
}
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)