import SwiftUI
struct S1: View {
@State var aa = 0
var body: some View {
TabView{
S2(aa: $aa)
.tabItem {
Image(systemName: "person.fill")
Text("1")
}
.toolbarBackground(.visible, for: .tabBar)
.toolbarBackground(.ultraThickMaterial, for: .tabBar)
S3(aa: $aa)
.tabItem {
Image(systemName: "person.fill")
Text("2")
}
.toolbarBackground(.visible, for: .tabBar)
.toolbarBackground(.ultraThickMaterial, for: .tabBar)
}
}
}
struct S1_Previews: PreviewProvider {
static var previews: some View {
S1()
}
}
import SwiftUI
struct S2: View {
@State var bb = 0
@Binding var aa: Int
var body: some View {
VStack{
HStack{
Button {
aa += 1
if aa > bb {
bb += 1
}
} label: {
Text("+")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
Button {
aa -= 1
if aa < bb {
bb -= 1
}
} label: {
Text("-")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
}
Text(String(bb))
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility3)
}
.onChange(of: aa) { newValue in
if aa > bb {
bb += 1
} else if aa < bb {
bb -= 1
}
}
}
}
struct S2_Previews: PreviewProvider {
static var previews: some View {
S2(aa: .constant(0))
}
}
import SwiftUI
struct S3: View {
@Binding var aa: Int
var body: some View {
HStack{
Button {
aa += 1
} label: {
Text("+")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
Button {
aa -= 1
} label: {
Text("-")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
}
}
}
struct S3_Previews: PreviewProvider {
static var previews: some View {
S3(aa: .constant(0))
}
}