Skip to content

Commit af80317

Browse files
committed
Add Doc preset
1 parent 593dd19 commit af80317

File tree

9 files changed

+214
-63
lines changed

9 files changed

+214
-63
lines changed

Assets/Readme/Miniature - Doc.svg

Lines changed: 12 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

164 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ class ViewController: UITableViewController {
66
let data: [Alert] = [
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"),
9-
Alert(key: "Message", preset: nil, title: nil, subtitle: "Email required"),
10-
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later")
9+
Alert(key: "Doc", preset: .doc, title: "Documents saved", subtitle: "See in folder new file"),
10+
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),
11+
Alert(key: "Message", preset: nil, title: nil, subtitle: "Email required")
1112
]
1213

1314
var selectedIndexPath: IndexPath {

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ For now supporting `Done`, `Heart`, `Error` & `Message` presets.
7777
<p float="left">
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">
80+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Doc.svg" width="80">
8081
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="80">
8182
</p>
8283

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.1"
4+
s.version = "2.0.2"
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+
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */; };
2627
/* End PBXBuildFile section */
2728

2829
/* Begin PBXContainerItemProxy section */
@@ -74,6 +75,7 @@
7475
F41205182382AD8B009C2AC7 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
7576
F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertLayout.swift; sourceTree = "<group>"; };
7677
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
78+
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconDocView.swift; sourceTree = "<group>"; };
7779
/* End PBXFileReference section */
7880

7981
/* Begin PBXFrameworksBuildPhase section */
@@ -154,6 +156,7 @@
154156
F41204E22382AC9B009C2AC7 /* SPAlertIconHeartView.swift */,
155157
F41204E32382AC9B009C2AC7 /* SPAlertIconDoneView.swift */,
156158
706F89492383277500ECF5D1 /* SPAlertIconErrorView.swift */,
159+
F4A836192385588300EB32E0 /* SPAlertIconDocView.swift */,
157160
);
158161
path = Icons;
159162
sourceTree = "<group>";
@@ -357,6 +360,7 @@
357360
706F894A2383277500ECF5D1 /* SPAlertIconErrorView.swift in Sources */,
358361
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */,
359362
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */,
363+
F4A8361A2385588300EB32E0 /* SPAlertIconDocView.swift in Sources */,
360364
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */,
361365
);
362366
runOnlyForDeploymentPostprocessing = 0;

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum SPAlertPreset {
2525

2626
case done
2727
case heart
28+
case doc
2829
case error
2930

3031
var iconView: UIView {
@@ -33,6 +34,8 @@ public enum SPAlertPreset {
3334
return SPAlertIconDoneView()
3435
case .heart:
3536
return SPAlertIconHeartView()
37+
case .doc:
38+
return SPAlertIconDocView()
3639
case .error:
3740
return SPAlertIconErrorView()
3841
}
@@ -56,6 +59,14 @@ public enum SPAlertPreset {
5659
layout.iconHeight = 77
5760
layout.bottomIconSpace = 35
5861
return layout
62+
case .doc:
63+
var layout = SPAlertLayout()
64+
layout.topSpace = 49
65+
layout.bottomSpace = 25
66+
layout.iconWidth = 112
67+
layout.iconHeight = 77
68+
layout.bottomIconSpace = 35
69+
return layout
5970
case .error:
6071
var layout = SPAlertLayout()
6172
layout.topSpace = 63
@@ -73,6 +84,8 @@ public enum SPAlertPreset {
7384
return .success
7485
case .heart:
7586
return .success
87+
case .doc:
88+
return .success
7689
case .error:
7790
return .error
7891
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 SPAlertIconDocView: 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+
DocDraw.drawDoc(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class DocDraw: NSObject {
41+
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)) {
43+
44+
let context = UIGraphicsGetCurrentContext()!
45+
46+
context.saveGState()
47+
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 70, height: 87), target: targetFrame)
48+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
49+
context.scaleBy(x: resizedFrame.width / 70, y: resizedFrame.height / 87)
50+
51+
let bezierPath = UIBezierPath()
52+
bezierPath.move(to: CGPoint(x: 13.73, y: 86.65))
53+
bezierPath.addLine(to: CGPoint(x: 55.38, y: 86.65))
54+
bezierPath.addCurve(to: CGPoint(x: 68.11, y: 73.76), controlPoint1: CGPoint(x: 63.77, y: 86.65), controlPoint2: CGPoint(x: 68.11, y: 82.2))
55+
bezierPath.addLine(to: CGPoint(x: 68.11, y: 38.84))
56+
bezierPath.addLine(to: CGPoint(x: 38.81, y: 38.84))
57+
bezierPath.addCurve(to: CGPoint(x: 31.59, y: 31.61), controlPoint1: CGPoint(x: 33.93, y: 38.84), controlPoint2: CGPoint(x: 31.59, y: 36.49))
58+
bezierPath.addLine(to: CGPoint(x: 31.59, y: 2))
59+
bezierPath.addLine(to: CGPoint(x: 13.73, y: 2))
60+
bezierPath.addCurve(to: CGPoint(x: 1, y: 14.85), controlPoint1: CGPoint(x: 5.38, y: 2), controlPoint2: CGPoint(x: 1, y: 6.41))
61+
bezierPath.addLine(to: CGPoint(x: 1, y: 73.76))
62+
bezierPath.addCurve(to: CGPoint(x: 13.73, y: 86.65), controlPoint1: CGPoint(x: 1, y: 82.23), controlPoint2: CGPoint(x: 5.38, y: 86.65))
63+
bezierPath.close()
64+
bezierPath.move(to: CGPoint(x: 39.55, y: 33.13))
65+
bezierPath.addCurve(to: CGPoint(x: 37.29, y: 30.87), controlPoint1: CGPoint(x: 38.07, y: 33.13), controlPoint2: CGPoint(x: 37.33, y: 32.39))
66+
bezierPath.addLine(to: CGPoint(x: 37.29, y: 2.39))
67+
bezierPath.addCurve(to: CGPoint(x: 42.8, y: 5.91), controlPoint1: CGPoint(x: 39.09, y: 2.62), controlPoint2: CGPoint(x: 40.84, y: 3.95))
68+
bezierPath.addLine(to: CGPoint(x: 64.16, y: 27.59))
69+
bezierPath.addLine(to: CGPoint(x: 64.68, y: 28.12))
70+
bezierPath.addCurve(to: CGPoint(x: 67.72, y: 33.13), controlPoint1: CGPoint(x: 66.41, y: 29.95), controlPoint2: CGPoint(x: 67.5, y: 31.49))
71+
bezierPath.addLine(to: CGPoint(x: 39.55, y: 33.13))
72+
bezierPath.close()
73+
fillColor.setFill()
74+
bezierPath.fill()
75+
context.restoreGState()
76+
}
77+
78+
@objc(StyleKitNameResizingBehavior)
79+
public enum ResizingBehavior: Int {
80+
81+
case aspectFit
82+
case aspectFill
83+
case stretch
84+
case center
85+
86+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
87+
if rect == target || target == CGRect.zero {
88+
return rect
89+
}
90+
91+
var scales = CGSize.zero
92+
scales.width = abs(target.width / rect.width)
93+
scales.height = abs(target.height / rect.height)
94+
95+
switch self {
96+
case .aspectFit:
97+
scales.width = min(scales.width, scales.height)
98+
scales.height = scales.width
99+
case .aspectFill:
100+
scales.width = max(scales.width, scales.height)
101+
scales.height = scales.width
102+
case .stretch:
103+
break
104+
case .center:
105+
scales.width = 1
106+
scales.height = 1
107+
}
108+
109+
var result = rect.standardized
110+
result.size.width *= scales.width
111+
result.size.height *= scales.height
112+
result.origin.x = target.minX + (target.width - result.width) / 2
113+
result.origin.y = target.minY + (target.height - result.height) / 2
114+
return result
115+
}
116+
}
117+
}
118+
}
119+

