https://github.com/Boris-Em/BEMCheckBox

BEMCheckBox

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


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

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

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 basically 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

https://github.com/Boris-Em/BEMCheckBox的更多相关文章

  1. 转载请注明出处: https://github.com/qiu-deqing/FE-interview

    转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...

  2. https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/

        https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ ...

  3. fatal: could not read Username for 'https://github.com': No such file or directo

    Git push origin master报错 fatal: could not read Username for 'https://github.com': No such file or di ...

  4. 结合个人经历总结的前端入门方法 (转自https://github.com/qiu-deqing/FE-learning)

    结合个人经历总结的前端入门方法 (https://github.com/qiu-deqing/FE-learning),里面有很详细的介绍. 之前一直想学习前端的,都不知道怎么下手都一年了啥也没学到, ...

  5. (2016 年) githup 博客地址 : https://github.com/JMWY/MyBlog

    githup 博客地址 : https://github.com/JMWY/MyBlog

  6. MJExtension的使用:https://github.com/CoderMJLee/MJExtension

    MJExtension能做什么? MJExtension是一套字典和模型之间互相转换的超轻量级框架 MJExtension能完成的功能 字典(JSON) --> 模型(Model) 模型(Mod ...

  7. MBProgressHUD框架的使用:https://github.com/jdg/MBProgressHUD

    MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgressHUD,然后把两个MBProgressHUD.h和MBP ...

  8. https://github.com/akullpp/awesome-java

    java stack https://github.com/akullpp/awesome-java

  9. https://github.com/oneuijs/You-Dont-Need-jQuery

    https://github.com/oneuijs/You-Dont-Need-jQuery

随机推荐

  1. First Project -用函数写的ATM+购物商城程序

    作业需求:模拟实现一个ATM + 购物商城程序 额度15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日,过期未还,按欠 ...

  2. 浅谈GFC

    Web页面的布局,我们常见的主要有“浮动布局(float)”.“定位布局(position)”.“行内块布局(inline-block)”.“CSS3的多栏布局(Columns)”.“伸缩布局(Fle ...

  3. 【原】thinkphp修改Redis操作类,支持选择数据库功能及添加其他方法

    版本3.2.2(ThinkPHP\Library\Think\Cache\Driver\Redis.class.php), 一:官方默认不支持选择数据库功能及,现就可选择数据库功能进行说明. 1 co ...

  4. 学习笔记——网络编程3(基于TCP协议的网络编程)

    TCP协议基础 IP协议是Internet上使用的一个关键协议,它的全称是Internet Protocol,即Internet协议,通常简称IP协议.   使用ServerSocket创建TCP服务 ...

  5. telnet mysql3306端口失败

    在linux上telnet远程mysql端口失败,经过上网查找后,找到多种方法. (1)我在本地的Navicat上新增了一个用户,主机名是linux的ip,也可以是 %(百分号代表这个用户可以在任何地 ...

  6. 2019西安多校联训 Day4

    T1 大水题!!难度简单,显然的贪心策略即可,but... 思路:首先我们按与i点作战后活下来的士兵排序,然后 若当前剩余兵力足够直接减掉战斗死亡人数,如果不够就加 够再打它,但是!我们在考完试观察测 ...

  7. xmpp 消息和好友上下线(3)

    原始地址:XMPPFrameWork IOS 开发(四) 消息 //收到消息 - (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XM ...

  8. css 实现鼠标滑过流光效果

    来划我啊 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  9. 面试总结——Java高级工程师(一)

    一.无笔试题 不知道是不是职位原因还是没遇到,面试时,都不需要做笔试题,而是填张个人信息表格,或者直接面试 二.三大框架方面问题 1.Spring 事务的隔离性,并说说每个隔离性的区别 解答:spri ...

  10. MyBatis 的基本要素—SQL 映射文件

    MyBatis 真正的强大在于映射语句,相对于它强大的功能,SQL 映射文件的配置却是相当简单.对比 SQL 映射配置和 JDBC 代码,发现使用 SQL 映射文件配置可减少 50% 以上的代码,并且 ...