I've built a custom button and now I'm trying to put it in a class.
The code below throws an error for the line "self.view.addSubview(button)
" - which is what I used when the code was running under viewDidLoad
.
Any suggestions?
class myButton {
var buttonLabel:String
var buttonRadius:CGFloat = 90
var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
init(buttonColour:CGColorRef, buttonLabel:String){
self.buttonColour = buttonColour
self.buttonLabel = buttonLabel
}
func drawButton() {
button.frame = 100, 100, buttonRadius * 2, buttonRadius * 2)
button.layer.borderColor = buttonColour
button.setTitle(buttonLabel, forState: UIControlState.Normal)
button.addTarget(self, action: "pressed:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button) // error: 'ViewController.myButton' does not have a member named 'view'
}