• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Customisable checkbox class for Objective-C

Custom checkboxes for Objective-C

U can use the TNCheckBoxGroup class to use some pre-built checkboxes, or you can extend it really easy to suit your own design. Every checkbox has a selected animation. When the text is longer then the available space, it will automatically wrap the text over multiple lines.

The current version supports 3 different checkboxes:

  1. Circle checkbox

  2. Square checkbox

  3. Custom image checkbox

Screenshot

Installation

##Manual

  • Just drag the files in the src folder to your project.
  • Import the checkbox class you want to use.

##Cocoapods

  • Add pod 'TNCheckBoxGroup' to your Podfile.
  • Done.

How to use

Import the TNCheckBoxGroup.h file.

Create data objects for every option in your checkbox group. You can use the following data objects: TNCircularCheckBoxData, TNRectangularCheckBoxData, TNImageCheckBoxData.

Every data object extends TNCheckBoxData, but has specific properties you can set.

You can set the following properties on every data object:

Property What does it do
identifier Set a human readeble name for the checkbox
labelText Set the text for the label
checked Set the checked state
labelFont Set the font for the label
labelColor Set the color for the label

The different classes have the following extra properties:

TNCircularCheckBoxData

Arguments What does it do
borderColor Set the border color for the outer circle
circleColor Set the color for the inner circle
borderRadius Set the radius for the outer circle
circleRadius Set the color for the inner circle

Example

TNCircularCheckBoxData *bananaData = [[TNCircularCheckBoxData alloc] init];
bananaData.identifier = @"banana";
bananaData.labelText = @"Banana";
bananaData.checked = YES;
bananaData.borderColor = [UIColor blackColor];
bananaData.circleColor = [UIColor blackColor];
bananaData.borderRadius = 20;
bananaData.circleRadius = 15;

TNRectangularCheckBoxData

Arguments What does it do
borderColor Set the border color for the outer rectangle
rectangleColor Set the color for the inner rectangle
borderWidth Set the width for the outer rectangle
borderHeight Set the height for the outer rectangle
rectangleWidth Set the width for the inner rectangle
rectangleHeight Set the height for the inner rectangle

Example

TNRectangularCheckBoxData *tennisData = [[TNRectangularCheckBoxData alloc] init];
tennisData.identifier = @"tennis";
tennisData.labelText = @"Tennis";
tennisData.borderColor = [UIColor grayColor];
tennisData.rectangleColor = [UIColor grayColor];
tennisData.borderWidth = tennisData.borderHeight = 20;
tennisData.rectangleWidth = tennisData.rectangleHeight = 15;

TNImageCheckBoxData

Arguments What does it do
selectedImage Set the image for the selected state
unselectedImage Set the image for the unselected state

Example

TNImageCheckBoxData *manData = [[TNImageCheckBoxData alloc] init];
manData.identifier = @"man";
manData.labelText = @"Man";
manData.checkedImage = [UIImage imageNamed:@"checked"];
manData.uncheckedImage = [UIImage imageNamed:@"unchecked"];

When you have created the different data objects, you can create an instance of TNCheckBoxGroup and pass an array with the data objects and set the layout. The style can be horizontal or vertical.

You can also set the margin between each item via the marginBetweenItems property. By default it's set to 15 pixels.

If you want, you can also set the identifier property to have a human readable name for the group.

Call the create method and set the position property to place the group at a specific point. Don't worry about the frame, this will be automatically calculated. And add the object to the view hierarchy.

self.myGroup = [[TNCheckBoxGroup alloc] initWithCheckBoxData:@[manData, womanData] style:TNCheckBoxLayoutVertical];
[self.myGroup create];
self.myGroup.position = CGPointMake(25, 25);

[self addSubview:self.myGroup];

Done!

Getting change notifications

When the state of the checkbox group has changed, an NSNotification is broadcasted.

You can listen to the GROUP_CHANGED message.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGroupGotUpdated:) name:GROUP_CHANGED object:self.myGroup];

Getting list of checked checkboxes

Every TNCheckBoxGroup instance has a property checkedCheckBoxes, this will return an array with all checked checkboxes.

