Coder Social home page Coder Social logo

alxrguz / alradiobuttons Goto Github PK

View Code? Open in Web Editor NEW
79.0 3.0 9.0 13.97 MB

RadioButtons for iOS. Inherited from UIControl, support 2 native styles, fully customizable.

License: MIT License

Ruby 1.47% Swift 95.23% Objective-C 3.30%
swift radiogroup radiobutton uicontrol uibutton uikit uicomponent apple ios radiobuttons

alradiobuttons's Introduction

ALRadioButtons

 

Navigation

Requirements

  • iOS 10.0 +
  • Swift 4.2 +

Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate ALRadioButtons click File -> Swift Package -> Add Package Dependency and insert:

https://github.com/alxrguz/ALRadioButtons

CocoaPods

ALRadioButtons is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ALRadioButtons'

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate ALRadioButtons into your project manually. Put Source/ALRadioButtons folder in your Xcode project.

Usage

Quick Start

import ALRadioButtons

class MyViewController: UIViewController {

    lazy var radioGroup = ALRadioGroup(items: [
        .init(title: "title1", subtitle: "subtitle1"),
        .init(title: "title2", subtitle: "subtitle2", detail: "Detail"),
        .init(title: "title3"),
    ], style: .grouped)

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(radioGroup)
        // ... Setup layout
        
        radioGroup.selectedIndex = 0
      	radioGroup.addTarget(self, action: #selector(radioGroupSelected(_:)), for: .valueChanged)
      
      	// If the checkbox selection can be canceled, then set this property to true 
      	radioGroup.allowDeselection = true
    }
    
    @objc private func radioGroupSelected(_ sender: ALRadioGroup) {
        print(sender.selectedIndex)
    }
}

Customization

Colors

You can customize the buttons, headers and indicators colors depending on their state.

radioGroup.selectedTitleColor = .systemBlue 
radioGroup.unselectedTitleColor = .black 
radioGroup.selectedDetailColor = .systemBlue
radioGroup.unselectedDetailColor = .black
radioGroup.selectedIndicatorColor = .systemBlue 
radioGroup.unselectedIndicatorColor = .systemBlue 
radioGroup.subtitleColor = .lightGray 
radioGroup.buttonBackgroundColor = .white 
radioGroup.separatorColor = .lightGray 

Font

radioGroup.titleFont = .systemFont(ofSize: 16, weight: .medium)
radioGroup.detailFont = .systemFont(ofSize: 16, weight: .regular)
radioGroup.subtitleFont = .systemFont(ofSize: 13, weight: .regular)

Layout

radioGroup.cornerRadius = 14 // Button corner radius, actual for .grouped style
radioGroup.buttonHeight = 50 
radioGroup.subtitleTopOffset = 8 // Subtitle offset from title bottom anchor
radioGroup.separatorTopOffset = 8 // Separator offset from title or subtitle (if added) bottom anchor
radioGroup.indicatorRingWidth = 2 // Outer ring width of indicator
radioGroup.indicatorRingSize = 22 // Indicator outer ring size
radioGroup.indicatorCircleInset = 5 // Indentation of the circle from the outer ring

License

ALRadioButtons is under MIT license. See the LICENSE file for more info.

alradiobuttons's People

Contributors

alxrguz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

alradiobuttons's Issues

Getting an blank page

import ALRadioButtons

class RadioButtonsTableViewCell: UITableViewCell {

@IBOutlet var radioButtons: ALRadioGroup!

lazy var radioGroup = ALRadioGroup(items: [
       .init(title: "title1", subtitle: "subtitle1"),
       .init(title: "title2", subtitle: "subtitle2", detail: "Detail"),
       .init(title: "title3"),
   ], style: .grouped)

override func awakeFromNib() {
    super.awakeFromNib()
    radioButtons = ALRadioGroup(items: [
        .init(title: "title1"),
        .init(title: "title2"),
        .init(title: "title3")
    ], style: .grouped)
    radioButtons.axis = .vertical
    radioButtons.selectedIndex = 0
    radioButtons.addTarget(self, action: #selector(radioGroupSelected(_:)), for: .valueChanged)
    radioButtons.allowDeselection = true
}

}

Can you please help me where can I did wrong ! ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.