Skip to content

Commit e984d30

Browse files
committed
Adopt to UIAppearance support.
1 parent aa4ed5f commit e984d30

File tree

6 files changed

+37
-70
lines changed

6 files changed

+37
-70
lines changed

Example App/iOS Example/App/AppDelegate.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121

2222
import UIKit
2323
import SparrowKit
24+
import SPAlert
2425

2526
@UIApplicationMain
2627
class AppDelegate: SPAppWindowDelegate {
2728

2829
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2930
let rootController = PresetsController().wrapToNavigationController(prefersLargeTitles: false)
3031
makeKeyAndVisible(viewController: rootController, tint: .systemBlue)
32+
33+
// If need to change for all alerts.
34+
// SPAlertView.appearance().duration = 2
35+
// SPAlertView.appearance().cornerRadius = 8
36+
3137
return true
3238
}
3339
}

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ You can remove duration and completion, its have default values.
141141
Also you can change some default values for alerts. For example you can change default duration and corner radius for alert with next code:
142142

143143
```swift
144-
SPAlertConfiguration.duration = 2
145-
SPAlertConfiguration.cornerRadius = 12
144+
SPAlertView.appearance().duration = 2
145+
SPAlertView.appearance().cornerRadius = 12
146146
```
147147

148-
It will apply for all alerts. Shoud set configuration before present any alerts. I recomend set it in app delegate.
148+
It will apply for all alerts. I recomend set it in app delegate. But you can change it in runtime.
149149

150150
## SwiftUI
151151

@@ -192,17 +192,17 @@ I have libraries with native interface and managing permissions. Also available
192192
Со сложными и непонятными задачами помогут в чате.
193193

194194
<p float="left">
195-
<a href="https://sparrowcode.by/telegram/channel">
195+
<a href="https://tutorials.ivanvorobei.by/telegram/channel">
196196
<img src="https://github.com/ivanvorobei/Readme/blob/main/Buttons/russian-community-tutorials.svg">
197197
</a>
198-
<a href="https://sparrowcode.by/telegram/libs">
198+
<a href="https://tutorials.ivanvorobei.by/telegram/libs">
199199
<img src="https://github.com/ivanvorobei/Readme/blob/main/Buttons/russian-community-libraries.svg">
200200
</a>
201-
<a href="https://sparrowcode.by/telegram/chat">
201+
<a href="https://tutorials.ivanvorobei.by/telegram/chat">
202202
<img src="https://github.com/ivanvorobei/Readme/blob/main/Buttons/russian-community-chat.svg">
203203
</a>
204204
</p>
205205

206-
Видео-туториалы выклыдываю на [YouTube](https://sparrowcode.by/youtube):
206+
Видео-туториалы выклыдываю на [YouTube](https://tutorials.ivanvorobei.by/youtube):
207207

208-
[![Tutorials on YouTube](https://cdn.ivanvorobei.by/github/readme/youtube-preview.jpg)](https://sparrowcode.by/youtube)
208+
[![Tutorials on YouTube](https://cdn.ivanvorobei.by/github/readme/youtube-preview.jpg)](https://tutorials.ivanvorobei.by/youtube)

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 = '3.3.1'
4+
s.version = '3.4.0'
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 }

Sources/SPAlert/SPAlertConfiguration.swift

Lines changed: 0 additions & 59 deletions
This file was deleted.

Sources/SPAlert/SPAlertView.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ open class SPAlertView: UIView {
4141
open var dismissByTap: Bool = true
4242
open var completion: (() -> Void)? = nil
4343

44+
// MARK: - UIAppearance
45+
46+
@objc dynamic open var cornerRadius: CGFloat = 8 {
47+
didSet {
48+
layer.cornerRadius = self.cornerRadius
49+
}
50+
}
51+
52+
@objc dynamic open var duration: TimeInterval = 1.5
53+
4454
// MARK: - Views
4555

4656
open var titleLabel: UILabel?
@@ -91,15 +101,17 @@ open class SPAlertView: UIView {
91101
if #available(iOS 11.0, *) {
92102
insetsLayoutMarginsFromSafeArea = false
93103
}
104+
94105
layer.masksToBounds = true
95-
layer.cornerRadius = SPAlertConfiguration.cornerRadius
96106
backgroundColor = .clear
97107
addSubview(backgroundView)
98108

99109
if dismissByTap {
100110
let tapGesterRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismiss))
101111
addGestureRecognizer(tapGesterRecognizer)
102112
}
113+
114+
setCornerRadius(self.cornerRadius)
103115
}
104116

105117
// MARK: - Configure
@@ -134,6 +146,10 @@ open class SPAlertView: UIView {
134146
addSubview(view)
135147
}
136148

149+
private func setCornerRadius(_ value: CGFloat) {
150+
layer.cornerRadius = value
151+
}
152+
137153
// MARK: - Present
138154

139155
fileprivate var presentDismissDuration: TimeInterval = 0.2
@@ -157,7 +173,11 @@ open class SPAlertView: UIView {
157173
}
158174
}
159175

160-
open func present(duration: TimeInterval = SPAlertConfiguration.duration, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
176+
open func present(haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
177+
present(duration: self.duration, haptic: haptic, completion: completion)
178+
}
179+
180+
open func present(duration: TimeInterval, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
161181

162182
if self.presentWindow == nil {
163183
self.presentWindow = UIApplication.shared.keyWindow

0 commit comments

Comments
 (0)