Search code examples
iosswiftxcode8

Xcode 8: fix for error (has no member 'backgroundColor')


Just trying to set the background color of the button but I keep getting the following error in Xcode 8.3.3.

Value of type '(UIButton) -> ()' has no member 'backgroundColor'

Screenshot of the error from xcode


Solution

  • You should get the outlet of the buttons to edit its properties. What you have got is a action of that button for the a particular event like touchUpInside.

    You should get the Outlet of the button like this:

    @IBOutlet weak var sampleButton: UIButton!
    

    and then set the backgroundColor in the viewDidLoad() :

    sampleButton.backgroundColor = UIColor.orange