Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BeauNouvelle authored Oct 18, 2020
2 parents ed0442e + 6b3ce4e commit c64d484
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 25 deletions.
4 changes: 3 additions & 1 deletion CheckboxDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = "Beau Nouvelle";
TargetAttributes = {
8B94E59120BE7E9E003BA7E2 = {
Expand Down Expand Up @@ -370,6 +370,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -429,6 +430,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:CheckboxDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
46 changes: 32 additions & 14 deletions checkbox/Checkbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import UIKit

/// Checkbox is a simple, animation free checkbox and UISwitch alternative designed
/// to be performant and easy to implement.
@IBDesignable
open class Checkbox: UIControl {

// MARK: - Enums

/// Shape of the center checkmark that appears when `Checkbox.isChecked == true`.
public enum CheckmarkStyle {
@objc public enum CheckmarkStyle: String {
/// ■
case square
/// ●
Expand All @@ -27,7 +28,8 @@ open class Checkbox: UIControl {
/// Shape of the outside box containing the checkmarks contents.
///
/// Used as a visual indication of where the user can tap.
public enum BorderStyle {

@objc public enum BorderStyle: String {
/// ▢
case square
/// ◯
Expand All @@ -39,14 +41,30 @@ open class Checkbox: UIControl {
/// Shape of the center checkmark that appears when `Checkbox.isChecked == true`.
///
/// **Default:** `CheckmarkStyle.square`
public var checkmarkStyle: CheckmarkStyle = .square
@objc dynamic public var checkmarkStyle: CheckmarkStyle = .square
@IBInspectable private var checkmarkStyleIB: String {
set {
checkmarkStyle = CheckmarkStyle(rawValue: newValue) ?? .square
}
get {
return checkmarkStyle.rawValue
}
}

/// Shape of the outside border containing the checkmarks contents.
///
/// Used as a visual indication of where the user can tap.
///
/// **Default:** `BorderStyle.square`
public var borderStyle: BorderStyle = .square
@objc dynamic public var borderStyle: BorderStyle = .square
@IBInspectable private var borderStyleIB: String {
set {
borderStyle = BorderStyle(rawValue: newValue) ?? .square
}
get {
return borderStyle.rawValue
}
}

/// Width of the borders stroke.
///
Expand All @@ -57,27 +75,27 @@ open class Checkbox: UIControl {
/// in order appear similar next to other border styles.
///
/// **Default:** `2`
public var borderLineWidth: CGFloat = 2
@IBInspectable public var borderLineWidth: CGFloat = 2

/// Size of the center checkmark element.
///
/// Drawn as a percentage of the size of the Checkbox's draw rect.
///
/// **Default:** `0.5`
public var checkmarkSize: CGFloat = 0.5
@IBInspectable public var checkmarkSize: CGFloat = 0.5

/// The checboxes border color in its unchecked state.
///
/// **Default:** The current tintColor.
public var uncheckedBorderColor: UIColor!
@IBInspectable public var uncheckedBorderColor: UIColor!

/// The checboxes border color in its checked state.
///
/// **Default:** The current tintColor.
public var checkedBorderColor: UIColor!
@IBInspectable public var checkedBorderColor: UIColor!

/// **Default:** The current tintColor.
public var checkmarkColor: UIColor!
@IBInspectable public var checkmarkColor: UIColor!

/// **Default:** White.
@available(swift, obsoleted: 4.1, renamed: "checkboxFillColor", message: "Defaults to a clear color")
Expand All @@ -86,13 +104,13 @@ open class Checkbox: UIControl {
/// The checkboxes fill color.
///
/// **Default:** `UIColoe.Clear`
public var checkboxFillColor: UIColor = .clear
@IBInspectable public var checkboxFillColor: UIColor = .clear

/// Sets the corner radius for the checkbox border.
///
///**Default:** `0.0`
/// - Note: Only applies to checkboxes with `BorderStyle.square`
public var borderCornerRadius: CGFloat = 0.0
@IBInspectable public var borderCornerRadius: CGFloat = 0.0

/// Increases the controls touch area.
///
Expand All @@ -101,7 +119,7 @@ open class Checkbox: UIControl {
/// This property helps with that.
///
/// **Default:** `5`
public var increasedTouchRadius: CGFloat = 5
@IBInspectable public var increasedTouchRadius: CGFloat = 5

/// A function can be passed in here and will be called
/// when the `isChecked` value changes due to a tap gesture
Expand All @@ -112,14 +130,14 @@ open class Checkbox: UIControl {

/// Indicates whether the checkbox is currently in a state of being
/// checked or not.
public var isChecked: Bool = false {
@IBInspectable public var isChecked: Bool = false {
didSet { setNeedsDisplay() }
}

/// Determines if tapping the checkbox generates haptic feedback to the user.
///
/// **Default:** `true`
public var useHapticFeedback: Bool = true
@IBInspectable public var useHapticFeedback: Bool = true

private var feedbackGenerator: UIImpactFeedbackGenerator?

Expand Down
47 changes: 42 additions & 5 deletions demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13168.3" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13147.4"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,7 +18,46 @@
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="k6k-5C-b4j" customClass="Checkbox" customModule="SimpleCheckbox">
<rect key="frame" x="157.5" y="303.5" width="60" height="60"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="bzZ-jx-qpT"/>
<constraint firstAttribute="width" secondItem="k6k-5C-b4j" secondAttribute="height" multiplier="1:1" id="vzd-ge-Anl"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="borderLineWidth">
<real key="value" value="10"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="isChecked" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="borderCornerRadius">
<real key="value" value="17"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="checkmarkStyleIB" value="tick"/>
<userDefinedRuntimeAttribute type="number" keyPath="checkmarkSize">
<real key="value" value="0.40000000000000002"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="checkedBorderColor">
<color key="value" red="0.95511585470000004" green="0.46605300900000002" blue="0.13618868589999999" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="uncheckedBorderColor">
<color key="value" red="0.28454998139999998" green="0.64039236310000003" blue="0.2571377158" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="checkmarkColor">
<color key="value" red="0.1752920151" green="0.58287692069999997" blue="0.84259629250000001" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="checkboxFillColor">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="borderStyleIB" value="circle"/>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="k6k-5C-b4j" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="3rq-nc-UQi"/>
<constraint firstItem="k6k-5C-b4j" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="elp-DN-3os"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down

0 comments on commit c64d484

Please sign in to comment.