Source/SPAlert/Views/Icons/SPAlertIconHeartView.swift

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,72 +36,73 @@ public class SPAlertIconHeartView: UIView {
3636
super.draw(rect)
3737
HeartDraw.drawHeart(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
3838
}
39-
}
40-
41-
class HeartDraw: NSObject {
4239

43-
@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)) {
44-
45-
let context = UIGraphicsGetCurrentContext()!
40+
class HeartDraw: NSObject {
4641

47-
context.saveGState()
48-
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 510, height: 470), target: targetFrame)
49-
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
50-
context.scaleBy(x: resizedFrame.width / 510, y: resizedFrame.height / 470)
51-
52-
let bezierPath = UIBezierPath()
53-
bezierPath.move(to: CGPoint(x: 255, y: 469.6))
54-
bezierPath.addLine(to: CGPoint(x: 219.3, y: 433.9))
55-
bezierPath.addCurve(to: CGPoint(x: 0, y: 140.65), controlPoint1: CGPoint(x: 86.7, y: 316.6), controlPoint2: CGPoint(x: 0, y: 237.55))
56-
bezierPath.addCurve(to: CGPoint(x: 140.25, y: 0.4), controlPoint1: CGPoint(x: 0, y: 61.6), controlPoint2: CGPoint(x: 61.2, y: 0.4))
57-
bezierPath.addCurve(to: CGPoint(x: 255, y: 53.95), controlPoint1: CGPoint(x: 183.6, y: 0.4), controlPoint2: CGPoint(x: 226.95, y: 20.8))
58-
bezierPath.addCurve(to: CGPoint(x: 369.75, y: 0.4), controlPoint1: CGPoint(x: 283.05, y: 20.8), controlPoint2: CGPoint(x: 326.4, y: 0.4))
59-
bezierPath.addCurve(to: CGPoint(x: 510, y: 140.65), controlPoint1: CGPoint(x: 448.8, y: 0.4), controlPoint2: CGPoint(x: 510, y: 61.6))
60-
bezierPath.addCurve(to: CGPoint(x: 290.7, y: 433.9), controlPoint1: CGPoint(x: 510, y: 237.55), controlPoint2: CGPoint(x: 423.3, y: 316.6))
61-
bezierPath.addLine(to: CGPoint(x: 255, y: 469.6))
62-
bezierPath.close()
63-
fillColor.setFill()
64-
bezierPath.fill()
65-
66-
context.restoreGState()
67-
}
68-
69-
@objc(HeartStyleKitResizingBehavior)
70-
public enum ResizingBehavior: Int {
71-
case aspectFit
72-
case aspectFill
73-
case stretch
74-
case center
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+
44+
let context = UIGraphicsGetCurrentContext()!
45+
46+
context.saveGState()
47+
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 510, height: 470), target: targetFrame)
48+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
49+
context.scaleBy(x: resizedFrame.width / 510, y: resizedFrame.height / 470)
50+
51+
let bezierPath = UIBezierPath()
52+
bezierPath.move(to: CGPoint(x: 255, y: 469.6))
53+
bezierPath.addLine(to: CGPoint(x: 219.3, y: 433.9))
54+
bezierPath.addCurve(to: CGPoint(x: 0, y: 140.65), controlPoint1: CGPoint(x: 86.7, y: 316.6), controlPoint2: CGPoint(x: 0, y: 237.55))
55+
bezierPath.addCurve(to: CGPoint(x: 140.25, y: 0.4), controlPoint1: CGPoint(x: 0, y: 61.6), controlPoint2: CGPoint(x: 61.2, y: 0.4))
56+
bezierPath.addCurve(to: CGPoint(x: 255, y: 53.95), controlPoint1: CGPoint(x: 183.6, y: 0.4), controlPoint2: CGPoint(x: 226.95, y: 20.8))
57+
bezierPath.addCurve(to: CGPoint(x: 369.75, y: 0.4), controlPoint1: CGPoint(x: 283.05, y: 20.8), controlPoint2: CGPoint(x: 326.4, y: 0.4))
58+
bezierPath.addCurve(to: CGPoint(x: 510, y: 140.65), controlPoint1: CGPoint(x: 448.8, y: 0.4), controlPoint2: CGPoint(x: 510, y: 61.6))
59+
bezierPath.addCurve(to: CGPoint(x: 290.7, y: 433.9), controlPoint1: CGPoint(x: 510, y: 237.55), controlPoint2: CGPoint(x: 423.3, y: 316.6))
60+
bezierPath.addLine(to: CGPoint(x: 255, y: 469.6))
61+
bezierPath.close()
62+
fillColor.setFill()
63+
bezierPath.fill()
64+
65+
context.restoreGState()
66+
}
7567

