Determine background colour of image view

Hi

I want to determine the background colour of an imageview when it is tapped and perform an action based on the colour. I cannot fathom the syntaxt for getting the information from the array in which the imageviews are stored. I have tried the below but it says. Any help would be appreciated. I am new and I’m sorry if I’m wasting peoples time, I’m learning by making my own app and its throwing up a lot of questions. Kind rgards.

'Value of type [UIImageView] has no member backgroundColour.

@IBAction func onTapping() {
if squares.backgroundColor == UIColor.red {

    }

If we go back to your previous question regarding the array of ImageViews then we can build on that.

Assuming that:

let square1 = UIIMageView()
let square2 = UIImageView()
...
...
...
let square9 = UIImageView()

Let’s also assume that your array is defined like this:

var viewArray: [UIImageView]

Put all the squares in the ViewArray.

viewArray = [square1,square2,square3,square4,square5,square6,square7,square8,square9]

If you had assigned a backgroundColor differently to each of the squares like:

square1.backgroundColor = .red
square2.backgroundColor = .green
square3.backgroundColor = .blue
square4.backgroundColor = .purple
square5.backgroundColor = .orange
square6.backgroundColor = .gray
square7.backgroundColor = .magenta
square8.backgroundColor = .cyan
square9.backgroundColor = .brown

then you can test each square by referencing the square in the relevant array position

let square = viewArray[0] // the first element in the array

then you can test image background colour like this:

if square.backgroundColor == .white {
    // do something
} else if square.backgroundColor == .red {
    // do something different
} else if ....
    ....
    ....
}

a better way to do the test is using switch

switch square.backgroundColor {
   case UIColor.red:
       // do something
   case UIColor.green:
        // do something else
   case UIColor.blue:
        // do something else
   ...
   ...
   ...
}

Does the make sense?