1

I have created a UIButton with system type

let systemButton = UIButton(type: .system)

I have a subclass of UIButton named SSRadioButton.

enter image description here Instead of doing this thing in IB, I want to do it programmatically. All suggestions are welcome.

Ramcharan Reddy
  • 621
  • 1
  • 5
  • 18

3 Answers3

3

Instead of

let systemButton = UIButton(type: .system)

Use,

let systemButton = SSRadioButton()

and do further activity.

Ruhi
  • 176
  • 2
  • 16
0

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)
}
cheznead
  • 2,589
  • 7
  • 29
  • 50
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
0

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.

Community
  • 1
  • 1
SphynxTech
  • 1,799
  • 2
  • 18
  • 38