Tasteful Checkbox for iOS. (Check box)

Overview

BEMCheckBox

Build Status Version License Platform Carthage Compatible

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

Table of Contents

Project Details

Learn more about the BEMCheckBox project, licensing, support etc.

Requirements

  • Requires iOS 7 or later. The sample project is optimized for iOS 9.
  • Requires Automatic Reference Counting (ARC).
  • Optimized for ARM64 Architecture.

License

See the License. You are free to make changes and use this in either personal or commercial projects. Attribution is not required, but highly appreciated. A little "Thanks!" (or something to that affect) is always welcome. If you use BEMCheckBox in your app, please let us know!

Support

Gitter chat
Join us on Gitter if you need any help or want to talk about the project.

Sample App

The iOS Sample App included with this project demonstrates one way to correctly setup and use BEMCheckBox. It also offers the possibility to customize the checkbox within the app.

React Native

BEMCheckBox can be used with React Native: React-Native-BEMCheckBox

NativeScript

BEMCheckBox can be used with NativeScript: NativeScript-BEMCheckBox

Xamarin

BEMCheckBox can also be used with Xamarin: XPlugins.iOS.BEMCheckBox

Getting Started

It only takes a few simple steps to install and setup BEMCheckBox to your project.

Installation

Swift Package Manager

Add https://github.com/Boris-Em/BEMCheckBox as a dependency to your Package.swift file or select File -> Swift Packages -> Add Package Dependency... in Xcode.

CocoaPods

The easiest way to install BEMCheckBox is to use CocoaPods. To do so, simply add the following line to your Podfile:

pod 'BEMCheckBox'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

Run carthage update after adding BEMCheckBox to your Cartfile to build the framework. Drag the built BEMCheckBox.framework into your Xcode project.

Manually

Finally, you can install BEMCheckBox manually. Simply drag and drop the Classes folder into your Xcode project. When you do so, make sure to check the "Copy items into destination group's folder" box.

Setup

Setting up BEMCheckBox to your project couldn't be more simple. It is modeled after UISwitch. In fact, you could just replace instances of UISwitch by BEMCheckBox in your project!
Here are the steps to follow to get everything up and running:

  1. Import "BEMCheckBox.h" to the header of your view controller:
#import "BEMCheckBox.h"
  1. BEMCheckBox can either be initialized programatically (through code) or with Interface Builder (Storyboard file). Use the method that makes the most sense for your project.

Programmatical Initialization
Just add the following code to your implementation (usually in the viewDidLoad method of your View Controller).

