项目介绍:
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
Single selection, two columns, solid border with title
Single selection, two columns, no border
Multiple selections, single column, no border
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 using Cocoapods
CocoaPods manages library dependencies for your Xcode projects. If you haven’t used it before, take a look here.
-
Add
pod 'iCheckbox'
to yourPodfile
. -
Run
pod install
.
Note: If this is very first pod installed in your project don’t
forget to open .xcworkspace
file not .xcodeproj
.
Install manually
-
Drag the
iCheckbox.xcodeproj
to your project. Go to app target’s settings, press the “+” under theEmbedded Binaries
section, and select theiCheckbox.framework
-
Add
@import iCheckbox
in your class. -
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 iCheckboxState
s, 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.