Skip to content

Commit 1612b23

Browse files
committed
Add .rotate preset
1 parent 779c374 commit 1612b23

File tree

8 files changed

+151
-1
lines changed

8 files changed

+151
-1
lines changed

Assets/Readme/Miniature - Rotate.svg

Lines changed: 10 additions & 0 deletions
Loading

Assets/Sketch/Presets.sketch

2.5 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: "Rotate", preset: .rotate, title: "Portrait mode", subtitle: "You can change it in settings"),
2021
Alert(key: "Magic", preset: .magic, title: "Magic here! You see", subtitle: "Strange text, true?"),
2122
Alert(key: "Add", preset: .add, title: "Added to Folder", subtitle: nil),
2223
Alert(key: "Error", preset: .error, title: "Oops", subtitle: "Please try again later"),

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-%20Rotate.svg" width="55">
2526
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Magic.svg" width="55">
2627
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Add.svg" width="55">
2728
<img src="https://github.com/ivanvorobei/SPAlert/blob/master/Assets/Readme/Miniature%20-%20Error.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.21"
4+
s.version = "2.0.22"
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
@@ -26,6 +26,7 @@
2626
F412052B2382AF64009C2AC7 /* SPAlertLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41205222382AEFA009C2AC7 /* SPAlertLayout.swift */; };
2727
F421EFF12398684E000A566D /* SPAlertIconFlagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */; };
2828
F45970B423A578A50092CE7C /* SPAlertIconCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */; };
29+
F459720223A841C00092CE7C /* SPAlertIconRotateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */; };
2930
F46AAEFE2392E97200BE9131 /* SPAlertIconMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */; };
3031
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */; };
3132
F47EE19D23959ADB00B02DF2 /* SPAlertIconShuffleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */; };
@@ -92,6 +93,7 @@
9293
F41205262382AF29009C2AC7 /* SPAlertIconAnimatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconAnimatable.swift; sourceTree = "<group>"; };
9394
F421EFF02398684E000A566D /* SPAlertIconFlagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconFlagView.swift; sourceTree = "<group>"; };
9495
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconCardView.swift; sourceTree = "<group>"; };
96+
F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconRotateView.swift; sourceTree = "<group>"; };
9597
F46AAEFD2392E97200BE9131 /* SPAlertIconMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconMessageView.swift; sourceTree = "<group>"; };
9698
F47D2FA5239D718400A346A5 /* SPAlertIconBoltView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconBoltView.swift; sourceTree = "<group>"; };
9799
F47EE19C23959ADB00B02DF2 /* SPAlertIconShuffleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPAlertIconShuffleView.swift; sourceTree = "<group>"; };
@@ -199,6 +201,7 @@
199201
F4CD29F323A037D00051EA23 /* SPAlertIconMagicView.swift */,
200202
F4D1623323A2E47200B5E3E9 /* SPAlertIconEjectView.swift */,
201203
F45970B323A578A50092CE7C /* SPAlertIconCardView.swift */,
204+
F459720123A841C00092CE7C /* SPAlertIconRotateView.swift */,
202205
);
203206
path = Icons;
204207
sourceTree = "<group>";
@@ -398,6 +401,7 @@
398401
F41204EE2382AC9B009C2AC7 /* SPAlert.swift in Sources */,
399402
F40FB62A239ADF940090BA57 /* SPAlertIconQuestionView.swift in Sources */,
400403
F4E4459D2390524A0067FF5C /* SPAlertIconExclamationView.swift in Sources */,
404+
F459720223A841C00092CE7C /* SPAlertIconRotateView.swift in Sources */,
401405
F41204EA2382AC9B009C2AC7 /* SPAlertPreset.swift in Sources */,
402406
F4A5A92C2388792F00B0DFE0 /* SPAlertIconBookmarkView.swift in Sources */,
403407
F47D2FA6239D718400A346A5 /* SPAlertIconBoltView.swift in Sources */,