BEMCheckBox *myCheckBox = [[BEMCheckBox alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[self.view addSubview:myCheckBox];

Interface Builder Initialization
1 - Drag a UIView to your UIViewController.
2 - Change the class of the new UIView to BEMCheckBox.
3 - Select the BEMCheckBox and open the Attributes Inspector. Most of the customizable properties can easily be set from the Attributes Inspector. The Sample App demonstrates this capability.

Documentation

All of the methods and properties available for BEMCheckBox are documented below.

Enabling / Disabling the Checkbox

The on Property

Just like UISwitch, BEMCheckBox provides the boolean property on that allows you to retrieve and set (without animation) a value determining wether the BEMCheckBox object is on or off. Defaults to NO.
Example usage:

self.myCheckBox.on = YES;
setOn:animated:

Just like UISwitch, BEMCheckBox provides an instance method setOn:animated: that sets the state of the checkbox to On or Off, optionally animating the transition.
Example usage:

[self.myCheckBox setOn:YES animated:YES];

Reloading

The instance method reload lets you redraw the entire checkbox, keeping the current on value.
Example usage:

[self.myCheckBox reload]

Group / Radio Button Functionality

BEMCheckBoxes can easily be grouped together to form radio button functionality. This will automatically manage the state of each checkbox in the group, so that only one is selected at a time, and can optionally require that the group has a selection at all times.

self.group = [BEMCheckBoxGroup groupWithCheckBoxes:@[self.checkBox1, self.checkBox2, self.checkBox3]];
self.group.selectedCheckBox = self.checkBox2; // Optionally set which checkbox is pre-selected
self.group.mustHaveSelection = YES; // Define if the group must always have a selection

To see which checkbox is selected in that group, just ask for it:

BEMCheckBox *selection = self.group.selectedCheckBox;

To manually update the selection for a group, just set it:

self.group.selectedCheckBox = self.checkBox1;

Delegate

BEMCheckBox uses a delegate to receive check box events. The delegate object must conform to the BEMCheckBoxDelegate protocol, which is composed of two optional methods:

  • didTapCheckBox:
    Sent to the delegate every time the check box gets tapped, after its properties are updated (on), but before the animations are completed.

  • animationDidStopForCheckBox:
    Sent to the delegate every time the check box finishes being animated.

Customization

BEMCheckBox is exclusively customizable though properties.
The following diagram provides a good overview:

Apparence Properties

lineWidth - CGFloat
The width of the lines of the check mark and box. Defaults to 2.0.

hideBox - BOOL
BOOL to control if the box should be hidden or not. Setting this property to YES will essentially turn the checkbox into a check mark. Defaults to NO.

boxType - BEMBoxType
The type of box to use. See BEMBoxType for possible values. Defaults to BEMBoxTypeCircle.

tintColor - UIColor
The color of the box when the checkbox is Off.

onCheckColor - UIColor
The color of the check mark when it is On.

onFillColor - UIColor
The color of the inside of the box when it is On.

onTintColor - UIColor
The color of the line around the box when it is On.

Animations

animationDuration - CGFloat
The duration in seconds of the animations. Defaults to 0.5.

onAnimationType - BEMAnimationType
The type of animation to use when the checkbox gets checked. Defaults to BEMAnimationTypeStroke. See BEMAnimationType bellow for possible values.

offAnimationType - BEMAnimationType
The type of animation to use when the checkbox gets unchecked. Defaults to BEMAnimationTypeStroke. See BEMAnimationType bellow for possible values.

BEMAnimationType
The possible values for onAnimationType and offAnimationType.

  • BEMAnimationTypeStroke

  • BEMAnimationTypeFill

  • BEMAnimationTypeBounce

  • BEMAnimationTypeFlat

  • BEMAnimationTypeOneStroke

  • BEMAnimationTypeFade

Comments
  • how to add two or more checkboxs?

    how to add two or more checkboxs?

    how to implement two or more checkbox in one viewcontroller, when one of them is checked then all other have to be unchecked automatically ? any help @Boris-Em ?

    help wanted question 
    opened by subhash08 16
  • Graphical problem while disabiling after an UIAlertController is shown

    Graphical problem while disabiling after an UIAlertController is shown

    Here you can download a video that shows the problem: https://dl.dropboxusercontent.com/u/8581359/check_box_usage.mp4

    Untill I show an UIAlertController, the behavior is correct, but as soon as I show it, the disabled animation brokes.

    Here is the didTapCheckBox event:

    -(void)didTapCheckBox:(id)sender {
        BEMCheckBox *checkBox = (BEMCheckBox*)sender;
    
        SpaceTargetInfoV2 *spaceTarget;
        for(SpaceTargetInfoV2 *st in self.spaceTargetListResponse.spaceTargetList) {
            if(st.idSpaceTarget == checkBox.tag) {
                spaceTarget = st;
            }
        }
    
        // if user wants to unbind check if it was the bind owner
        if(!checkBox.on) {
            if(spaceTarget.idUserBindOwner == [[[NSNumberFormatter alloc] init] numberFromString:[Util getIDUser]]) {
                // call the unbind
            }
            else {
                // alert user he cannot do that op
                UIAlertController * alert = [UIAlertController alertControllerWithTitle:[Util getLangValueForTag:@"geofenceUnbindNotAuthorized"]
                                                                                message:@""
                                                                         preferredStyle: UIAlertControllerStyleAlert];
    
                UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){}];
                [alert addAction:ok];
    
                [self presentViewController:alert animated:YES completion:nil];
                [self.tableView reloadData];
            }
        }
        else {
    
        }
    }
    

    Waiting for your replay.

    Thanks in advance, Samuel

    bug 
    opened by samuelrabini 9
  • BEMCheckBoxGroup Header

    BEMCheckBoxGroup Header

    I'm using this with Carthage (not by choice) and it seems like the Framework Carthage generates doesn't have the Group header file. I'm not sure what the issue is, maybe it needs some configuration updates in the Framework's Xcode project?

    bug 
    opened by Vortec4800 8
  • Checkboxes in UITableViewCell Objects

    Checkboxes in UITableViewCell Objects

    So I'm creating a questionnaire app in which I have a UITableView with a custom Cell class that inherits from UITableViewCell, and it contains an additional checkbox attribute on top of the inherited ones. My problem is twofold.

    Firstly, for whatever reason, the checkboxes will not render in the XCode interface builder. I'm running the latest versions of Swift and Xcode, and I installed via CocoaPods. Secondly, when the controller starts up some of the checkboxes are selected while others are not. As I scroll, some of them even change. Do you have any ideas as to what might be causing this?

    opened by ghost 7
  • Migrated to swift and fixed rendering bugs

    Migrated to swift and fixed rendering bugs

    I have migrated everything to Swift (with proper ObjC compat).

    Along the way I have solved the main rendering issues - the one where too many layer recreations are performed, and the one where stroke line is bleeding outside of the component.

    @Boris-Em I think this will make many people happy. Please take a look.

    opened by danielgindi 6
  • Added a new group feature for radio button functionality

    Added a new group feature for radio button functionality

    I'm not sure what you think about this, but I've added some functionality that enables the creation of radio button groups. This allows for the definition of a group of check boxes where only one can be selected at a time, and it can optionally disallow no selections in that group.

    If you like the idea I can add some documentation to the README file before merging.

    Here's basics on how it works.

    Say we have 3 checkboxes that we want to group:

    @property (strong, nonatomic) IBOutlet BEMCheckBox *checkBox1;
    @property (strong, nonatomic) IBOutlet BEMCheckBox *checkBox2;
    @property (strong, nonatomic) IBOutlet BEMCheckBox *checkBox3;
    

    We create a group for the checkboxes:

    @property (strong, nonatomic) BEMCheckBoxGroup *group;
    

    Then we add the checkboxes to the group:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        self.group = [BEMCheckBoxGroup groupWithCheckBoxes:@[self.checkBox1, self.checkBox2, self.checkBox3]];
        self.group.selectedCheckBox = self.checkBox2; // Optionally set which checkbox is pre-selected
        self.group.mustHaveSelection = YES; // Define if there can be no checkboxes selected
    }
    

    That's it. You can find out which box is currently selected in the group by asking for it:

    BEMCheckBox *selection = self.group.selectedCheckBox;
    

    We can also manually change which box is selected at any time, which will automatically update the other group's box states as well:

    self.group.selectedCheckBox = self.checkBox1; // Boxes 2 and 3 will be deselected if one is selected
    

    Of course, the target action and delegate callbacks will all get sent as expected.

    Let me know any feedback you have. Hopefully this will be useful.

    enhancement 
    opened by Vortec4800 6
  • tags and multiple checkboxes

    tags and multiple checkboxes

    What is the best scenario for this?

    30 checkboxes in 10 tableviewcells, 3 checkboxes in each cell. each defined with tags (a.tag = 101; b.tag = 201; c.tag = 301;) a,b,c are every checkbox has a defined value (how can we achieve this ??) - Example: a.value = @"this is a value"; b.value = [NSDate new]; etc.

    Now, i want to get the value tapped on a checkbox when is checked or unchecked (.on event) and to populate the checkboxes with data coming from a json file (matrix of checks?)

    Any good idea on how to approach this?

    Thanks. Chris

    question 
    opened by i-am-chris 6
  • BEMCheckBox object cannot be an outlet in Swift

    BEMCheckBox object cannot be an outlet in Swift

    Hi,

    I'm using your library and it's truly awesome, congrats =)

    I'm suffering a little issue and perhaps you might help me. I've placed an UIView and changed its class to BEMCheckBox afterwards from Storyboard. Everything is running pretty well, but when I try to make an outlet from the BEMCheckBox object in Storyboard to my View Controller I'm getting the next 2 errors:

    'weak' may only be applied to class and class-bound protocol types, not '<<error type>>'
    Use of undeclared type 'BEMCheckBox'
    

    This is the outlet:

    @IBOutlet weak var taskCheckBox: BEMCheckBox!
    

    I'm using Swift and I had to create a bridge. Any idea of what's happening?

    help wanted question 
    opened by rubenjimenez 6
  • Using `on` property requires `reload` and loses animation

    Using `on` property requires `reload` and loses animation

    If the on value is set without calling reload, the entire checkbox disappears. It is actually still tappable, and would re-appear when it is tapped to on.

    Then I tried calling reload after changing on value. This time the checkbox won't disappear, but the on/off animation will be gone forever in this checkbox instance.

    bug question 
    opened by danie11am 6
  • Assigning Delegate

    Assigning Delegate

    If this checbox is a property of a UITableViewCell how do you recieve the delegate method of didTapOn? Perhaps i'm doing this wrong, but i've tried to assign the delegate within my custom tableviewcell and within my cellForRowAtIndexPath inside my tableViewController and still that delegate method does not fire when tapping on the checkbox.

    question 
    opened by emtjoshhart 5
  • Clipped border

    Clipped border

    It seems, that BEMPathManager doesn't take into account lineWidth, therefore drawings of the box will be clipped at the bottom by container view and drawings of the checkmark will be slightly skewed downwards

    bug 
    opened by Emailrus 5
  • Update Package.swift

    Update Package.swift

    "Platforms" in Package.swift should be updated from iOS v8 to iOS v9 to reflect the minimum supported deployment target version and thus silence a warning when using Swift Package Manager.

    opened by antonmartinsson 0
  • Add delegate function

    Add delegate function "ShouldChange"

    Hi, may I propose some enhancement: It would be beneficial to have a delegate function like "shouldChange" with Bool result that gets called just before any state change (selected, unselected) happens triggered form UI. In case the delegate returns false, no change happens and the box stays as it is. Default behaviour: Allow changes. Something similar is available e.g. for UITextField. I have situations, where I need to run checks or calculations before allowing to switch the state. In addition the state sometimes is populated from a popup where multiple entries are required to allow the state become true - clicking on the checkbox with this delegate function would allow me to trigger the popup easily and avoid the user being able to manually check the box. Would keep things simple and avoid having to work with additional gesture recognizers above the box. Regards Oggerschummer

    enhancement 
    opened by Oggerschummer 1
  • "BEMCheckBox.xcconfig couldn't be open because there is no such file"

    Already updated cocoapods, carthage manager, and podfile and BEMCheckBox dependencies, has anyone faced this before?

    Error says the following:

    Dependency Analysis Error "The file “BEMCheckBox.xcconfig” couldn’t be opened because there is no such file. (/Users/thizzle/Documents/bebolt-ios/Pods/Target Support Files/BEMCheckBox/BEMCheckBox.xcconfig) error: unable to read module map contents from 'Target Support Files/BEMCheckBox/BEMCheckBox.modulemap': Error Domain=NSCocoaErrorDomain Code=260 "The file “BEMCheckBox.modulemap” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/thizzle/Documents/bebolt-ios/Pods/Target Support Files/BEMCheckBox/BEMCheckBox.modulemap, NSUnderlyingError=0x7fb24dfb6e80 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

    opened by tinahaibodi 0
