Skip to content

stoto/M13Checkbox

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 setup for any string. Just initialize with a string, and M13Checkbox will figure out the width for you.
  • The height can be changed. *You can add your own shape if desired! *No images! Everything is drawn with code!

screenshot

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)initWithTitle:(NSString *)title andHeight:(CGFloat)height: Creates a checkbox with the height specified, 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)setTitle:(NSString *)title: Sets the title of the titleLabel, and resizes the width of the contra's frame to fit that text.
  • - (void)setState:(M13CheckboxState)state: Sets the state of the checkbox to the state given.
  • - (void)toggleState: 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) 2012 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.

About

A customizeable checkbox for iOS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 100.0%