I've created a custom button class as follows.
import UIKit
class LogButtonView: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.frame = CGRectMake(200, 200, 100, 100)
self.layer.cornerRadius = 50
self.layer.borderWidth = 1
self.layer.borderColor = self.tintColor.CGColor
}
}
And I know how to use it in story board.
But how can I create an instance of it dynamically in ViewController.swift and add it to containerView?
import UIKit
class ViewController: UIViewController {
@IBOutlet var containerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let logBtn = LogButtonView() // Missing argument for parameter 'coder' in call
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
And if possible, I want all LogButtonView instances to be of the same size, so I set self.frame = CGRectMake(200, 200, 100, 100). But the instances in story board seem to be of the size I dragged them to be.