Releases(1.4.1)
Owner
Boris Emorine
Boris Emorine
RadioGroup - The missing iOS radio buttons group.

RadioGroup The missing iOS radio buttons group. Usage let radioGroup = RadioGroup(titles: ["First Option Title", "Another Option Title", "Last"]) radi

Yonat Sharon 188 Dec 20, 2022
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
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
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
Simple customizable iOS bottom menu works like Tabbar, in Swift

SSCustomTabMenu Simple customizable iOS bottom menu works like Tabbar, in Swift. Features Simple and customizable iOS Tab Menu items, in Swift. Requir

Simform Solutions 81 Aug 3, 2022
Simple ui check box

CheckBox Example To run the example project, clone the repo, and run pod install from the Example directory first.

Jamal Alaayq 4 Jan 8, 2020
Customizable CheckBox / RadioButton component for iOS

GDCheckbox An easy to use CheckBox/Radio button component for iOS, with Attributes inspector support. Requirements Xcode 10+ Swift 5 iOS 9+ Installati

Saeid 23 Oct 8, 2022
UICollectionViewCell with checkbox when it isSelected and empty circle when not - like Photos.app "Select" mode.

CheckmarkCollectionViewCell UICollectionViewCell with checkbox when it isSelected and empty circle when not - like Photos.app "Select" mode. Usage cla

