From d5cad4de7455d5d4c71150080b8413f525534e7a Mon Sep 17 00:00:00 2001 From: Igor Kulman Date: Tue, 29 Sep 2020 18:14:41 +0200 Subject: [PATCH 1/3] Border and checkmark style available to use with UIAppearance --- checkbox/Checkbox.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/checkbox/Checkbox.swift b/checkbox/Checkbox.swift index 7974535..398552b 100644 --- a/checkbox/Checkbox.swift +++ b/checkbox/Checkbox.swift @@ -13,7 +13,7 @@ public class Checkbox: UIControl { // MARK: - Enums /// Shape of the center checkmark that appears when `Checkbox.isChecked == true`. - public enum CheckmarkStyle { + @objc public enum CheckmarkStyle: Int { /// ■ case square /// ● @@ -27,7 +27,7 @@ public 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: Int { /// ▢ case square /// ◯ @@ -39,14 +39,14 @@ public 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 /// 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 /// Width of the borders stroke. /// From 013c212d5953241ecb8ff1919e8e97ebd3cfad5d Mon Sep 17 00:00:00 2001 From: Darren Jones Date: Sat, 17 Oct 2020 16:40:49 +0100 Subject: [PATCH 2/3] Updated demo for Xcode 12 --- CheckboxDemo.xcodeproj/project.pbxproj | 4 +++- .../xcshareddata/xcschemes/SimpleCheckbox.xcscheme | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CheckboxDemo.xcodeproj/project.pbxproj b/CheckboxDemo.xcodeproj/project.pbxproj index b0a0a74..fd6d9bf 100644 --- a/CheckboxDemo.xcodeproj/project.pbxproj +++ b/CheckboxDemo.xcodeproj/project.pbxproj @@ -182,7 +182,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1200; ORGANIZATIONNAME = "Beau Nouvelle"; TargetAttributes = { 8B94E59120BE7E9E003BA7E2 = { @@ -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; @@ -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; diff --git a/CheckboxDemo.xcodeproj/xcshareddata/xcschemes/SimpleCheckbox.xcscheme b/CheckboxDemo.xcodeproj/xcshareddata/xcschemes/SimpleCheckbox.xcscheme index d91236d..8317925 100644 --- a/CheckboxDemo.xcodeproj/xcshareddata/xcschemes/SimpleCheckbox.xcscheme +++ b/CheckboxDemo.xcodeproj/xcshareddata/xcschemes/SimpleCheckbox.xcscheme @@ -1,6 +1,6 @@ - - - - Date: Sat, 17 Oct 2020 16:41:01 +0100 Subject: [PATCH 3/3] Added storyboard (IBDesignable) support --- checkbox/Checkbox.swift | 41 +++++++++++++++++++--------- demo/Base.lproj/Main.storyboard | 47 +++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/checkbox/Checkbox.swift b/checkbox/Checkbox.swift index 7974535..606f85c 100644 --- a/checkbox/Checkbox.swift +++ b/checkbox/Checkbox.swift @@ -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 public class Checkbox: UIControl { // MARK: - Enums /// Shape of the center checkmark that appears when `Checkbox.isChecked == true`. - public enum CheckmarkStyle { + public enum CheckmarkStyle: String { /// ■ case square /// ● @@ -27,7 +28,7 @@ public 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 { + public enum BorderStyle: String { /// ▢ case square /// ◯ @@ -40,6 +41,14 @@ public class Checkbox: UIControl { /// /// **Default:** `CheckmarkStyle.square` 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. /// @@ -47,6 +56,14 @@ public class Checkbox: UIControl { /// /// **Default:** `BorderStyle.square` 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. /// @@ -57,27 +74,27 @@ public 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") @@ -86,13 +103,13 @@ public 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. /// @@ -101,7 +118,7 @@ public 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 @@ -112,14 +129,14 @@ public 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? diff --git a/demo/Base.lproj/Main.storyboard b/demo/Base.lproj/Main.storyboard index f6562a9..9444348 100644 --- a/demo/Base.lproj/Main.storyboard +++ b/demo/Base.lproj/Main.storyboard @@ -1,11 +1,9 @@ - - - - + + - + @@ -20,7 +18,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +