Posts

Radio Button In macOS Xcode

Image
To add a RadioButton to a NSView , there are two ways to achieve, the first one is by adding it programmatically and the second one is with Interface Builder (Xcode 7 onwards) First Way Adding the options programmatically. Please refer to Button Programming tips. Here first we create a 1) NSButtonCell object and assign a title to it. 2) Then create NSMatrix object of model , NSRadioModeMatrix and number of Rows = 3 and number of columns as 1. 3) After creating the matrix, you can simple assign the title to each elements But, here will have to worry about autolayout and other stuff while adding programmatically. Apart from this approach of NSMatrix is discouraged , from OS X v10.8. Second Way(Easiest Way , less code) This one is much simpler and takes advantage of Xcode Interface builder and can be achieved from Xcode 7 onwards only. I usually add them a NSStackView and link all actions to a COMMON  action handler. Please read Xcode7 release notes for below s