-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
KeyboardIconView.swift
69 lines (63 loc) · 2.02 KB
/
KeyboardIconView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import SwiftUI
struct KeyboardIconView: View {
@Environment(\.colorScheme) var colorScheme
let size: CGFloat
let letter: String
init(_ letter: String = "", size: CGFloat) {
self.size = size
self.letter = letter
}
var body: some View {
Rectangle()
.fill(Color(.textBackgroundColor))
.overlay { iconOverlay().opacity(0.2) }
.overlay {
AngularGradient(stops: [
.init(color: Color.clear, location: 0.0),
.init(color: Color.white.opacity(0.2), location: 0.2),
.init(color: Color.clear, location: 1.0),
], center: .bottomLeading)
LinearGradient(stops: [
.init(color: Color.white.opacity(0.1), location: 0),
.init(color: Color.clear, location: 0.02),
], startPoint: .top, endPoint: .bottom)
LinearGradient(stops: [
.init(color: Color.clear, location: 0.99),
.init(color: Color(.windowBackgroundColor), location: 1.0),
], startPoint: .top, endPoint: .bottom)
}
.overlay { iconBorder(size).opacity(0.5) }
.overlay {
Text(letter)
.font(Font.system(size: size * 0.3, weight: .regular, design: .rounded))
.allowsTightening(true)
.minimumScaleFactor(0.2)
}
.frame(width: size, height: size)
.fixedSize()
.drawingGroup(opaque: true)
.iconShape(size)
// .background(
// Rectangle()
// .fill(Color.black.opacity( colorScheme == .light ? 0.33 : 0.9 ))
// .clipShape(RoundedRectangle(cornerRadius: size * 0.125))
// .offset(x: 0, y: size * 0.025)
// .scaleEffect(x: 0.95)
// .blur(radius: 1)
// )
}
}
#Preview {
HStack(alignment: .top, spacing: 8) {
KeyboardIconView("M", size: 192)
VStack(alignment: .leading, spacing: 8) {
KeyboardIconView("O", size: 128)
HStack(alignment: .top, spacing: 8) {
KeyboardIconView("L", size: 64)
KeyboardIconView("L", size: 32)
KeyboardIconView("Y", size: 16)
}
}
}
.padding()
}