2017-01-23 4 views
1

のために迅速にプログラムでカスタムクラスを割り当てるにはどうすれば私はのサブクラスSSRadioButtonという名前UIButtonを持っているシステムの種類はUIButton

let systemButton = UIButton(type: .system) 

とUIButtonを作成しました。

enter image description here IBでこれを行うのではなく、プログラムで実行したいと思います。すべての提案は大歓迎です。あなたの意図は、プログラムでそれを作るのであれば

+0

あなたはIBOutletとしてViewControllerに接続していますか? –

+0

いいえ、私のビューコントローラは何も持っていません。プログラムで行う必要があるすべて –

答えて

0

、単に実装:ボタンの

// 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) 

対象:

func myButtonPressed() { 
    print(#function) 
} 
3

代わりの

let systemButton = UIButton(type: .system) 

を使用し、

let systemButton = SSRadioButton() 

などのアクティビティを実行します。