GithubHelp home page GithubHelp logo

abedalkareem / amchoice Goto Github PK

View Code? Open in Web Editor NEW
45.0 4.0 5.0 251 KB

Radio buttons and check boxes for iOS

License: MIT License

Swift 89.13% Ruby 8.10% Objective-C 2.76%
swift ios ios-swift amchoice radio-buttons check-box check radio button radio-button-swift

amchoice's Introduction

Facebook Buy Me A Coffee Youtube Twitter

A custom radio buttons and check boxs for iOS

Screenshots

Usage

1-Add a UIView to your view controller and set the custom class to AMChoice .

2-Set the images for select and unselect statuses (You can set it programmatically also).

3-Creat a new model and implement Selectable protocol, by implementing Selectable protocol you must add three variables (title, isSelected, and isUserSelectEnable).

class VoteModel: NSObject, Selectable {
  var title: String
  var isSelected: Bool = false
  var isUserSelectEnable: Bool = true 
    
  init(title:String,isSelected:Bool,isUserSelectEnable:Bool) {
    self.title = title
    self.isSelected = isSelected
    self.isUserSelectEnable = isUserSelectEnable
  }
}

4-Set the data (Selectable items) for the AMChoice view.

amChoiceView.data = myItems 

More

You can make any customization to the AMChoice view, or you can implement the AMChoiceDelegate protocol to get the selected index, see the comment in the code below to know more.

class ViewController: UIViewController,AMChoiceDelegate {

  @IBOutlet weak var amChoiceView: AMChoice!
  
  let myItems = [
    VoteModel(title: "Will smith", isSelected: false, isUserSelectEnable: true),
    VoteModel(title: "Al pacino", isSelected: false, isUserSelectEnable: true),
    VoteModel(title: "Abedalkareem", isSelected: false, isUserSelectEnable: true),
  ]
    
  override func viewDidLoad() {
    super.viewDidLoad()
        
        
    amChoiceView.isRightToLeft = false // use it to support right to left language.
    amChoiceView.delegate = self // the delegate used to get the selected item when pressed.
    amChoiceView.data = myItems // fill your items.
    amChoiceView.selectionType = .single // selection type, single or multiple.
    amChoiceView.cellHeight = 50 // to set cell hight.
    amChoiceView.arrowImage = nil // use it if you want to add arrow to the cell.
        
    // you can set the selected and unselected image programmatically
    amChoiceView.selectedImage = UIImage(named: "selectedItem")
    amChoiceView.unselectedImage = UIImage(named: "unSelectedItem")
  }
    
  // get the selected item when pressed
  func didSelectRowAt(indexPath: IndexPath) {
    print("item at index \(indexPath.row) selected")
  }

  @IBAction func submit(_ sender: Any) {
    let selectedItems = amChoiceView.getSelectedItems() as! [VoteModel] // use getSelectedItems to get all selected item
    print(selectedItems)
    
     // use getSelectedItemsJoined to get all selected item joined with separator (if the selection type multiple)
    let selectedItemCommaSeparated = amChoiceView.getSelectedItemsJoined(separator: ",") 
    print("\n\n\nComma Separated: \n \(selectedItemCommaSeparated)")
  }
}

Installation

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

pod 'AMChoice'

Support me ๐Ÿš€

You can support this project by:

1- Checking my apps.
2- Star the repo.
3- Share the repo with your friends.
4- Buy Me A Coffee.

Follow me โค๏ธ

Facebook | Twitter | Instagram | Youtube

License

The MIT License (MIT)

Copyright (c) 2017 Abedalkareem

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

amchoice's People

Contributors

abedalkareem 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

Watchers

 avatar  avatar  avatar  avatar

amchoice's Issues

Answer width Problem

Hi bro, thanks for this but there is important problem for use it.
If your answers are short its good but else your answers are long its not showing more than one line.
If you fix, it will be more usefull, thanks :)

ekran resmi 2019-01-03 15 06 16

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.