Yonat Sharon 62 Oct 19, 2022
JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box.

JustPersist JustPersist is the easiest and safest way to do persistence on iOS with Core Data support out of the box. It also allows you to migrate to

Just Eat 167 Mar 13, 2022
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.

Features Variable PIN length Underline, border and custom styles The error status with / without shake animation Resetting the error status manually,

Vladimir Kokhanevich 95 Nov 24, 2022
iOS SDK for the Box Content API

Box iOS SDK Getting Started Docs: https://developer.box.com/guides/mobile/ios/quick-start/ NOTE: The Box iOS SDK in Objective-C (prior to v3.0.0) has

Box 112 Dec 19, 2022
LogDog is designed to work out of the box, you can use the pre-configured logger anytime, anywhere

LogDog user-friendly logging apple/swift-log api compatible Usage LogDog is designed to work out of the box, you can use the pre-configured logger any

Luo Xiu 21 Aug 14, 2022
A quick and simple way to authenticate a Box user in your iPhone or iPad app.

BoxSimpleOAuth A quick and simple way to authenticate a Box user in your iPhone or iPad app. Adding BoxSimpleOAuth to your project CocoaPods CocoaPods

Ryan Baumbach 15 Mar 10, 2021
Automate box any value! Print log without any format control symbol! Change debug habit thoroughly!

LxDBAnything Automate box any value! Print log without any format control symbol! Change debug habit thoroughly! Installation You only need drag LxD

DeveloperLx 433 Sep 7, 2022
A highly configurable and out-of-the-box-pretty UI library

We absolutely love beautiful interfaces! As an organization named Unicorn, we are obligated to be unique and majestic.

Clayton (McIlrath) Unicorn 225 Feb 11, 2022