Git Product home page Git Product logo

m13checkbox's Introduction

M13Checkbox

A customizable checkbox for iOS that mimics the checkbox found on OS X, and Safari.

Features:

  • Simple to setup, just initialize with the desired parameters, and add to your subview.
  • Many customizable settings to make it easy to seamlessly integrate with your app.
  • All appearance settings follow the UIAppearance protocol.
  • Can be a standalone checkbox, or add a title.
  • Easy resizing. Use the provided methods to resize the control's width to the content, and change the font size based on the height of the checkbox.
  • Resizeable!
  • You can add your own shape if desired!
  • No images! Everything is drawn with code!

Examples:

Default

Resizable

Supports Titles

Custom Size With Text

Custom Size and Multiline Text

Text Alignment

Supports a Mixed State

OS X Styling

Custom Stroke

Custom Colors

Custom Corner Radius

Control Disabling

Initialization:

  • - (id)init:Creates a checkbox with the default height, and no text.
  • - (id)initWithFrame:(CGRect)frame: Creates a checkbox with the specified frame, and no text. The box will just fill the height of the frame.
  • - (id)initWithTitle:(NSString *)title: Creates a checkbox with the default height, and the specified text. The width of the frame will be changed to make the text fit.
  • - (id)initWithFrame:(CGRect)frame title:(NSString *)title: Creates a checkbox with the default, and the given text. The width of the frame will be changed to make the text fit.

Properties:

  • M13CheckboxState checkState: There are three checkbox states available:
    • M13CheckboxStateUnchecked (default)
    • M13CheckboxStateChecked
    • M13CheckboxStateMixed
  • (UILabel *)titleLabel: The title label will appear if one sets a string for it to display. The label will fill the control's frame minus the frame of the checkbox itself.
  • M13CheckboxAlignment checkAlignment: Determines if the checkbox is to the left or right of the text. Follows the UIAppearance protocol. The possible values are:
    • M13CheckboxAlignmentLeft - Checkbox is to the left of the text.
    • M13CheckboxAlignmentRight - Checkbox is to the right of the text. (default)
  • CGRect boxFrame: Frame of the checkbox itself in the control's frame, just in case one would need to separate the frames of the titleLabel, and the checkbox. (READ ONLY).
  • - (id)value: Returns a custom value that is associated with a specific M13CheckboxState. The values returned come from these properties:
    • id checkedValue
    • id uncheckedValue
    • id mixedValue

Appearance Properties:

All Properties follow the UIAppearance protocol.

  • BOOL flat: If YES, the checkbox draws with solid color instead of gradients. (default is NO.)
  • CGFloat strokeWidth: The width of the stroke around the box. (default is 5% of the height of the control's frame.)
  • UIColor *strokeColor: The color of the stroke around the box. (default is [UIColor colorWithRed: 0.167 green: 0.198 blue: 0.429 alpha: 1])
  • UIColor *checkColor: The color of the checkmark. (default is [UIColor colorWithRed:0.0 green:0.129 blue:0.252 alpha:1.0])
  • UIColor *tintColor: The color of the checkbox when checked or mixed. (default is [UIColor colorWithRed: 0.616 green: 0.82 blue: 0.982 alpha: 1])
  • UIColor *uncheckedColor: The color of the checkbox when unchecked. (default is [UIColor colorWithRed:0.925 green:0.925 blue:0.925 alpha:1.0])
  • CGFloat radius: The radius of the corners of the box. (default is 18.75% of the boxes height.)

Extra Methods:

  • - (void)setCheckState:(M13CheckboxState)state: Sets the state of the checkbox to the state given.
  • - (void)toggleCheckState: Toggles the state between M13CheckboxStateUnchecked, and M13CheckboxStateChecked
  • - (void)autoFitFontToHeight: Changes the font size, so it fills the height of the frame.
  • - (void)autoFitWidthToText: Changes the width of the frame to fit the titleLabel's text.
  • - (UIBezierPath *)getDefaultShape: Override this method to specify your own shape to draw instead of the checkmark. All distances should be specified as percentages of the height of the frame.

License:

MIT License

Copyright (c) 2014 Brandon McQuilkin

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.

m13checkbox's People

Contributors

0x0c avatar andreacremaschi avatar benaneesh avatar bryanone avatar cbs avatar jaltin avatar jefmwols avatar marxon13 avatar ninjakittenproductions avatar uberjason avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.