Below is the code
Post
Replies
Boosts
Views
Activity
Content View
import SwiftUI
import UIKit
import WrappingStack
extension UIScreen{
static let screenWidth = UIScreen.main.bounds.size.width
static let screenHeight = UIScreen.main.bounds.size.height
static let screenSize = UIScreen.main.bounds.size
}
struct ContentView: View {
@State private var buttons = 0
@State var breath = true
@State var fn=0
@State var filename=""
@State var array:[String] = ["Button"]
@State var array1:[Bool]=[true,true]
@State var Hstack=1
@State var b=""
@State private var isEditing = true
@State var a = 0
@State var color = Color.blue
@State var ca:[Color]=[Color.blue]
var body: some View {
// the button to add other buttons
VStack(alignment: .trailing, spacing: -35)
{
//
Button(action:{
engine.stop()
} ) {
Text("Pause")
.frame(width: UIScreen.screenWidth, height: UIScreen.screenHeight/4)
.accentColor(.black)
.font(.largeTitle)
.cornerRadius(12.5)
}.background(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=View@*/Color.white/*@END_MENU_TOKEN@*/)
Button(action: {
buttons += 1
} ) {
Image(systemName: "plus.circle.fill").foregroundColor(.red)
.font(.largeTitle)
//.hoverEffect()
}
//the added buttons
//ForEach(0..<Hstack, id: \.self)
//{g in
Text("i")
.foregroundColor(Color("black"))
.font(.largeTitle)
}
WrappingHStack(id: \.self,horizontalSpacing:10,verticalSpacing:10) { // use the same id is in the `ForEach` below
ForEach(0..<buttons, id: \.self) { i in
Button(array[i]+" ( \(i) )") {
a=buttons%7
array1.append(true)
print("hi")
do{print(array[i])
try play(array[i])
}
catch{
print("error")
}
}
.frame(width: (UIScreen.screenWidth/5)-10, height: UIScreen.screenHeight/7)
.accentColor(.black)
.font(.title)
.background(ca[i])
.contextMenu
{
Button(action: {
buttons-=1
let removed = array.remove(at: i)
let removed1 = array1.remove(at: i)
let removed2 = ca.remove(at: i)
}) {
Text("Remove")
.foregroundColor(.red) // Not working
Image(systemName: "trash")
}
Button("Red Button") {
ca.insert(Color.red,at: i)
}
Button("Blue Button") {
ca.insert(Color.blue,at: i)
}
Button("Green Button") {
ca.insert(Color.green,at: i)
}
Button("Orange Button") {
ca.insert(Color.orange,at: i)
}
Button("White Button") {
ca.insert(Color.white,at: i)
}
}
.cornerRadius(12.5)
.fileImporter(isPresented: $array1[i], allowedContentTypes: [.audio]) { result in
do{
let fileurl=try result.get()
print(fileurl)
filename=fileurl.lastPathComponent
array.insert(filename, at: i)
}
catch{
print("error")
}
array1.insert(true, at: i+1)
ca.insert(Color.blue, at: i+1)
print(array.count)
}
}
}
VStack{
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}