编辑代码

/*func displayArrayGraphButtonTips(){
let myViewl = self.view.viewwithTag(2001) as! UIImageview 
let myView2 = self.view.viewwithTag(2002) as! UIImageview
 myViewl.backgroundColor = .darkGray 
 myView2.backgroundColor = .darkGray
myView1.isUserInteractionEnabled = true
 myView2.isUserInteractionEnabled = true

let h= myViewl.frame.size.height 
let w= myViewl.frame.size.width

let padding : CGFloat = 5
 let margin : CGFloat = 10
let grid w=(w-margin *2 - padding*CGFloat(cols-1))/ CGFloat
(cols)
let grid h=(h-margin * 2 - padding * CGFloat(rows-1))/ CGFloat
(rows)
for i in 0..<rows {
   for j in 0..<cols {
       let x = margin + CGFloat(j) * (grid_w + padding) 
       let y=margin + CGFloat(i)*(grid h+padding)
let rect= CGRect(x: x, y:y , width: grid w, height: grid h)

let fileNamel = ivl[i*cols+j]
 let tag1=i*cols+j+5000
addButton(view: myViewl, rect:rect,fileName:fileNamel,
tag: tagl)
let fileName2 = iv2[i*cols+j]
let tag2 = i*cols+j +4000
fileName:fileNamel,addButton(view: myView2,rect: rect,tag: tag2)
   }
  }
}
func addButton(view:UIView,rect:CGRect,fileName:String,tag:Int){
let img=UIImage(named: fileName) 
let btn =UIButton(frame: rect) 
btn.setImage(img, for:.normal)

var mytag =tag
if mytag >= 5000 {
    mytag -=5000
}
else if mytag >= 4000 {
    mytag -= 4000}
let row = Int (mytag / cols) 
let col = mytag - cols * row
let result = errorCords.filter {
    $0== (row,col)
}
if result.count >= 1 && TipsFlag {
     btn.backgroundColor=.blue
}
else {
btn.backgroundColor=.yellow
}
     btn.tag= tag
      btn.addTarget(self, action: #selector(buttonCheckMusicTimer (_:))
for:.touchUpInside)
    view.addSubview(btn)
}
@IBAction func onTips( sender : UIButton){
        TipsFlag=!TipsFlag
displayArrayGraphButtonTips()
  }

@IBAction func onBegin(_ sender : UIButton){
GameOver = false
beainTimestamp=getCurrentTimeStamp()
timeElapse()
distractorCreate(mount: 5) 
differenceCreate(mount: 3)
displayArrayGraphButtonTips()
}*/



/*func addButton(view:UIView,rect:CGRect,fileName:String,tag:Int){
let img=UIImage(named:fileName) 
let btn = UIButton(frame: rect)
 btn.setImage(img,for:.normal)

var mytag=tag
if mytag >= 5000 {
    mytag -= 5000
}
else if mytag >= 4000 {
   mytag -= 4000}
}
let row= Int (mytag/cols) 
let col= mytag -cols * row

let result = errorCords.filter {
   $0==(row,col)
}
if result.count >= 1 && TipsFlag {
   btn.backgroundColor=.blue
    btn.tag=tag
      btn.addTarget(self,action: #selector (buttonCheckMusicTimer (_:)),
for:.touchUpInside)
view.addSubview(btn)
} 
let resultl = cords.filter {
    $0==(row,col)
}


if resultl.count >= 1 { 
    btn.tag= tag
btn.addTarget(self,action: #selector(buttonCheckMusicTimer(_:)),
for:.touchUpInside)
    view.addSubview(btn)
    }
    }
func removeAllSubViews(view:UIView){
if view.subviews.count>0 {
view.subviews.forEach({$0.removeFromSuperview(())
}
}

@IBAction func onTips( sender : UIButton){
TipsFlag=!TipsFlag
displayArrayGraphButtonTips()
}
@IBAction func onBegin(_ sender : UIButton){
GameOver=false
beginTimestamp =getCurrent
TimeStamp()
timeElapse()
distractorCreate(mount: 10) 
differenceCreate(mount:8)
displayArrayGraphButtonTips()
}
@IBAction func onNext(_ sender : UIButton){
GameOver=true
TipsFlag = false
let muview1 = self.view viewWithTag(2001) as! UITmageView
let muview2 = self.view viewWithTag(2002) as! UITmageView
currentBackground += 1
if currentBackground > 4 {
    currentBackground =1
}
let image = UITmage(named:"back0\(currentBackground)")!
muview1.image =image
muview2.image =image
 removeAllSubViews(view:myView1)
 removeAllSubViews(view:myView2)*/


 /*import SwiftuI
struct ContentView : View{

@State var userName:String=""
@State var passWord:String=""

var body: some View {
VStack {
Text("欢迎使用找不同")
.font(.title)
.padding()
Divider()
.background(Color(brown))
 Image(systemName:"person")
.resizable()
.frame(width:150,height:150)
cornerRadius(50)


Vstack {
    TextField("请输入用户名",text:$userName)
·padding()
.padding(.leading,10)
.background(Color(.lightGray))
.cornerRadius(15)
TextField("请输入密码",text:$passWord)
·padding()
.padding(.leading,10)
.background(Color(.lightGray))
.cornerRadius(15)
}
padding()

Button(action:{
print("被点击了...")
},label:{Text("登录")})
padding()
Spacer()
            }   
        }
    }
struct Contentview Previews:PreviewProvider {
     static var previews: so me View {
         ContentView()
     }
}*/