Getting list of unchecked checkboxes

Every TNCheckBoxGroup instance has a property uncheckedCheckBoxes, this will return an array with all unchecked checkboxes.

Styling checkboxes

Group-level

If you want to provide the same label font and color for all checkboxes in a specific group, you can set the labelFont and labelColor properties.

Checkbox-level

If you want to provide different label fonts and/or colors for specific checkboxes in a group, you can set the labelFont and labelColor properties on the TNCheckBox subclass.

Creating custom checkboxes

If you want it is really easy to add your own custom checkboxes.

  1. Create a data model class in which you store the specific data for your checkbox. This class needs to extend TNCheckBoxData.

  2. Create a checkbox class which extends TNCheckBox.

  3. Override the setup method (don't forget to call the super method at the end).

  4. Override the createCheckbox method, here you can draw your custom checkbox.

  5. Override the checkWithAnimation: method to supply your own animations when the checkbox state changes.

  6. There is no step 6.

Demo

There is a demo project added to this repository, so you can see how it works.

License

TNCheckBoxGroup published under the MIT license:

Copyright (C) 2014, Frederik Jacques

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.

More Repositories

1

sketch-favicon-exporter-template

Easily generate favicons for today's devices with Sketch.
219
star
2

TNSexyImageUploadProgress

An easy image upload visualiser for Objective-C
Objective-C
143
star
3

TNRadioButtonGroup

Create easy radio button groups in objective-c
Objective-C
143
star
4

TNImageSliderViewController

A Swift image slider component based on UICollectionView
Swift
90
star
5

native-ios-and-unity3d

Objective-C
56
star
6

DynamicColladaSceneKitPrototype

You can find more info about this prototype at http://www.the-nerd.be/2014/11/07/dynamically-load-collada-files-in-scenekit-at-runtime/
Objective-C
44
star
7

3d-touch-peek-and-pop-tutorial

This tutorial is part of a blog post
Swift
31
star
8

touchid-swift-tutorial

The project associated to the blog post on how to integrate TouchID.
Swift
26
star
9

objc-login-system

An easy way to create a login system in obj-c
Objective-C
22
star
10

TNSwiftyCheckboxGroup

A Swift component based on UICollectionView to create checkbox groups with various styles.
Swift
21
star
11

quick-actions-3d-touch-tutorial

Swift
19
star
12

TNColorScrollViewController

A view controller for Objective-C which creates a scrollview with view with different background colors.
Objective-C
15
star
13

TNInfoBubble

Prisma-style info bubbles for your iOS application
Swift
15
star
14

countrykit

Swift library with all continents, regions, subregions & countries of the world according to Standard Country or Area Codes for Statistical Use (UN M94).
Swift
12
star
15

vatnumberkit

VatNumberKit - A Swift VAT validation library for iOS & macOS
Swift
11
star
16

FaceRecognitionTrainer

iPhone prototype app for Face.com
Objective-C
9
star
17

TNGradientPickerSlider

TNGradientPickerSlider is a ready-to-use AppKit component which lets your users select multiple colors to build a gradient for your macOS application.
Swift
9
star
18

ios-pongwars

A Swift implementation of Pong Wars with SpriteKit.
Swift
6
star
19

messaging-objc-unity

Objective-C++
5
star
20

ZDepthAnimation

Mimic the National Geographic - National Parcs iPad app animation
Objective-C
4
star
21

uiscrollview-extensions

For the lazy ones who hate to divide offset.x by bounds.width
Shell
4
star
22

LightWeightCoreDataMigration

How to do a leightweight core data migration
Objective-C
2
star
23

UIFont-Enumerate

Swift extension to enumerate all available font families with their font names on the device
Ruby
2
star
24

UIColor-Hex-Swift

Create UIColor objects in Swift from a CSS color string or a hexadecimal integer.
Shell
1
star
25

cocoaheads-rxswift-primer

The demo project for my CocoaHeads presentation on November 22, 2017.
Swift
1
star
26

DictaPoint

A prototype mac app to grade students via voice recognition
C
1
star