RadioGroup - The missing iOS radio buttons group.

Overview

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"])
    .fixedSize()

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, or use as view modifiers (e.g., .buttonSize(32)). .

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.selectedTintColor = .blue  // selected radio button's surrounding ring (default is tintColor)

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.3")
]

Meta

@yonatsharon

https://github.com/yonat/RadioGroup

Comments
  • Cant archive from Xcode

    Cant archive from Xcode

    Description of the problem: Not able to do archive from Xcode; if installed through swift package manager; if its Pods then no issues..

    • maybe issue with the dependency SweeterSwift..??

    attaching the screen shot for your review....

    Minimal project that reproduces the problem (so I'll be able to figure out how to fix it): [link to a Minimal Reproducible Example as described at https://ootips.org/yonat/repex ]

    Swift PM n archive from Xcode Version 12.1 (12A7403) CocoaPods version 1.10.0

    Screen Shot 2020-11-02 at 6 29 23 PM bug 
    opened by ghost 7
  • Archive error

    Archive error

    I am using RadioGroup via SwiftPackage Manager in my project with target iOS 10. Its all fine but when I try to archive project for submission, I get error as shown below:

    sc1

    Is it due to SwiftUI code? My project is not a SwiftUI code as it targets from iOS 10. Any suggestion or solution that could be helpful? Thanks

    bug 
    opened by PrakashMaharjan 6
  • Radio buttons are not distributed evenly.

    Radio buttons are not distributed evenly.

    Description of the problem: The buttons inside the radio group are not distributed equally. Even when I set the spacing.

    radioGroup.spacing = 12
    

    Can you help me to check this issue? Thanks!

    Screen Shot 2019-08-04 at 23 46 05 bug 
    opened by quangctkm9207 5
  • Remove dependency SweeterSwift

    Remove dependency SweeterSwift

    Hey,

    First of all, thanks for the great library.

    I would like to import only the library RadioGroup but not SweeterSwift.

    Would it be possible to remove the dependency SweeterSwift?

    Thanks

    enhancement 
    opened by 4brunu 4
  • RadioGroup Items not shown correctly

    RadioGroup Items not shown correctly

    Description of the problem: [description] I have three items showing horizontally but sometimes they don't show correctly!

    Screen Shot 2021-07-10 at 11 21 39 PM Screen Shot 2021-07-10 at 11 24 10 PM

    It's in a Vstack with some other items but as it is horizontal, some times it draw normal, sometimes draw like the image above! Minimal project that reproduces the problem (so I'll be able to figure out how to fix it): [link to a Minimal Reproducible Example as described at https://ootips.org/yonat/repex ]

    bug 
    opened by gharary 3
  • Tint color configuration

    Tint color configuration

    📲 What

    • Allow changing of tint color for selected and not selected button

    🛠 How

    • Expose selectedTintColor and notSelectedTintColor which defines what tint color to use

    ✅ Acceptance criteria

    • Tested it locally

    ⏰ TODO

    • N/A

    🔗 References

    Screen Shot 2020-12-23 at 12 36 11 PM
    opened by jaimejazarenoiii 3
  • Be able to change selected button's tint color

    Be able to change selected button's tint color

    Is it possible to change the outer ring's color if it's selected?

    something like this

    @IBInspectable open dynamic var selectedTintColor: UIColor? {
            didSet {
                layer.borderColor = selectedTintColor.cgColor ?? selectedColor
            }
        }
    

    Let me know if it's possible or not, if so, I can make the PR Thank you.

    enhancement 
    opened by jaimejazarenoiii 2
  • Item row configuration

    Item row configuration

    Added optional properties specific to each item

    1. itemHeight -> Developer can give each row height
    2. itemBorderWidth,itemBorderColour,itemCornerRadius -> This belongs to border width,colour, corner radius
    3. itemInnerPadding -> Once added border maybe looks bad because of control is too closed to the stack view, so that better to add padding.
    opened by ramrcram 2
  • Unable to simultaneously satisfy constraints.

    Unable to simultaneously satisfy constraints.

    [LayoutConstraints] Unable to simultaneously satisfy constraints.
    	Probably at least one of the constraints in the following list is one you don't want. 
    	Try this: 
    		(1) look at each constraint and try to figure out which you don't expect; 
    		(2) find the code that added the unwanted constraint or constraints and fix it. 
    	(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
    (
        "<NSAutoresizingMaskLayoutConstraint:0x600001f93d90 RadioGroup.RadioGroup:0x7fa74196d5c0.height == 0>",
        "<NSLayoutConstraint:0x600001f8c960 UIStackView:0x7fa74196d7d0.topMargin == RadioGroup.RadioGroup:0x7fa74196d5c0.topMargin>",
        "<NSLayoutConstraint:0x600001f8ca00 UIStackView:0x7fa74196d7d0.bottomMargin == RadioGroup.RadioGroup:0x7fa74196d5c0.bottomMargin>",
        "<NSLayoutConstraint:0x600001f8c730 UIStackView:0x7fa74196d7d0.bottom == UILayoutGuide:0x600000562e60.bottom>",
        "<NSLayoutConstraint:0x600001f8c870 RadioGroup.RadioGroup:0x7fa74196d5c0.bottom == UILayoutGuide:0x600000563100.bottom + 8>",
        "<NSLayoutConstraint:0x600001f8c690 UILayoutGuide:0x600000562e60.top == UIStackView:0x7fa74196d7d0.top>",
        "<NSLayoutConstraint:0x600001f8c7d0 UILayoutGuide:0x600000563100.top == RadioGroup.RadioGroup:0x7fa74196d5c0.top + 8>"
    )
    
    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0x600001f8c730 UIStackView:0x7fa74196d7d0.bottom == UILayoutGuide:0x600000562e60.bottom>
    
    bug 
    opened by cikichen 1
  • Unselect current item

    Unselect current item

    Description: Can you please add ability to unselect current selection? I see that control supports this with selectedIndex: -1 but if I tap on already selected item it doesn't unselect.

    Problems I encountered when trying to implement this myself: I tried to subclass RadioGroup but func selectIndex(item: RadioGroupItem) isn't open + RadioGroupItem is also internal.

    Thanks!

    enhancement 
    opened by josipbernat 1
  • This is great! Thank you!

    This is great! Thank you!

    One small suggestion on the docs in the README-- Add an example usage of fixedSize() -- and what it's needed for. The radio buttons were spread out for me too far and I didn't realize how to change this, initially.

    enhancement 
    opened by crspybits 1
  • RadioGroup Layout Constraint Error.

    RadioGroup Layout Constraint Error.

    Description of the problem: When running, I am seeing that one of the constraints is 0 for a table size so the constraint is being ignored(dropped). v 1.4.1 Loaded with cocoaPods.

    Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002030fa0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x600003a281c0'UIViewLayoutMarginsGuide']-(0)-| (active, names: '|':UIStackView:0x7fb001407cf0 )>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2020-11-08 18:44:01.921289-0500 RadioGroupBug[90413:13898342] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x60000202c640 h=--& v=--& RadioGroup.width == 0 (active, names: RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x600002074d70 H:|-(0)-UIStackView:0x7faff2b136b0 (active, names: RadioGroupItem:0x7faff2b11f20, '|':RadioGroupItem:0x7faff2b11f20 )>", "<NSLayoutConstraint:0x600002074dc0 UIStackView:0x7faff2b136b0.right == RadioGroupItem.right (active, names: RadioGroupItem:0x7faff2b11f20 )>", "<NSLayoutConstraint:0x6000020317c0 H:|-(0)-[UIStackView:0x7fb001407cf0] (active, names: RadioGroup:0x7fb001407b00, '|':RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x600002030cd0 UIStackView:0x7fb001407cf0.rightMargin == RadioGroup.rightMargin (active, names: RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x600002011b30 'UISV-alignment' RadioGroupItem.leading == RadioGroupItem.leading (active, names: RadioGroupItem:0x7faff2b0fd00, RadioGroupItem:0x7faff2b11f20 )>", "<NSLayoutConstraint:0x600002010be0 'UISV-alignment' RadioGroupItem.trailing == RadioGroupItem.trailing (active, names: RadioGroupItem:0x7faff2b0fd00, RadioGroupItem:0x7faff2b11f20 )>", "<NSLayoutConstraint:0x600002010960 'UISV-canvas-connection' UIStackView:0x7fb001407cf0.leading == RadioGroupItem.leading (active, names: RadioGroupItem:0x7faff2b0fd00 )>", "<NSLayoutConstraint:0x600002010c80 'UISV-canvas-connection' UIStackView:0x7faff2b136b0.leading == RadioButton.leading (active, names: RadioButton:0x7faff2b12320 )>", "<NSLayoutConstraint:0x600002010b40 'UISV-canvas-connection' H:[UIView:0x7faff2b0d560]-(0)-| (active, names: '|':UIStackView:0x7faff2b136b0 )>", "<NSLayoutConstraint:0x600002012440 'UISV-canvas-connection' H:[RadioGroupItem]-(0)-| (active, names: RadioGroupItem:0x7faff2b0fd00, '|':UIStackView:0x7fb001407cf0 )>", "<NSLayoutConstraint:0x600002010e60 'UISV-spacing' H:[RadioButton]-(4)-[UIView:0x7faff2b0d560] (active, names: RadioButton:0x7faff2b12320 )>", "<NSLayoutConstraint:0x6000020316d0 'UIView-leftMargin-guide-constraint' H:|-(0)-UILayoutGuide:0x600003a281c0'UIViewLayoutMarginsGuide' (active, names: '|':UIStackView:0x7fb001407cf0 )>", "<NSLayoutConstraint:0x600002031810 'UIView-leftMargin-guide-constraint' H:|-(8)-UILayoutGuide:0x600003a28380'UIViewLayoutMarginsGuide' (active, names: RadioGroup:0x7fb001407b00, '|':RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x600002030d20 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003a281c0'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':UIStackView:0x7fb001407cf0 )>", "<NSLayoutConstraint:0x600002030b40 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003a28380'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: RadioGroup:0x7fb001407b00, '|':RadioGroup:0x7fb001407b00 )>" )

    Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002010e60 'UISV-spacing' H:[RadioButton]-(4)-[UIView:0x7faff2b0d560] (active, names: RadioButton:0x7faff2b12320 )>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2020-11-08 18:44:01.972791-0500 RadioGroupBug[90413:13898342] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x60000202c640 h=--& v=--& RadioGroup.width == 0 (active, names: RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x6000020317c0 H:|-(0)-[UIStackView:0x7fb001407cf0] (active, names: RadioGroup:0x7fb001407b00, '|':RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x600002030cd0 UIStackView:0x7fb001407cf0.rightMargin == RadioGroup.rightMargin (active, names: RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x6000020316d0 'UIView-leftMargin-guide-constraint' H:|-(0)-UILayoutGuide:0x600003a281c0'UIViewLayoutMarginsGuide' (active, names: '|':UIStackView:0x7fb001407cf0 )>", "<NSLayoutConstraint:0x600002031810 'UIView-leftMargin-guide-constraint' H:|-(8)-UILayoutGuide:0x600003a28380'UIViewLayoutMarginsGuide' (active, names: RadioGroup:0x7fb001407b00, '|':RadioGroup:0x7fb001407b00 )>", "<NSLayoutConstraint:0x600002030d20 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003a281c0'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':UIStackView:0x7fb001407cf0 )>", "<NSLayoutConstraint:0x600002030b40 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003a28380'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: RadioGroup:0x7fb001407b00, '|':RadioGroup:0x7fb001407b00 )>" )

    Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002030d20 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003a281c0'UIViewLayoutMarginsGuide']-(0)-|(LTR) (active, names: '|':UIStackView:0x7fb001407cf0 )>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

    Minimal project that reproduces the problem (so I'll be able to figure out how to fix it): [link to a Minimal Reproducible Example as described at https://ootips.org/yonat/repex ] You should be able to download it from here. Xcode 12.1 https://github.com/rlegault33/RadioGroupBug

    bug 
    opened by rlegault33 3
Owner
Yonat Sharon
Freelance iOS developer. Agile, TDD, and all that jazz. 🎸
Yonat Sharon
Animated Social share buttons control for iOS written in Swift

SwiftShareBubbles Animated Social share buttons control for iOS written in Swift. This library is inspired AAShareBubbles. I tried AAShareBubbles with

Takeshi Fujiki 175 Jun 11, 2022
A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.

A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code. Preview You'll be

Lorenzo Greco 2.3k Dec 31, 2022
Lickable-Button We made the buttons on the screen look so good you'll want to lick them

Lickable-Button We made the buttons on the screen look so good you'll want to lick them. - Steve Jobs A little SwiftUI button project at WWDC 2021 Lic

Nate Thompson 14 Dec 29, 2021
Added functionality that system buttons are not easy to implement

LLCustomButton Added functionality that system buttons are not easy to implement What are the functions ? Sets the position and spacing of text and im

coder 18 Jul 28, 2022
Added functionality that system buttons are not easy to implement

LLCustomButton Added functionality that system buttons are not easy to implement What are the functions ? Sets the position and spacing of text and im

coder 18 Jul 28, 2022
Inspired by Apple’s download progress buttons in the app store

GBKUIButtonProgressView Inspired by Apple’s download progress buttons in the app store Created by @pklada and @miketsprague Checkout the blog post. In

Guidebook 541 Sep 1, 2022
Yet another animated flat buttons in Swift

DynamicButton is a powerful flat design button written in Swift to display hamburger button like with animated transitions between style updates. It a

Yannick Loriot 1.2k Jan 5, 2023
An easy way to create beautiful social authentication buttons

EasySocialButton An easy way to create beautiful social authentication buttons Screenshots Installation Cocoa Pods pod 'EasySocialButton' Manual Drag

Antonio Zaitoun 162 Dec 11, 2022
A fully customisable swift subclass on UIButton which allows you to create beautiful buttons without writing any line of code.

JSButton Demo $ pod try JSButton ...or clone this repo and build and run/test the JSButton project in Xcode to see JSButton in action. If you don't ha

Jogendra 12 May 9, 2022
LabelButtonKit is a mini library for labeled buttons (of SF Symbols), written entirely in SwiftUI

A simple Button with an SFSymbol (icon) as a label, vertically. As well as a Dynamic Type variant using it horizontally. Using SwiftUI. A List View of buttons is also available here. Have fun! ??

Marcos Morais 5 Nov 26, 2022
Floaty is simple floating action button for iOS.

Floaty is simple floating action button for iOS. (formerly KCFloatingActionButton) Why change the name? Follow the swift naming convention. KCF

Lee Sun-Hyoup 1.5k Jan 7, 2023
iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift

iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift

Pallav Agarwal 21 Oct 23, 2022
iOS 7-style bouncy button.

SSBouncyButton SSBouncyButton is simple button UI component with iOS 7-style bouncy animation. Take A Look Try It! pod 'SSBouncyButton', '~> 1.0' Use

StyleShare 310 Dec 15, 2022
Flat design pressable button for iOS developers.

HTPressableButton HTPressableButton is designed for iOS developers to be able to spend time developing ideas, not building basic buttons. These stylis

Famolus 859 Dec 12, 2022
Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift).

TVButton Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). The effect is triggered by long pressing or dragging. Usage Imp

Roy Marmelstein 1.2k Dec 21, 2022
Interactive and fully animated Material Design button for iOS developers.

WYMaterialButton Inspired by Google Material Design, written purely in Swift 3. WYMaterialButton implemented Material Design on iOS and add more dynam

Yu Wang 76 Oct 7, 2022
This is a UI lib for iOS. Effects like shining.

WCLShineButton This is a UI lib for iOS. Effects like shining. Chinese (Simplified): 中文说明 博客介绍 CocoaPods CocoaPods is the recommended way to add WCLSh

W_C__L 1.4k Dec 31, 2022
Tasteful Checkbox for iOS. (Check box)

BEMCheckBox BEMCheckBox is an open source library making it easy to create beautiful, highly customizable, animated checkboxes for iOS. Table of Conte

Boris Emorine 2.6k Dec 8, 2022
A high-performance button control with rounded corners for iOS.

TORoundedButton TORoundedButton is an open source UI control of a standard user button. Its design consists of displaying text on top of a solid recta

Tim Oliver 480 Dec 26, 2022