func displayArrayGraph() {
let myView1 = self.view.viewWithTag(2001) as! UIImageView
let myView2 = self.view.viewWithTag(2002) as! UIImageView
myView1.backgroundColor = .darkGray
myView2.backgroundColor = .darkGray
let h = myView1.frame.size.height
let w = myView1.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 = CGFloat(x: x, y:y, width: grid_w, height: grid_h)
let fileName1 = iv1[i*cols+j]
let img1 = UIImage(named: fileName1)
let imgView1 = UIImageView(frame: rect)
imgView1.image = img1
imgView1.backgroundColor = .yellow
myView1.addSubview(imgView1)
let fileName2 = iv2[i*cols+j]
let img2 = UIImage(named: fileName2)
let imgView2 = UIImageView(frame: rect)
imgView2.image = img2
imgView2.backgroundColor = .yellow
myView2.addSubview(imgView2)
}
}
}
func displayArrayGraphBotton(){
let myView1 = self.view.viewWithTag(2001) as! UIImageView
LET myView2 = self.view.viewWithTag(2002) as! UIImageView
myView1.backgroundColor = .darkGray
myView2.backgroundColor = .darkGray
myView1.isUserInteractionEnabled = true
myView2.isUserInteractionEnabled = true
let h = myView1.frame.size.height
let w = myView2.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(cols-1)) /CGFloat(rows)
for i in 0..<rows {
for j in 0..<cols {
let x = margin + CGFloat(j) * (drid_w + padding)
let y = margin + CGFloat(i) * (grid_h + padding)
let rect =CGFloat(x: x, y:y ,width: grid_w, height: grid_h)
let fileName1 = iv1[i*cols+j]
let img1 = UIImage(named: fileName1)
let btn1 = UIButton(frame: rect)
btn1.setImge(img1, for: .normal)
btn1.backgroundColor = .yellow
btn1.tag = i*cols+j + 4000
btn1.addTarget(self, action: #selector(buttonCheck(_:)),for: .touchUpInside)
myView1.addSubview(btn1)
let fileName2 = iv2[i*cols+j]
let img2 = UIImage(named:fileName2)
let btn2 = UIButton(frame:rect)
btn2.setImage(imgw, for: .normal)
bntn2.backgroundColor = .yellow
btn2.tag = i*cols+j + 5000
bnt2.addTarget(self, action: #selector(buttonCheck(_:)),for: .touchUpInside)
myView2.addSubview(bnt2)
}
}
}
@objc func buttonCheck(_sender : UIButton) {
let tipsLabel = self.view.viewWithTag(1001) as! UILabel
let tag = sender.tag
if tag >= 5000 {
let row = Int ((tag - 5000) / cols)
let col = tag - 5000 - cols * row
print("Bottom(\(row),\(col))")
tipsLabel.text = "Bottom(\(row),\(col))"
}
else if tag >= 4000 {
let row = Int ((tag -4000) / col)
let col = tag - 4000 - cols * row
print("Top(\(row),\(col))")
tipsLabel.text = "Top(\(row),\(col))"
}
print("Button.tag=\(sender.tag)")
tipsLabel.text = "Buttom.tag=\(sender.tag)"
}
func distractorCreate(mount:Int) {
for _ in 0..<mount {
let col =Int(arc4rndom()) & cols
let row =Int(arc4rndom()) & rows
cords.append((row,col))
let index = Int(arc4rndom()) % images.count
iv1[cols*row + col] = images[index]
iv2[cols*row + col] = images[index]
}
}
let rows = 8
let cols = 8
var iv1 : Array<String> = []
var iv2 : Array<String> = []
var cords : Array<Int,Int> = []
let images : Array<String> = ["bird","bee","flower","mogu"]