Skip to content

The missing iOS radio buttons group.

License

Notifications You must be signed in to change notification settings

nasircsms/RadioGroup

 
 

Repository files navigation

RadioGroup

Swift Version Build Status License CocoaPods Compatible
Platform PRs Welcome

The missing iOS radio buttons group.

Usage

let radioGroup = RadioGroup(titles: ["First Option Title", "Another Option Title", "Last"])
radioGroup.selectedIndex = 0
radioGroup.addTarget(self, action: #selector(optionSelected), forControlEvents: .valueChanged)

SwiftUI Usage

RadioGroupPicker(selectedIndex: $selection, titles: ["One", "Two", "Three"])

Changing Appearance

The properties below can be set in Interface Builder, in code, or through a UIAppearance proxy (e.g., RadioGroup.appearance().titleColor = .red). When using SwiftUI you can set them in the RadioGroupPicker initializer .

Layout:

radioGroup.isVertical = false           // default is true => buttons are stacked vertically
radioGroup.titleAlignment = .right
radioGroup.isButtonAfterTitle = true    // default is false => button left (leading) relative to title

Color and Font:

radioGroup.tintColor = .green       // surrounding ring
radioGroup.selectedColor = .red     // inner circle (default is same color as ring)

radioGroup.titleColor = .blue
radioGroup.titleFont = myFont

Or use attributed strings:

radioGroup.attributedTitles = [
    NSAttributedString(string: "Italic", attributes: [.obliqueness: 0.3]),
    NSAttributedString(string: "Underline", attributes: [.underlineStyle: 1]),
]

Size:

radioGroup.buttonSize = 42.0
radioGroup.spacing = 12             // spacing between buttons
radioGroup.itemSpacing = 12         // horizontal spacing between button and title

Button appearance:

RadioButton.appearance().size = 32              // height=width of button
RadioButton.appearance().ringWidth = 3
RadioButton.appearance().ringSpacing = 7        // space between outer ring and inner circle
RadioButton.appearance().selectedColor = .blue  // color of inner circle

Installation

CocoaPods:

pod 'RadioGroup'

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/yonat/RadioGroup", from: "1.4.0")
]

Meta

@yonatsharon

https://github.com/yonat/RadioGroup

About

The missing iOS radio buttons group.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 90.1%
  • Ruby 9.9%