Skip to content

Commit 5c29465

Browse files
committed
Added appearance to UITabBar.
1 parent 0245399 commit 5c29465

File tree

4 files changed

+97
-13
lines changed

4 files changed

+97
-13
lines changed

Sources/SparrowKit/UIKit/Extensions/UINavigationBarExtension.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#if canImport(UIKit) && (os(iOS) || os(tvOS))
2323
import UIKit
2424

25-
public extension UINavigationBar {
25+
extension UINavigationBar {
2626

2727
/**
2828
SparrowKit: Change font of title.
2929

3030
- parameter font: New font of title.
3131
*/
32-
func setTitleFont(_ font: UIFont) {
32+
open func setTitleFont(_ font: UIFont) {
3333
titleTextAttributes = [.font: font]
3434
}
3535

@@ -38,7 +38,7 @@ public extension UINavigationBar {
3838

3939
- parameter color: New color of title.
4040
*/
41-
func setTitleColor(_ color: UIColor) {
41+
open func setTitleColor(_ color: UIColor) {
4242
titleTextAttributes = [.foregroundColor: color]
4343
}
4444

@@ -48,7 +48,7 @@ public extension UINavigationBar {
4848
- parameter backgroundColor: New background color of navigation.
4949
- parameter textColor: New text color of title.
5050
*/
51-
func setColors(backgroundColor: UIColor, textColor: UIColor) {
51+
open func setColors(backgroundColor: UIColor, textColor: UIColor) {
5252
isTranslucent = false
5353
self.backgroundColor = backgroundColor
5454
barTintColor = backgroundColor
@@ -60,7 +60,7 @@ public extension UINavigationBar {
6060
/**
6161
SparrowKit: Make transparent of background of navigation.
6262
*/
63-
func makeTransparent() {
63+
open func makeTransparent() {
6464
isTranslucent = true
6565
backgroundColor = .clear
6666
barTintColor = .clear
@@ -71,7 +71,8 @@ public extension UINavigationBar {
7171
/**
7272
SparrowKit: Set opacity for background view.
7373
*/
74-
func setBackgroundAlpha(_ value: CGFloat) {
74+
@available(*, deprecated, message: "Use appearance")
75+
open func setBackgroundAlpha(_ value: CGFloat) {
7576
for (index, view) in subviews.enumerated() {
7677
// Hide background for navigation bar.
7778
// Usually it first view.
@@ -81,26 +82,26 @@ public extension UINavigationBar {
8182
}
8283
}
8384

84-
@available(iOS 13.0, tvOS 13.0, *)
8585
/**
8686
SparrowKit: Set appearance for navigation bar.
8787
*/
88-
func setAppearance(_ value: SPNavigationBarAppearance) {
88+
@available(iOS 13.0, tvOS 13.0, *)
89+
open func setAppearance(_ value: SPNavigationBarAppearance) {
8990
self.standardAppearance = value.standardAppearance
9091
self.scrollEdgeAppearance = value.scrollEdgeAppearance
9192
}
9293

93-
@available(iOS 13.0, tvOS 13.0, *)
9494
/**
9595
SparrowKit: Appearance cases.
9696
*/
97-
enum SPNavigationBarAppearance {
97+
@available(iOS 13.0, tvOS 13.0, *)
98+
public enum SPNavigationBarAppearance {
9899

99100
case transparentAlways
100101
case transparentStandardOnly
101102
case opaqueAlways
102103

103-
var standardAppearance: UINavigationBarAppearance {
104+
public var standardAppearance: UINavigationBarAppearance {
104105
switch self {
105106
case .transparentAlways:
106107
let appearance = UINavigationBarAppearance()
@@ -117,7 +118,7 @@ public extension UINavigationBar {
117118
}
118119
}
119120

120-
var scrollEdgeAppearance: UINavigationBarAppearance {
121+
public var scrollEdgeAppearance: UINavigationBarAppearance {
121122
switch self {
122123
case .transparentAlways:
123124
let appearance = UINavigationBarAppearance()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 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+
#if canImport(UIKit) && (os(iOS) || os(tvOS))
23+
import UIKit
24+
25+
extension UITabBar {
26+
27+
/**
28+
SparrowKit: Set appearance for tab bar.
29+
*/
30+
@available(iOS 13.0, tvOS 13.0, *)
31+
open func setAppearance(_ value: SPTabBarAppearance) {
32+
self.standardAppearance = value.standardAppearance
33+
if #available(iOS 15.0, *) {
34+
self.scrollEdgeAppearance = value.scrollEdgeAppearance
35+
}
36+
}
37+
38+
/**
39+
SparrowKit: Appearance cases.
40+
*/
41+
@available(iOS 13.0, tvOS 13.0, *)
42+
public enum SPTabBarAppearance {
43+
44+
case transparentAlways
45+
case transparentStandardOnly
46+
case opaqueAlways
47+
48+
public var standardAppearance: UITabBarAppearance {
49+
switch self {
50+
case .transparentAlways:
51+
let appearance = UITabBarAppearance()
52+
appearance.configureWithTransparentBackground()
53+
return appearance
54+
case .transparentStandardOnly:
55+
let appearance = UITabBarAppearance()
56+
appearance.configureWithDefaultBackground()
57+
return appearance
58+
case .opaqueAlways:
59+
let appearance = UITabBarAppearance()
60+
appearance.configureWithDefaultBackground()
61+
return appearance
62+
}
63+
}
64+
65+
public var scrollEdgeAppearance: UITabBarAppearance {
66+
switch self {
67+
case .transparentAlways:
68+
let appearance = UITabBarAppearance()
69+
appearance.configureWithTransparentBackground()
70+
return appearance
71+
case .transparentStandardOnly:
72+
let appearance = UITabBarAppearance()
73+
appearance.configureWithTransparentBackground()
74+
return appearance
75+
case .opaqueAlways:
76+
let appearance = UITabBarAppearance()
77+
appearance.configureWithDefaultBackground()
78+
return appearance
79+
}
80+
}
81+
}
82+
}
83+
#endif

SparrowKit.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 = 'SparrowKit'
4-
s.version = '3.4.3'
4+
s.version = '3.4.4'
55
s.summary = 'Collection of native Swift extensions to boost your development. Support tvOS and watchOS.'
66
s.homepage = 'https://github.com/ivanvorobei/SparrowKit'
77
s.source = { :git => 'https://github.com/ivanvorobei/SparrowKit.git', :tag => s.version }

0 commit comments

Comments
 (0)