Skip to content

Commit d9145ac

Browse files
committed
Added Bookmark preset
Realese 2.0.4 version.
1 parent 471f797 commit d9145ac

File tree

10 files changed

+145
-9
lines changed

10 files changed

+145
-9
lines changed
Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

1.74 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ViewController: UITableViewController {
77
Alert(key: "Done", preset: .done, title: "Added to Library", subtitle: nil),
88
Alert(key: "Heart", preset: .heart, title: "Love", subtitle: "We'll recommend more like this for you"),
99
Alert(key: "Doc", preset: .doc, title: "Document saved", subtitle: "See in folder new file"),
10+
Alert(key: "Bookmark", preset: .bookmark, title: "Added to bookmark", subtitle: "See bookmarks screen"),
1011
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),
1112
Alert(key: "Message", preset: nil, title: nil, subtitle: "Email required")
1213
]

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ For now supporting `Done`, `Heart`, `Doc`, `Error` & `Message` presets.
7878
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Done.svg" width="80">
7979
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Heart.svg" width="80">
8080
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Doc.svg" width="80">
81+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Bookmark.svg" width="80">
8182
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="80">
8283
</p>
8384

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.2"
4+
s.version = "2.0.4"
55
s.summary = "Native alert from Apple Music & Feedback. Contains Done, Heart & Message 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+
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */; };
2627
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */; };
2728
/* End PBXBuildFile section */
2829

@@ -75,6 +76,7 @@
7576
F41205182382AD8B009C2AC7 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
7677
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
7778
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
79+
F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBookmarkView.swift; sourceTree = "<group>"; };
7880
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconDocView.swift; sourceTree = "<group>"; };
7981
/* End PBXFileReference section */
8082

