简体   繁体   中英

how to create my own radio buttons

I am new to Swift and Xcode so I need help with what I am doing. And what I am doing is this. I have three buttons one of them starts out checked. and what I want it to do is when I click on another button it checks it and unchecked the previous. I want my own radio buttons

For Radio Buttons there is nothing that comes built in.

You can use SSRadioButtonsController You can create a controller object and add buttons array to it like

var radioButtonController = SSRadioButtonsController()
radioButtonController.setButtonsArray([button1!,button2!,button3!])

You can also use something like this tutorial .

The standard Apple class that is designed to work with radio button groups is NSMatrix. Specifically you'd create an NSMatrix with mode "NSRadioModeMatrix". NSMatrix takes an NSCell for its list of items. So you can use any built-in NSCell subclass (like NSButton) or anything else custom you would like.

You can manage manually by setBackgroundImage and setImage property. at initial time set rounded image as setBackgroundImage for all three button. At button click event set "bulletin" image by setImage property for selected button and set nil for all other button setImage property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM