-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVText.swift
84 lines (71 loc) · 2.81 KB
/
VText.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import SwiftUI
public struct VText : View {
@State var text : String
var fontWeight : FontWeight = FontWeight(rawValue: "") ?? .medium
var fontSize : CGFloat = 17
var spacing : CGFloat = 6
var alignment : HorizontalAlignment = .leading
public init(text : State<String> ,fontWeight: FontWeight = FontWeight(rawValue: "") ?? .medium, fontSize: CGFloat = 17, spacing: CGFloat = 6, alignment: HorizontalAlignment = .leading) {
self._text = text
self.fontWeight = fontWeight
self.fontSize = fontSize
self.spacing = spacing
self.alignment = alignment
}
@State private var textIndex : [String] = []
public var body: some View{
VStack(alignment: alignment, spacing: spacing){
ForEach(Array(zip(textIndex, 0 ..< textIndex.count)), id: \.0) { item in
switch fontWeight.rawValue{
case "light" :
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.light)
case "regular":
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.regular)
case "medium":
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.medium)
case "bold":
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.bold)
case "heavy":
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.heavy)
case "black":
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.black)
default:
Text(textIndex[item.1])
.font(.system(size: fontSize))
.fontWeight(.regular)
}
}
}
.onAppear{
for i in 0 ..< text.count {
textIndex.append(String(text[text.index(text.startIndex, offsetBy: i)]))
}
}
.onChange(of: text) { newValue in
textIndex = []
for i in 0 ..< text.count {
textIndex.append(String(text[text.index(text.startIndex, offsetBy: i)]))
}
}
}
}
public enum FontWeight: String {
case light = "light"
case regular = "regular"
case medium = "medium"
case bold = "bold"
case heavy = "heavy"
case black = "black"
}