Skip to content

Commit dee821d

Browse files
committed
Add .search preset
1 parent 104f2ce commit dee821d

File tree

8 files changed

+143
-1
lines changed

8 files changed

+143
-1
lines changed

Assets/Readme/Miniature - Search.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

3.04 KB
Binary file not shown.

Example/Controllers/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ViewController: UITableViewController {
2323
Alert(key: "Privacy", preset: .privacy, title: "Privacy accepted", subtitle: "You privacy it important"),
2424
Alert(key: "Rotate", preset: .rotate, title: "Portrait mode", subtitle: "You can change it in settings"),
2525
Alert(key: "Magic", preset: .magic, title: "Magic here! You see", subtitle: "Strange text, true?"),
26+
Alert(key: "Search", preset: .search, title: "Searching", subtitle: "Maybe need other title"),
2627
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
2728
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),
2829
Alert(key: "Shuffle", preset: .shuffle, title: "Songs Shuffled", subtitle: nil),

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ And other
2828
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Privacy.svg" width="55">
2929
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Rotate.svg" width="55">
3030
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Magic.svg" width="55">
31+
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Search.svg" width="55">
3132
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
3233
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.svg" width="55">
3334
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Shuffle.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.26"
4+
s.version = "2.0.28"
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
@@ -32,6 +32,7 @@
3232
F459720223A841C00092CE7C /* SPAlertIconRotateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */; };
3333
F45DDF2823AFFF3000CA3956 /* SPAlertIconCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45DDF2723AFFF3000CA3956 /* SPAlertIconCartView.swift */; };
3434
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
35+
F47120BB23C25EFA003B73C5 /* SPAlertIconSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47120BA23C25EFA003B73C5 /* SPAlertIconSearchView.swift */; };
3536
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */; };
3637
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
3738
F47EE19F23959AE500B02DF2 /* SPAlertIconRepeatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */; };
@@ -103,6 +104,7 @@
103104
F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRotateView.swift; sourceTree = "<group>"; };
104105
F45DDF2723AFFF3000CA3956 /* SPAlertIconCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconCartView.swift; sourceTree = "<group>"; };
105106
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
107+
F47120BA23C25EFA003B73C5 /* SPAlertIconSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconSearchView.swift; sourceTree = "<group>"; };
106108
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBoltView.swift; sourceTree = "<group>"; };
107109
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
108110
F47EE19E23959AE500B02DF2 /* SPAlertIconRepeatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRepeatView.swift; sourceTree = "<group>"; };
@@ -214,6 +216,7 @@
214216
F42DE05323AD7D8A007CCE29 /* SPAlertIconDislikeView.swift */,
215217
F42DE05523AD7D94007CCE29 /* SPAlertIconPrivacyView.swift */,
216218
F45DDF2723AFFF3000CA3956 /* SPAlertIconCartView.swift */,
219+
F47120BA23C25EFA003B73C5 /* SPAlertIconSearchView.swift */,
217220
);
218221
path = Icons;
219222
sourceTree = "<group>";
@@ -430,6 +433,7 @@
430433
F41205292382AF5C009C2AC7 /* SPAlertIconAnimatable.swift in Sources */,
431434
F4D1623423A2E47200B5E3E9 /* SPAlertIconEjectView.swift in Sources */,
432435
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */,
436+
F47120BB23C25EFA003B73C5 /* SPAlertIconSearchView.swift in Sources */,
433437
F42DE05623AD7D94007CCE29 /* SPAlertIconPrivacyView.swift in Sources */,
434438
F4CA67B5238ABD0100E72F79 /* SPAlertIconAddView.swift in Sources */,
435439
F41204EB2382AC9B009C2AC7 /* SPAlertIconHeartView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public enum SPAlertPreset {
4949
case dislike
5050
case privacy
5151
case cart
52+
case search
5253

5354
/**
5455
View for preset. Wrap to `UIView`.
@@ -101,6 +102,8 @@ public enum SPAlertPreset {
101102
return SPAlertIconPrivacyView()
102103
case .cart:
103104
return SPAlertIconCartView()
105+
case .search:
106+
return SPAlertIconSearchView()
104107
}
105108
}
106109

@@ -294,6 +297,14 @@ public enum SPAlertPreset {
294297
layout.iconHeight = 86
295298
layout.bottomIconSpace = 39
296299
return layout
300+
case .search:
301+
var layout = SPAlertLayout()
302+
layout.topSpace = 42
303+
layout.bottomSpace = 29
304+
layout.iconWidth = 98
305+
layout.iconHeight = 98
306+
layout.bottomIconSpace = 39
307+
return layout
297308
}
298309
}
299310

@@ -338,6 +349,8 @@ public enum SPAlertPreset {
338349
return .success
339350
case .card:
340351
return .success
352+
case .search:
353+
return .success
341354
case .rotate:
342355
return .success
343356
case .like:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 SPAlertIconSearchView: 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+
SearchDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class SearchDraw: 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: 61, height: 63), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 61, y: resizedFrame.height / 63)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 24.46, y: 49.92))
50+
bezierPath.addCurve(to: CGPoint(x: 38.1, y: 45.53), controlPoint1: CGPoint(x: 29.56, y: 49.92), controlPoint2: CGPoint(x: 34.26, y: 48.28))
51+
bezierPath.addLine(to: CGPoint(x: 52.56, y: 59.99))
52+
bezierPath.addCurve(to: CGPoint(x: 55.06, y: 61), controlPoint1: CGPoint(x: 53.23, y: 60.66), controlPoint2: CGPoint(x: 54.12, y: 61))
53+
bezierPath.addCurve(to: CGPoint(x: 58.45, y: 57.52), controlPoint1: CGPoint(x: 57.05, y: 61), controlPoint2: CGPoint(x: 58.45, y: 59.47))
54+
bezierPath.addCurve(to: CGPoint(x: 57.47, y: 55.08), controlPoint1: CGPoint(x: 58.45, y: 56.61), controlPoint2: CGPoint(x: 58.15, y: 55.75))
55+
bezierPath.addLine(to: CGPoint(x: 43.1, y: 40.68))
56+
bezierPath.addCurve(to: CGPoint(x: 47.92, y: 26.46), controlPoint1: CGPoint(x: 46.12, y: 36.71), controlPoint2: CGPoint(x: 47.92, y: 31.8))
57+
bezierPath.addCurve(to: CGPoint(x: 24.46, y: 3), controlPoint1: CGPoint(x: 47.92, y: 13.56), controlPoint2: CGPoint(x: 37.37, y: 3))
58+
bezierPath.addCurve(to: CGPoint(x: 1, y: 26.46), controlPoint1: CGPoint(x: 11.56, y: 3), controlPoint2: CGPoint(x: 1, y: 13.56))
59+
bezierPath.addCurve(to: CGPoint(x: 24.46, y: 49.92), controlPoint1: CGPoint(x: 1, y: 39.37), controlPoint2: CGPoint(x: 11.56, y: 49.92))
60+
bezierPath.close()
61+
bezierPath.move(to: CGPoint(x: 24.46, y: 44.86))
62+
bezierPath.addCurve(to: CGPoint(x: 6.06, y: 26.46), controlPoint1: CGPoint(x: 14.39, y: 44.86), controlPoint2: CGPoint(x: 6.06, y: 36.53))
63+
bezierPath.addCurve(to: CGPoint(x: 24.46, y: 8.06), controlPoint1: CGPoint(x: 6.06, y: 16.39), controlPoint2: CGPoint(x: 14.39, y: 8.06))
64+
bezierPath.addCurve(to: CGPoint(x: 42.86, y: 26.46), controlPoint1: CGPoint(x: 34.53, y: 8.06), controlPoint2: CGPoint(x: 42.86, y: 16.39))
65+
bezierPath.addCurve(to: CGPoint(x: 24.46, y: 44.86), controlPoint1: CGPoint(x: 42.86, y: 36.53), controlPoint2: CGPoint(x: 34.53, y: 44.86))
66+
bezierPath.close()
67+
fillColor.setFill()
68+
bezierPath.fill()
69+
70+
context.restoreGState()
71+
}
72+
73+
@objc(StyleKitNameResizingBehavior)
74+
public enum ResizingBehavior: Int {
75+
76+
case aspectFit
77+
case aspectFill
78+
case stretch
79+
case center
80+
81+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
82+
if rect == target || target == CGRect.zero {
83+
return rect
84+
}
85+
86+
var scales = CGSize.zero
87+
scales.width = abs(target.width / rect.width)
88+
scales.height = abs(target.height / rect.height)
89+
90+
switch self {
91+
case .aspectFit:
92+
scales.width = min(scales.width, scales.height)
93+
scales.height = scales.width
94+
case .aspectFill:
95+
scales.width = max(scales.width, scales.height)
96+
scales.height = scales.width
97+
case .stretch:
98+
break
99+
case .center:
100+
scales.width = 1
101+
scales.height = 1
102+
}
103+
104+
var result = rect.standardized
105+
result.size.width *= scales.width
106+
result.size.height *= scales.height
107+
result.origin.x = target.minX + (target.width - result.width) / 2
108+
result.origin.y = target.minY + (target.height - result.height) / 2
109+
return result
110+
}
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)