I was curious of how to create a custom class for a UI element (say for example, a button)?
I've read the Apple development docs and I followed the instructions, what I thought was to create a separate UIButton class file and link that class file for all buttons on the storyboard.
Here's the separate UIButton class code (file named buttonz.swift):
import UIKit
public class buttonz: UIButton {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.layer.borderWidth = 1
self.backgroundColor = UIColor.whiteColor()
self.layer.borderColor = UIColor.blackColor().CGColor
}
}
And on the storyboard, I linked that specific button to the new UIButton class:
The problem is that when I run the simulator, it gives me an error in the debig console:
this class is not key value coding-compliant for the key aButton
I thought the process was straightforward in the guide but am I missing any extra steps? Please let me know, thanks!
For reference, here is the link to the Apple docs that I used as a guide.
Edit 1 - Here's the action link to the viewcontroller.swift for the view controller. I just ctrl + dragged the button from the story board into the viewcontroller.swift.
@IBAction func a(sender: AnyObject) {
var alertView = UIAlertView();
alertView.addButtonWithTitle("Ok");
alertView.title = "title";
alertView.message = "message";
alertView.show();
}
