Yumin Hwang Yumin Hwang - 2 months ago 5x
iOS Question

How to add property to UIButton?

I'm trying to add properties to keyboard keys like

I got an error

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

how to fix this ?

this is my code keyboardViewController.swift

import UIKit

class KeyboardViewController: UIInputViewController {
var newKeyboardView: UIView!

@IBAction func keyPressed(sender: UIButton) {


@IBOutlet var nextKeyboardButton: UIButton!

override func updateViewConstraints() {

// Add custom view sizing constraints here

override func viewDidLoad() {



func loadInterface() {
// load the nib file
let keyboardNib = UINib(nibName: "newKeyboard", bundle: nil)
// instantiate the view
newKeyboardView = keyboardNib.instantiateWithOwner(self, options: nil)[0] as! UIView

// add the interface to the main view

// copy the background color
view.backgroundColor = newKeyboardView.backgroundColor

override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated

override func textWillChange(textInput: UITextInput?) {
// The app is about to change the document's contents. Perform any preparation here.

override func textDidChange(textInput: UITextInput?) {
// The app has just changed the document's contents, the document context has been updated.

var textColor: UIColor
let proxy = self.textDocumentProxy
if proxy.keyboardAppearance == UIKeyboardAppearance.Dark {
textColor = UIColor.whiteColor()
} else {
textColor = UIColor.blackColor()
self.nextKeyboardButton.setTitleColor(textColor, forState: .Normal)



Seems like you're trying to "add property" not to a button, but rather to a closure which accepts a button as an argument.

Make it like this:

nextKeyboardButton.layer.shadowColor = UIColor.redColor.cgColor
nextKeyboardButton.layer.shadowRadius = 5.0