hello

I want to create an application with a counter and a number so that every time I press the button the number increases 1 2 0 .. Then I want to call the lighting feature and set it -9 so that the screen is completely dark, but the button remains on! I want to link the lights to a button as a kind of energy saving so that when I press it, the screen turns off while the application and the button remain on





I don't think there is a way to adjust lighting but here is how to make a counter
Code Block
@State var counter: Int = 0
    var body: some View {
        VStack {
            Text("\(counter)")
            Button("Count Up") {
                counter += 1
            }
            
            Button("Count Down") {
                counter -= 1
            }
         
        }
     


there is a way to adjust the device brightness by pressing a button but that will not work like you want it to.
I will try to do justice to it, show it to me
I tried it, the screen turned off and the button stayed on, but I couldn't connect the brightness to a button
Because I don't know how
At first I was going to link the button and the counter with the volume up and down button, but it is forbidden, then I got this idea




















You cannot change a button behaviour. That's forbidden.

But to control brightness:
        UIScreen.main.brightness = 0.1 // between 0 and 1

Could you place the order here please


Code Block
@State var counter: Int = 0 
  var body: some View {   
    VStack {     
      Text("\(counter)") 
          Button("Count Up") {                counter += 1            }                        Button("Count Down") {                counter -= 1            }                 }     
Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols

I am showing this error





What did you post ? Could you edit it properly so we can understand what it is ?
ZStack {

            LinearGradient(gradient: Gradient(colors: [Color.orange, Color.yellow, Color.white]), startPoint: .top, endPoint: .bottom)



                .edgesIgnoringSafeArea(.all)

                SwiftUIView()

                boton()

          

                    .font(Font.system(size: 80))

                    .offset(x: 10, y: -10)

            

        }

        UIScreen.main.brightness = 0.1 // between 0 and 1





    }

}

struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}
Please,
  • explain what is your question

  • take some care when you post code to make it easier to read:

Code Block
ZStack {
LinearGradient(gradient: Gradient(colors: [Color.orange, Color.yellow, Color.white]), startPoint: .top, endPoint: .bottom)
.edgesIgnoringSafeArea(.all)
SwiftUIView()
boton()
.font(Font.system(size: 80))
.offset(x: 10, y: -10)
}
UIScreen.main.brightness = 0.1 // between 0 and 1
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}


what do you do with line 12, copied in the middle of the code ? It should be inside some func (like a Button action)
what is boton() ?

import SwiftUI




struct boton: View {

    

    @State var boton : String = "S"

    var body: some View {

        

                

        

        VStack {

            

            Text("bnvnb: \(boton)")

            

            Button(action: {

                self.boton = self.boton + "S"

                        

            } ) {

                

                /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/

                    

            }

            

        }

        

    }

    

}

Code Block
 

This is the button file you recalled






I don't know how to arrange the text Sorry, but I want to control the brightness. Can you create a code and slider ?
How was this important code with the lighting control feature so that the user can modify the lighting from within the application, not through the system by pulling the tape!










hello
 
 
Q