Tomás
Tomás

Reputation: 97

How to check the view background color

I'm making a single view app, with an empty view, for a start on studying IOS. I'd like to check the background color of this view … something simple, like this:

Function CheckColor ( )
If ( view.background.color is white ) then {
    // do something 
} else {
    // do something  
}
End function 

I'd like to make a simple "blinking screen ", to learn how to control the basic view properties and the NStimer object.

Thanks a lot!

Upvotes: 2

Views: 2325

Answers (2)

Usernumbernine
Usernumbernine

Reputation: 276

The UIColor class has a method to compare colors. isEqual()

your example would look like this:

func checkColor() {
    if self.view.backgroundColor!.isEqual(UIColor.whiteColor()) {
        println("yes")
    } else {
        println("no")
    }
}

Upvotes: 1

Lamour
Lamour

Reputation: 3030

if you want a function that check the color of any view :

func CheckColor(CustomView:UIView )
{
   if CustomView.backgroundColor.isEqual(UIColor.whiteColor()) 
     {
         println("it is white");
     } 
     else {
          println("I don't know :)");
       }
 }

Upvotes: 2

Related Questions