Skip to content

Commit 8488acb

Browse files
committed
Clean Dimmed button. Added colors. Added layout methods.
1 parent 98704ec commit 8488acb

File tree

9 files changed

+382
-169
lines changed

9 files changed

+382
-169
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 SPDimmedButton {
26+
27+
/**
28+
SparrowKit: Button state.
29+
*/
30+
public enum AppearanceState {
31+
32+
/**
33+
SparrowKit: The button is in the normal state.
34+
*/
35+
case `default`
36+
37+
/**
38+
SparrowKit: The button is in a dimmed state, for example when another `UIViewController` is presented.
39+
*/
40+
case dimmed
41+
42+
/**
43+
SparrowKit: The button is disabled. Controlled through the `isDisabled` property.
44+
*/
45+
case disabled
46+
}
47+
}
48+
#endif
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 SPDimmedButton {
26+
27+
/**
28+
SparrowKit: Represent colors for state of button for elements.
29+
*/
30+
public struct Colorise {
31+
32+
public var title: Mode
33+
public var icon: Mode
34+
public var background: Mode
35+
36+
/**
37+
SparrowKit: This init allow create colorise with automatically tint oberving.
38+
39+
- parameter content: Colorise mode for `title` & `icon`.
40+
- parameter background: Colorise mode for background.
41+
*/
42+
public init(content: Mode, background: Mode) {
43+
self.title = content
44+
self.icon = content
45+
self.background = background
46+
}
47+
48+
/**
49+
- parameter content: Color for `title` & `icon`.
50+
- parameter background: Color for background.
51+
*/
52+
public init(content: UIColor, background: UIColor) {
53+
self.title = .custom(content)
54+
self.icon = .custom(content)
55+
self.background = .custom(background)
56+
}
57+
58+
/**
59+
- parameter content: Color for `title` & `icon`.
60+
- parameter background: Color for image.
61+
- parameter background: Color for background.
62+
*/
63+
public init(content: UIColor, icon: UIColor, background: UIColor) {
64+
self.title = .custom(content)
65+
self.icon = .custom(icon)
66+
self.background = .custom(background)
67+
}
68+
69+
/**
70+
SparrowKit: Represent of rendering colors in button.
71+
72+
It need for have dynamic tint color and fixed custom.
73+
*/
74+
public enum Mode {
75+
76+
/**
77+
SparrowKit: Always specific color.
78+
*/
79+
case custom(UIColor)
80+
81+
/**
82+
SparrowKit: Observe and apply tint color of button.
83+
*/
84+
case tint
85+
86+
/**
87+
SparrowKit: Observe and apply secondary tint color of button.
88+
*/
89+
case secondaryTint
90+
}
91+
92+
// MARK: - Ready Use
93+
94+
public static var tintedContent: Colorise {
95+
return .init(content: .tint, background: .custom(.clear))
96+
}
97+
98+
public static var tintedColorful: Colorise {
99+
return .init(content: .custom(.white), background: .tint)
100+
}
101+
102+
public static var tinted: Colorise {
103+
return .init(content: .tint, background: .secondaryTint)
104+
}
105+
}
106+
}
107+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 SPDimmedButton {
26+
27+
public enum HiglightStyle {
28+
29+
case content
30+
case background
31+
32+
static var `default`: HiglightStyle {
33+
return .background
34+
}
35+
}
36+
}
37+
#endif

0 commit comments

Comments
 (0)