iCheckbox 2.0.0

iCheckbox 2.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2016
SPMSupports SPM

Maintained by Stefan Godoroja.



iCheckbox 2.0.0

iCheckbox

A custom checkbox component for iOS apps, written in Swift 3.0. Checkboxes can be ordered in one or two columns, can have solid borders with or without rounded corners, single or multiple selections, etc. iCheckbox works with iOS 8 and newer, also can be used in an Objective-C project.

See few examples:

Single selection, two columns, rounded corners solid border with title

ve49bsufoe

Single selection, two columns, solid border with title

hpqth224qj

Single selection, two columns, no border

plnuwbl9nf

Multiple selections, single column, no border

multiple

Library offers checkbox/checkbox pool customization:

  • Checkbox

    • Normal state title color
    • Selected state title color
    • Normal state image
    • Selected state image
    • Size

  • Checkbox pool

    • Position on canvas
    • Selection type
    • Pool style
    • Border type
    • Border width
    • Border color
    • Border corner radius
    • Header title color

Install manually

  1. Drag the iCheckbox.xcodeproj to your project. Go to app target’s settings, press the “+” under the Embedded Binaries section, and select the iCheckbox.framework
  2. Add @import iCheckbox in your class.
  3. That’s all.

Getting Started

Using iCheckbox is straightforward. Use iCheckboxBuilderConfig to create a configuration instance for the iCheckboxBuilder which will render checkboxes. iCheckboxBuilderConfig contains values to setup checkbox title color, checkbox states images, checkbox pool border, etc. Except iCheckboxBuilderConfig, iCheckboxBuilder takes a series of iCheckboxStates, each of them describing a checkbox, it’s title and selected state. To get notified when a checkbox is tapped, interested class must implement iCheckboxDelegate’s didSelectCheckbox() method.

Full example:

Swift

class ViewController: UIViewController, iCheckboxDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        addCheckboxes()
    }

    func addCheckboxes() {
        var checkboxBuilderConfig = iCheckboxBuilderConfig()
        checkboxBuilderConfig.headerTitle = "Some title"

        let checkboxBuilder = iCheckboxBuilder(withCanvas: self.view, andConfig: checkboxBuilderConfig)
        checkboxBuilder.delegate = self

        var firstCheckboxState = iCheckboxState()
        firstCheckboxState.title = "One"
        var secondCheckboxState = iCheckboxState()
        secondCheckboxState.title = "Two"
        var thirdCheckboxState = iCheckboxState()
        thirdCheckboxState.title = "Three"
        var fourthCheckboxState = iCheckboxState()
        fourthCheckboxState.title = "Four"
        var fifthCheckboxState = iCheckboxState()
        fifthCheckboxState.title = "Five"
        var sixthCheckboxState = iCheckboxState()
        sixthCheckboxState.title = "Six"
        var seventhCheckboxState = iCheckboxState()
        seventhCheckboxState.title = "Seven"
        checkboxBuilder.addCheckboxes(withStates: [firstCheckboxState,
                                                   secondCheckboxState,
                                                   thirdCheckboxState,
                                                   fourthCheckboxState,
                                                   fifthCheckboxState,
                                                   sixthCheckboxState,
                                                   seventhCheckboxState])
    }

    func didSelectCheckbox(withState state: Bool, identifier: Int, andTitle title: String) {
        print("Checkbox '\(title)', has selected state: \(state)")
    }
  }

Objective-C

#import "ViewController.h"
@import iCheckbox;

@interface ViewController () <iCheckboxDelegate>
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    iCheckboxBuilderConfig *buiderConfig = [[iCheckboxBuilderConfig alloc] init];
    buiderConfig.headerTitle = @"Some Title";
    iCheckboxBuilder *builder = [[iCheckboxBuilder alloc] initWithCanvas:self.view
                                                               andConfig:buiderConfig];
    builder.delegate = self;

    iCheckboxState *firstCheckbox = [[iCheckboxState alloc] initWithTitle:@"First"
                                                                 selected:NO];
    iCheckboxState *secondCheckbox =  [[iCheckboxState alloc] initWithTitle:@"Second"
                                                                  selected:NO];
    iCheckboxState *thirdCheckbox =  [[iCheckboxState alloc] initWithTitle:@"Third"
                                                                  selected:NO];
    iCheckboxState *fourthCheckbox =  [[iCheckboxState alloc] initWithTitle:@"Four"
                                                                  selected:NO];
    iCheckboxState *fifthCheckbox =  [[iCheckboxState alloc] initWithTitle:@"Five"
                                                                  selected:NO];
    iCheckboxState *sixthCheckbox =  [[iCheckboxState alloc] initWithTitle:@"Six"
                                                                  selected:NO];
    iCheckboxState *seventhCheckbox =  [[iCheckboxState alloc] initWithTitle:@"Seven"
                                                                  selected:NO];
    [builder addCheckboxesWithStates:@[firstCheckbox,
                                       secondCheckbox,
                                       thirdCheckbox,
                                       fourthCheckbox,
                                       fifthCheckbox,
                                       sixthCheckbox,
                                       seventhCheckbox]];
}

- (void)didSelectCheckboxWithState:(BOOL)state identifier:(NSInteger)identifier andTitle:(NSString *)title
{
    NSLog(@"Checkbox %@, has selected state: %d", title, state);
}

@end

TODO

  • Add support for OSX, tvOS and watchOS.
  • More customization options.
  • Add unit tests.
  • Add Carthage support.

Contact

If you detect any issues or want a feature to be added, create an issue or generate a pull request. Alternatively you can contact me on twitter.

License

MIT License

Copyright © 2016 Stefan Godoroja

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.