@@ -157,6 +159,7 @@
157159
F41204E32382AC9B009C2AC7 /* SPAlertIconDoneView.swift */,
158160
706F89492383277500ECF5D1 /* SPAlertIconErrorView.swift */,
159161
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */,
162+
F4A5A92B2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift */,
160163
);
161164
path = Icons;
162165
sourceTree = "<group>";
@@ -355,6 +358,7 @@
355358
F412052A2382AF64009C2AC7 /* SPAlertHaptic.swift in Sources */,
356359
F41204EE2382AC9B009C2AC7 /* SPAlert.swift in Sources */,
357360
F41204EA2382AC9B009C2AC7 /* SPAlertPreset.swift in Sources */,
361+
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */,
358362
F41204EC2382AC9B009C2AC7 /* SPAlertIconDoneView.swift in Sources */,
359363
F41204E92382AC9B009C2AC7 /* SPAlertView.swift in Sources */,
360364
706F894A2383277500ECF5D1 /* SPAlertIconErrorView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum SPAlertPreset {
2929
case done
3030
case heart
3131
case doc
32+
case bookmark
3233
case error
3334

3435
/**
@@ -42,6 +43,8 @@ public enum SPAlertPreset {
4243
return SPAlertIconHeartView()
4344
case .doc:
4445
return SPAlertIconDocView()
46+
case .bookmark:
47+
return SPAlertIconBookmarkView()
4548
case .error:
4649
return SPAlertIconErrorView()
4750
}
@@ -71,7 +74,15 @@ public enum SPAlertPreset {
7174
case .doc:
7275
var layout = SPAlertLayout()
7376
layout.topSpace = 49
74-
layout.bottomSpace = 25
77+
layout.bottomSpace = 29
78+
layout.iconWidth = 112
79+
layout.iconHeight = 77
80+
layout.bottomIconSpace = 35
81+
return layout
82+
case .bookmark:
83+
var layout = SPAlertLayout()
84+
layout.topSpace = 51
85+
layout.bottomSpace = 29
7586
layout.iconWidth = 112
7687
layout.iconHeight = 77
7788
layout.bottomIconSpace = 35
@@ -98,6 +109,8 @@ public enum SPAlertPreset {
98109
return .success
99110
case .doc:
100111
return .success
112+
case .bookmark:
113+
return .success
101114
case .error:
102115
return .error
103116
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 SPAlertIconBookmarkView: 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+
BookmarkDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class BookmarkDraw: NSObject {
41+
42+
@objc dynamic public class func draw(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 40, height: 53), 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: 40, height: 53), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 40, y: resizedFrame.height / 53)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 4.15, y: 52))
50+
bezierPath.addCurve(to: CGPoint(x: 1, y: 48.46), controlPoint1: CGPoint(x: 2.4, y: 52), controlPoint2: CGPoint(x: 1, y: 50.93))
51+
bezierPath.addLine(to: CGPoint(x: 1, y: 8.67))
52+
bezierPath.addCurve(to: CGPoint(x: 8.6, y: 1), controlPoint1: CGPoint(x: 1, y: 3.63), controlPoint2: CGPoint(x: 3.61, y: 1))
53+
bezierPath.addLine(to: CGPoint(x: 31.29, y: 1))
54+
bezierPath.addCurve(to: CGPoint(x: 38.88, y: 8.67), controlPoint1: CGPoint(x: 36.27, y: 1), controlPoint2: CGPoint(x: 38.88, y: 3.63))
55+
bezierPath.addLine(to: CGPoint(x: 38.88, y: 48.46))
56+
bezierPath.addCurve(to: CGPoint(x: 35.71, y: 52), controlPoint1: CGPoint(x: 38.88, y: 50.93), controlPoint2: CGPoint(x: 37.46, y: 52))
57+
bezierPath.addCurve(to: CGPoint(x: 32.52, y: 50.32), controlPoint1: CGPoint(x: 34.39, y: 52), controlPoint2: CGPoint(x: 33.55, y: 51.3))
58+
bezierPath.addLine(to: CGPoint(x: 21.04, y: 39.35))
59+
bezierPath.addCurve(to: CGPoint(x: 19.94, y: 38.74), controlPoint1: CGPoint(x: 20.55, y: 38.91), controlPoint2: CGPoint(x: 20.24, y: 38.74))
60+
bezierPath.addCurve(to: CGPoint(x: 18.85, y: 39.35), controlPoint1: CGPoint(x: 19.64, y: 38.74), controlPoint2: CGPoint(x: 19.34, y: 38.88))
61+
bezierPath.addLine(to: CGPoint(x: 8.5, y: 49.18))
62+
bezierPath.addLine(to: CGPoint(x: 7.65, y: 49.97))
63+
bezierPath.addCurve(to: CGPoint(x: 4.15, y: 52), controlPoint1: CGPoint(x: 6.04, y: 51.46), controlPoint2: CGPoint(x: 5.31, y: 52))
64+
bezierPath.close()
65+
fillColor.setFill()
66+
bezierPath.fill()
67+
context.restoreGState()
68+
}
69+
70+
@objc(StyleKitNameResizingBehavior)
71+
public enum ResizingBehavior: Int {
72+
73+
case aspectFit
74+
case aspectFill
75+
case stretch
76+
case center
77+
78+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
79+
if rect == target || target == CGRect.zero {
80+
return rect
81+
}
82+
83+
var scales = CGSize.zero
84+
scales.width = abs(target.width / rect.width)
85+
scales.height = abs(target.height / rect.height)
86+
87+
switch self {
88+
case .aspectFit:
89+
scales.width = min(scales.width, scales.height)
90+
scales.height = scales.width
91+
case .aspectFill:
92+
scales.width = max(scales.width, scales.height)
93+
scales.height = scales.width
94+
case .stretch:
95+
break
96+
case .center:
97+
scales.width = 1
98+
scales.height = 1
99+
}
100+
101+
var result = rect.standardized
102+
result.size.width *= scales.width
103+
result.size.height *= scales.height
104+
result.origin.x = target.minX + (target.width - result.width) / 2
105+
result.origin.y = target.minY + (target.height - result.height) / 2
106+
return result
107+
}
108+
}
109+
}
110+
}

Source/SPAlert/Views/Icons/SPAlertIconDocView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public class SPAlertIconDocView: UIView {
3434

3535
public override func draw(_ rect: CGRect) {
3636
super.draw(rect)
37-
DocDraw.drawDoc(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
37+
DocDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
3838
}
3939

4040
class DocDraw: NSObject {
4141

42-
@objc dynamic public class func drawDoc(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 70, height: 87), resizing: ResizingBehavior = .aspectFit, fillColor: UIColor = UIColor(red: 0.349, green: 0.345, blue: 0.353, alpha: 1.000)) {
42+
@objc dynamic public class func draw(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 70, height: 87), resizing: ResizingBehavior = .aspectFit, fillColor: UIColor = UIColor(red: 0.349, green: 0.345, blue: 0.353, alpha: 1.000)) {
4343

4444
let context = UIGraphicsGetCurrentContext()!
4545

Source/SPAlert/Views/Icons/SPAlertIconHeartView.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ public class SPAlertIconHeartView: UIView {
3434

3535
public override func draw(_ rect: CGRect) {
3636
super.draw(rect)
37-
HeartDraw.drawHeart(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
37+
HeartDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
3838
}
3939

4040
class HeartDraw: NSObject {
4141

42-
@objc dynamic public class func drawHeart(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 510, height: 470), resizing: ResizingBehavior = .aspectFit, fillColor: UIColor = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000)) {
43-
42+
@objc dynamic public class func draw(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 510, height: 470), resizing: ResizingBehavior = .aspectFit, fillColor: UIColor = UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000)) {
4443
let context = UIGraphicsGetCurrentContext()!
45-
4644
context.saveGState()
4745
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 510, height: 470), target: targetFrame)
4846
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
@@ -61,7 +59,6 @@ public class SPAlertIconHeartView: UIView {
6159
bezierPath.close()
6260
fillColor.setFill()
6361
bezierPath.fill()
64-
6562
context.restoreGState()
6663
}
6764

0 commit comments

Comments
 (0)