Source/SPAlert/Models/SPAlertPreset.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public enum SPAlertPreset {
4444
case magic
4545
case eject
4646
case card
47+
case rotate
4748

4849
/**
4950
View for preset. Wrap to `UIView`.
@@ -86,6 +87,8 @@ public enum SPAlertPreset {
8687
return SPAlertIconEjectView()
8788
case .card:
8889
return SPAlertIconCardView()
90+
case .rotate:
91+
return SPAlertIconRotateView()
8992
}
9093
}
9194

@@ -143,6 +146,14 @@ public enum SPAlertPreset {
143146
layout.iconHeight = 77
144147
layout.bottomIconSpace = 35
145148
return layout
149+
case .rotate:
150+
var layout = SPAlertLayout()
151+
layout.topSpace = 46
152+
layout.bottomSpace = 29
153+
layout.iconWidth = 112
154+
layout.iconHeight = 112
155+
layout.bottomIconSpace = 35
156+
return layout
146157
case .eject:
147158
var layout = SPAlertLayout()
148159
layout.topSpace = 48
@@ -283,6 +294,8 @@ public enum SPAlertPreset {
283294
return .success
284295
case .card:
285296
return .success
297+
case .rotate:
298+
return .success
286299
}
287300
}
288301
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 SPAlertIconRotateView: 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+
RotateDraw.draw(frame: rect, resizing: .aspectFit, fillColor: self.tintColor)
38+
}
39+
40+
class RotateDraw: 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: 71), target: targetFrame)
46+
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
47+
context.scaleBy(x: resizedFrame.width / 62, y: resizedFrame.height / 71)
48+
let bezierPath = UIBezierPath()
49+
bezierPath.move(to: CGPoint(x: 7.69, y: 32.39))
50+
bezierPath.addCurve(to: CGPoint(x: 8.52, y: 30.88), controlPoint1: CGPoint(x: 8.28, y: 32.09), controlPoint2: CGPoint(x: 8.58, y: 31.63))
51+
bezierPath.addCurve(to: CGPoint(x: 7.37, y: 24.98), controlPoint1: CGPoint(x: 8.47, y: 29.91), controlPoint2: CGPoint(x: 7.37, y: 28.56))
52+
bezierPath.addCurve(to: CGPoint(x: 16.61, y: 15.16), controlPoint1: CGPoint(x: 7.37, y: 19.31), controlPoint2: CGPoint(x: 10.94, y: 15.29))
53+
bezierPath.addLine(to: CGPoint(x: 16.95, y: 15.15))
54+
bezierPath.addLine(to: CGPoint(x: 16.95, y: 18.87))
55+
bezierPath.addCurve(to: CGPoint(x: 20.11, y: 20.37), controlPoint1: CGPoint(x: 16.95, y: 20.94), controlPoint2: CGPoint(x: 18.56, y: 21.45))
56+
bezierPath.addLine(to: CGPoint(x: 27.62, y: 14.91))
57+
bezierPath.addCurve(to: CGPoint(x: 27.62, y: 12.06), controlPoint1: CGPoint(x: 28.83, y: 14.02), controlPoint2: CGPoint(x: 28.83, y: 12.97))
58+
bezierPath.addLine(to: CGPoint(x: 20.24, y: 6.67))
59+
bezierPath.addCurve(to: CGPoint(x: 16.95, y: 8.1), controlPoint1: CGPoint(x: 18.62, y: 5.43), controlPoint2: CGPoint(x: 16.95, y: 5.91))
60+
bezierPath.addLine(to: CGPoint(x: 16.95, y: 12.06))
61+
bezierPath.addLine(to: CGPoint(x: 16.87, y: 12.06))
62+
bezierPath.addCurve(to: CGPoint(x: 4, y: 24.96), controlPoint1: CGPoint(x: 9.14, y: 12.06), controlPoint2: CGPoint(x: 4, y: 17.25))
63+
bezierPath.addCurve(to: CGPoint(x: 5.4, y: 31.63), controlPoint1: CGPoint(x: 4, y: 27.84), controlPoint2: CGPoint(x: 4.59, y: 30.21))
64+
bezierPath.addCurve(to: CGPoint(x: 7.69, y: 32.39), controlPoint1: CGPoint(x: 5.89, y: 32.42), controlPoint2: CGPoint(x: 6.85, y: 32.79))
65+
bezierPath.close()
66+
bezierPath.move(to: CGPoint(x: 51.05, y: 66))
67+
bezierPath.addLine(to: CGPoint(x: 24.33, y: 66))
68+
bezierPath.addCurve(to: CGPoint(x: 17.44, y: 59.08), controlPoint1: CGPoint(x: 19.73, y: 66), controlPoint2: CGPoint(x: 17.44, y: 63.79))
69+
bezierPath.addLine(to: CGPoint(x: 17.44, y: 32.44))
70+
bezierPath.addCurve(to: CGPoint(x: 24.33, y: 25.52), controlPoint1: CGPoint(x: 17.44, y: 27.73), controlPoint2: CGPoint(x: 19.73, y: 25.52))
71+
bezierPath.addLine(to: CGPoint(x: 51.05, y: 25.52))
72+
bezierPath.addCurve(to: CGPoint(x: 57.94, y: 32.44), controlPoint1: CGPoint(x: 55.66, y: 25.52), controlPoint2: CGPoint(x: 57.94, y: 27.73))
73+
bezierPath.addLine(to: CGPoint(x: 57.94, y: 59.08))
74+
bezierPath.addCurve(to: CGPoint(x: 51.05, y: 66), controlPoint1: CGPoint(x: 57.94, y: 63.79), controlPoint2: CGPoint(x: 55.66, y: 66))
75+
bezierPath.close()
76+
fillColor.setFill()
77+
bezierPath.fill()
78+
context.restoreGState()
79+
}
80+
81+
@objc(StyleKitNameResizingBehavior)
82+
public enum ResizingBehavior: Int {
83+
84+
case aspectFit
85+
case aspectFill
86+
case stretch
87+
case center
88+
89+
public func apply(rect: CGRect, target: CGRect) -> CGRect {
90+
if rect == target || target == CGRect.zero {
91+
return rect
92+
}
93+
94+
var scales = CGSize.zero
95+
scales.width = abs(target.width / rect.width)
96+
scales.height = abs(target.height / rect.height)
97+
98+
switch self {
99+
case .aspectFit:
100+
scales.width = min(scales.width, scales.height)
101+
scales.height = scales.width
102+
case .aspectFill:
103+
scales.width = max(scales.width, scales.height)
104+
scales.height = scales.width
105+
case .stretch:
106+
break
107+
case .center:
108+
scales.width = 1
109+
scales.height = 1
110+
}
111+
112+
var result = rect.standardized
113+
result.size.width *= scales.width
114+
result.size.height *= scales.height
115+
result.origin.x = target.minX + (target.width - result.width) / 2
116+
result.origin.y = target.minY + (target.height - result.height) / 2
117+
return result
118+
}
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)