I've created a button in the following way, in my ViewController:
var userButton: Button!
override func viewDidLoad() {
userButton = Button()
userButton.frame = CGRect(x: self.view.frame.width / 2 + 90, y:
self.view.frame.height / 1.5 + 110, width: 100, height: 100)
userButton.addTarget(self, action: #selector(MainController.userButtonTapped(sender:)), for: .touchUpInside)
self.view.addSubview(userButton)
}
This is the Button class I've created:
import UIKit
@IBDesignable
class Button: UIButton {
// MARK: - PROPERTIES
@IBInspectable var cornerRadius: CGFloat = 3.0 {
didSet {
setupView()
}
}
// MARK: - CONFIGURATION
override func awakeFromNib() {
setupView()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setupView()
}
/**
* Sets default properties to the view.
*/
func setupView() {
self.layer.cornerRadius = cornerRadius
* Shadow properties */
self.layer.shadowColor = SHADOW_COLOR.cgColor
self.layer.shadowOpacity = 0.6
self.layer.shadowRadius = 6.0
self.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
}
}
When running the app, userButton does not have the properties set in the class. However, when I set these properties in the ViewController, it works. Why doesn't it work with the class?