76-
public func apply(rect: CGRect, target: CGRect) -> CGRect {
77-
if rect == target || target == CGRect.zero {
78-
return rect
79-
}
68+
@objc(HeartStyleKitResizingBehavior)
69+
public enum ResizingBehavior: Int {
8070

81-
var scales = CGSize.zero
82-
scales.width = abs(target.width / rect.width)
83-
scales.height = abs(target.height / rect.height)
71+
case aspectFit
72+
case aspectFill
73+
case stretch
74+
case center
8475

85-
switch self {
86-
case .aspectFit:
87-
scales.width = min(scales.width, scales.height)
88-
scales.height = scales.width
89-
case .aspectFill:
90-
scales.width = max(scales.width, scales.height)
91-
scales.height = scales.width
92-
case .stretch:
93-
break
94-
case .center:
95-
scales.width = 1
96-
scales.height = 1
76+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
77+
if rect == target || target == CGRect.zero {
78+
return rect
79+
}
80+
81+
var scales = CGSize.zero
82+
scales.width = abs(target.width / rect.width)
83+
scales.height = abs(target.height / rect.height)
84+
85+
switch self {
86+
case .aspectFit:
87+
scales.width = min(scales.width, scales.height)
88+
scales.height = scales.width
89+
case .aspectFill:
90+
scales.width = max(scales.width, scales.height)
91+
scales.height = scales.width
92+
case .stretch:
93+
break
94+
case .center:
95+
scales.width = 1
96+
scales.height = 1
97+
}
98+
99+
var result = rect.standardized
100+
result.size.width *= scales.width
101+
result.size.height *= scales.height
102+
result.origin.x = target.minX + (target.width - result.width) / 2
103+
result.origin.y = target.minY + (target.height - result.height) / 2
104+
return result
97105
}
98-
99-
var result = rect.standardized
100-
result.size.width *= scales.width
101-
result.size.height *= scales.height
102-
result.origin.x = target.minX + (target.width - result.width) / 2
103-
result.origin.y = target.minY + (target.height - result.height) / 2
104-
return result
105106
}
106107
}
107108
}

0 commit comments

Comments
 (0)