1

i'm making a custom keyboard and wanna add shadow to buttons. so added some code(keys.layer~~) in viewDidLoad()

but i can't set multiple button to one IBOutlet
what i want is all keys have 'keys(IBOutlet)' as value(?) is it possible? if it's not, any other thing is fine :) help!

this is my code (pls ignore next keyboard button)

@IBAction func keys(sender: AnyObject) {

}

@IBOutlet weak var keys: UIButton!

@IBOutlet var nextKeyboardButton: UIButton!

override func updateViewConstraints() {
    super.updateViewConstraints()

    // Add custom view sizing constraints here
}

override func viewDidLoad() {
    super.viewDidLoad()

    loadInterface()
    keys.layer.cornerRadius = 4.0;
    keys.layer.shadowColor = UIColor.blackColor().CGColor
    keys.layer.shadowOffset = CGSizeMake(0.0, 2.0)
    keys.layer.masksToBounds = false
    keys.layer.shadowRadius = 1.0
    keys.layer.shadowOpacity = 0.5
Yumin Hwang
  • 159
  • 2
  • 2
  • 14

1 Answers1

0

You can make UIButton extension like this and used with all the object of your custom keyboard Button

extension UIButton {

    func setShadow() {
        self.layer.cornerRadius = 4.0;
        self.layer.shadowColor = UIColor.blackColor().CGColor
        self.layer.shadowOffset = CGSizeMake(0.0, 2.0)
        self.layer.masksToBounds = false
        self.layer.shadowRadius = 1.0
        self.layer.shadowOpacity = 0.5
    }
}

Now you can call this method with your button object like this way

self.nextKeyboardButton.setShadow()

Edit:

If you want to access multiple Button object with same object you can create an Array of UIButton, and store all the Outlet Button inside that array.

var buttonArray = [UIButton]()
Nirav D
  • 71,513
  • 12
  • 161
  • 183