I have created a UIButton with system type
let systemButton = UIButton(type: .system)
I have a subclass of UIButton named SSRadioButton.
Instead of doing this thing in IB, I want to do it programmatically. All suggestions are welcome.
I have created a UIButton with system type
let systemButton = UIButton(type: .system)
I have a subclass of UIButton named SSRadioButton.
Instead of doing this thing in IB, I want to do it programmatically. All suggestions are welcome.
Instead of
let systemButton = UIButton(type: .system)
Use,
let systemButton = SSRadioButton()
and do further activity.
If your intention is to make it programmatically, simply implement:
// make sure to setup the frame as it should...
let myButton = SSRadioButton(frame: CGRect(x: 0, y: 0, width: 500, height: 50))
// OR, for your case:
//let myButton = SSRadioButton(type: .system)
myButton.addTarget(self, action: #selector(myButtonPressed), for: .touchUpInside)
// setup all pther needed properties...
view.addSubview(myButton)
Target of the button:
func myButtonPressed() {
print(#function)
}
You can have all details about UIButton () declaration in stack overflow: how to init a UIButton subclass?. It is a very complete answer and I do not have anything to add.