/*import Swiftul
let lightGrayColor = Color(red: 239.0/255.0,green: 243.0/255.0, blue:244.0/255.0,opacity: 1.0)

struct Contentview : View {

@State var userName : String =""
@State var passWord : String = ""
@State private var alertFlag : Bool = false
@State private var alertMsg : String
var body: some View {
VStack {
Text("欢迎使用找不同")
.font(.title)
.padding()
Divider()
.background(Color(.brown))
 Image("back02")
.resizable()
.frame(width: 150,height:150)
.cornerRadius(150)

VStack {
TextField("请输入用户名",text:$userName)
·padding()
.padding(.leading,10)
.background(lightGrayColor)
ornerRadius(15)
}
·padding()

Button(action:{
if self.userName == "Zfchen" && self.passWord == "123{
self.alertflag = true
self.alertMsg="登录成功"
}
else {
self.alertflag = true
self.alertMsg ="登录失败"
}
},label:{
Text("登录")
.font(.headline)
.foregroundColor(.white)
.frame(width: 220,height: 60)
.background(Color.green)
.cornerRadius(15.0)
})
padding() 
Spacer()
}
.alert(ispresented: $alertFlag){ () -> Alert in
          Alert(title: Text("登录提示"), message:Text(self.alertMsg),
dismissButton: .default(Text("确定")))
       }
    }
}

struct ContentView Previews: PreviewProvider {
    static var previews: some View {
       ContentView()
    } 
}*/


/*mport uikit

class CoreGraphUIView : UIView{
override func touchesBegan(_touches: Set<UITouch>, with event: UIEvent?) {
self.backgroundColor =UIColor.red
 print("Began:\(touches)")
}

override func touchesEnded( touches: Set<UITouch>, with event: UIEvent?) {
self.backgroundColor =UIColor.lightGray 
print("Ended:\(touches)")
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
self.backgroundColor = UIColor.blue 
print("Moved:\(touches)")
}
class viewController: UIViewController{

    override func viewDidLoad() {
super.viewDidLoad()
 let height = self.view.frame.size.height 
 let width = self.view.frame.size.width
 let graphFrame = CGRect(x: 0, y: 0, width: width, height: height)
 let graphView=CoreGraphUIView(frame: graphFrame) 
 graphView.backgroundColor = UIColor.white
 self,view.addSubview(graphView)
    }
}*/


/*class shape {
var name : string?
var sides : Int?
var origin : cGPoint?
var lineColor : UIColor = UIColor.red
var fillColor : UIColor = UIColor.green
var lineWidth : CGFloat = 2
init(name : String, sides : Int, origin :CGPoint){
self.name = name 
self.sides= sides 
self.origin = origin
}
func sayhello(){
     print("Shape is \(na ame!) sides \(sides!), and originCord is(\
(origin!.x),\(origin!.y)) ")
   }
}*/