0
func barButtonSelected(button:UIBarButtonItem){


    for vi in topNav!.items {
        vi.tintColor = UIColor.redColor()
    }

    button.tintColor = UIColor(hex: "FF0000")

}

the func is UIBarButtonItem'action,I can change the tintcolor of the button which i taped, but can't change the others,the xcode shows cannot assign tintColor to "vi" error,by the way it's a swift code

six
  • 115
  • 1
  • 1
  • 7
  • tool bar items might be colored by the toolbar's background color. try changing topNav.backgroundColor. i don't have a project set up with a toolbar so i'm not going to test it myself right now. – mitrenegade Sep 05 '14 at 03:55

1 Answers1

0

use downcast , check this code:

    func barButtonSelected(button:UIBarButtonItem){


    for vi in topNav!.items {
        let theVi = vi as UIBarButtonItem
        theVi.tintColor = UIColor.redColor()
    }

    button.tintColor = UIColor(hex: "FF0000")

}