var body: some View {\n VStack {\n Text("SoDuKu!")\n .font(.custom("Arial Rounded MT Bold", size: 40))\n .foregroundColor(Color(red: 1, green: 0.471, blue: 0.329))\n \n let borderSize = CGFloat(5)\n \n ForEach(0..<9, id: .self) { row in\n HStack {\n ForEach(0..<9, id: .self) { column in\n SudokuCellView(value: self.$puzzle[row][column])\n }\n }\n }\n }\n .background(\n Image("backgroundImageName") // Replace "backgroundImageName" with the name of your image\n .resizable()\n .scaledToFill()\n .edgesIgnoringSafeArea(.all)\n )\n .onTapGesture {\n hideKeyboard()\n }\n}\n\nprivate func hideKeyboard() {\n UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)\n}

SwiftUI 设置背景图片 - 如何在 SwiftUI 中添加背景图片

原文地址: https://www.cveoy.top/t/topic/pTv5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录