[ad_1]
I’m creating the app for IOS and I’m the primary time utilizing SwiftUI, only a newbie.
The issue is that I attempt to change the values of Textual content() by button click on which can be made through the use of ForEach Identifiable. All the pieces is good however that is the one factor that I can’t do and discover a solution for my self on web.
Right here is my code
import SwiftUI
non-public struct SizePreferenceKey: PreferenceKey {
static var defaultValue: CGSize = .zero
static func cut back(worth: inout CGSize, nextValue: () -> CGSize) {}
}
public struct SemaphoreFlags: View {
@State non-public var headerHeight = CGSize()
public var physique: some View {
ZStack{
Picture("background")
.resizable()
.scaledToFill()
.body(maxWidth: UIScreen.screenWidth, maxHeight: UIScreen.screenHeight )
.edgesIgnoringSafeArea(.backside)
VStack{
Picture("header_inv")
.resizable()
.aspectRatio(contentMode: .match)
.body(maxWidth: UIScreen.screenWidth ,alignment: .high)
.opacity(0.0)
.readSize {
peak in headerHeight = peak
}.padding(.backside, 16)
Textual content("HEADER TEXT")
.foregroundColor(.white)
.font(.system(dimension: 24))
.fontWeight(.medium)
.body(width: UIScreen.screenWidth - 25, peak: UIScreen.screenWidth / 6, alignment: .middle)
.background(Shade(purple: 0.29, inexperienced: 0.67, blue: 0.88))
.padding(.backside, 4.0)
ScrollView{
Textual content(NSLocalizedString("BeaufortScale_Description", remark: "BeaufortScale_Description"))
.font(.system(dimension: 20))
.multilineTextAlignment(.middle)
.background(Shade.white)
.padding(.horizontal,8)
.foregroundColor(.black)
.body(width: .infinity, peak: .infinity)
}
Picture("clean")
.resizable()
.aspectRatio(contentMode: .match)
.body(width: UIScreen.screenWidth - 25, peak: UIScreen.screenWidth / 2, alignment: .middle)
Textual content("BottomLETTER")
.font(.system(dimension: UIScreen.screenWidth/6))
.fontWeight(.medium)
.multilineTextAlignment(.middle)
.foregroundColor(Shade(purple: 0.09, inexperienced: 0.30, blue: 0.47))
.body(width: UIScreen.screenWidth, peak: .infinity, alignment: .middle)
Spacer()
ScrollView(.horizontal, showsIndicators: false){
HStack{
ForEach(semaphoreButtonPropsData) { merchandise in
semaphoreFlagsButton(SemaphoreButtonProps: merchandise)
}
}
}.clipped().edgesIgnoringSafeArea(.backside).padding(.vertical)
}.body(width: .infinity, peak: .infinity)
Picture("header")
.resizable()
.aspectRatio(contentMode: .match)
.body(maxWidth: UIScreen.screenWidth, maxHeight: UIScreen.screenHeight ,alignment: .high)
VStack {
HStack {
Button (motion: gotoMenu, label: {
Picture("again")
.resizable()
.aspectRatio(contentMode: .match)
.body(width: 32, peak: headerHeight.peak)
.padding(.main, 16.0)
})
Spacer()
}
Spacer()
}
}.background(Shade(purple: 0.09, inexperienced: 0.30, blue: 0.47).edgesIgnoringSafeArea(.all))
}
}
struct SemaphoreFlags_Previews: PreviewProvider {
static var previews: some View {
SemaphoreFlags()
}
}
struct semaphoreFlagsButton: View {
var SemaphoreButtonProps: semaphoreButtonProps
var physique: some View {
Button(motion:{
// ACTION TO CHANGE THE VALUES OF DESIGN
(HEADER TEXT, DESCRIPTION, IMAGE, BOTTOM LETTER)
}, label: {
Textual content(SemaphoreButtonProps.buttonLetter)
.font(.system(dimension: 26))
.fontWeight(.gentle)
.foregroundColor(Shade.white)
.multilineTextAlignment(.main)
.padding(.all, 4.0)
.foregroundColor(.white)
.body(width: .infinity, peak: 50, alignment: .middle)
})
.body(width: 100, peak: 50 , alignment: .middle)
.background(Shade(purple: 0.29, inexperienced: 0.67, blue: 0.88))
.cornerRadius(12)
.padding(.main, 8)
}
}
struct semaphoreButtonProps: Identifiable {
var id = UUID()
var headerText: String
var description: String
var picture: Picture
var bottomLetter: String
var buttonLetter: String
}
let semaphoreButtonPropsData = [
semaphoreButtonProps(headerText: "About",
description: NSLocalizedString("BeaufortScale_Description", comment: "BeaufortScale_Description"),
image: Image("blank"),
bottomLetter: " ",
buttonLetter: "About"),
semaphoreButtonProps(headerText: "Alpha",
description: " ",
image: Image("a-alpha"),
bottomLetter: "A",
buttonLetter: "A"),
semaphoreButtonProps(headerText: "Bravo",
description: " ",
image: Image("b-bravo"),
bottomLetter: "B",
buttonLetter: "B")
]
Huge Thanks!
[ad_2]
