### Carthage Installation Source: https://context7.com/boris-em/bemcheckbox/llms.txt Add BEMCheckBox to your project using Carthage by specifying the GitHub repository in your Cartfile and running 'carthage update'. ```text # Cartfile github "Boris-Em/BEMCheckBox" ``` -------------------------------- ### Swift Package Manager Installation Source: https://context7.com/boris-em/bemcheckbox/llms.txt Integrate BEMCheckBox using Swift Package Manager by adding the package dependency to your Package.swift file or through Xcode's package manager. ```swift // Package.swift dependencies: [ .package(url: "https://github.com/Boris-Em/BEMCheckBox", from: "1.0.0") ] ``` -------------------------------- ### CocoaPods Installation Source: https://context7.com/boris-em/bemcheckbox/llms.txt Add BEMCheckBox to your project using CocoaPods by including it in your Podfile. Ensure your platform is set to iOS 9.0 or higher. ```ruby # Podfile platform :ios, '9.0' use_frameworks! target 'YourApp' do pod 'BEMCheckBox' end ``` -------------------------------- ### Setting Checkbox State with `on` Property Source: https://context7.com/boris-em/bemcheckbox/llms.txt Use the `on` property to get or set the checkbox state instantly without animation. It defaults to `false`. This property can also be used to toggle the state. ```swift import BEMCheckBox // Get current state let isChecked = myCheckBox.on // Returns: false // Set state without animation myCheckBox.on = true // Toggle state myCheckBox.on = !myCheckBox.on ``` -------------------------------- ### Initialize BEMCheckBox Programmatically Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Create and add a checkbox instance to your view hierarchy. ```objective-c BEMCheckBox *myCheckBox = [[BEMCheckBox alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; [self.view addSubview:myCheckBox]; ``` -------------------------------- ### Animation Configuration Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Configure the animation properties for the BEMCheckbox. ```APIDOC ## Animations ### `animationDuration` - **Type**: `CGFloat` - **Description**: The duration in seconds of the animations. Defaults to `0.5`. ### `onAnimationType` - **Type**: `BEMAnimationType` - **Description**: The type of animation to use when the checkbox gets checked. Defaults to `BEMAnimationTypeStroke`. See `BEMAnimationType` below for possible values. ### `offAnimationType` - **Type**: `BEMAnimationType` - **Description**: The type of animation to use when the checkbox gets unchecked. Defaults to `BEMAnimationTypeStroke`. See `BEMAnimationType` below for possible values. ### `BEMAnimationType` - **Description**: The possible values for `onAnimationType` and `offAnimationType`. - **`BEMAnimationTypeStroke`** - **`BEMAnimationTypeFill`** - **`BEMAnimationTypeBounce`** - **`BEMAnimationTypeFlat`** - **`BEMAnimationTypeOneStroke`** - **`BEMAnimationTypeFade`** ``` -------------------------------- ### Terms and Conditions Form Implementation in Swift Source: https://context7.com/boris-em/bemcheckbox/llms.txt This code creates a view controller with three BEMCheckBox instances and a submit button. It configures the checkboxes, handles tap events via a delegate, and updates the submit button's enabled state and appearance based on whether the required checkboxes are selected. Use this for forms requiring user agreement to terms or privacy policies. ```swift import UIKit import BEMCheckBox class TermsViewController: UIViewController, BEMCheckBoxDelegate { var termsCheckBox: BEMCheckBox! var privacyCheckBox: BEMCheckBox! var newsletterCheckBox: BEMCheckBox! var submitButton: UIButton! override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white // Required: Terms checkbox termsCheckBox = createCheckBox(at: CGPoint(x: 30, y: 100)) termsCheckBox.delegate = self // Required: Privacy checkbox privacyCheckBox = createCheckBox(at: CGPoint(x: 30, y: 160)) privacyCheckBox.delegate = self // Optional: Newsletter checkbox newsletterCheckBox = createCheckBox(at: CGPoint(x: 30, y: 220)) newsletterCheckBox.onAnimationType = .bounce newsletterCheckBox.offAnimationType = .bounce // Submit button submitButton = UIButton(frame: CGRect(x: 30, y: 300, width: 200, height: 44)) submitButton.setTitle("Submit", for: .normal) submitButton.backgroundColor = .systemGray submitButton.isEnabled = false submitButton.addTarget(self, action: #selector(submitTapped), for: .touchUpInside) view.addSubview(submitButton) updateSubmitButton() } func createCheckBox(at origin: CGPoint) -> BEMCheckBox { let checkBox = BEMCheckBox(frame: CGRect(origin: origin, size: CGSize(width: 40, height: 40))) checkBox.boxType = .square checkBox.cornerRadius = 4.0 checkBox.lineWidth = 2.0 checkBox.onTintColor = .systemBlue checkBox.onFillColor = .systemBlue checkBox.onCheckColor = .white checkBox.onAnimationType = .fill checkBox.offAnimationType = .fill checkBox.animationDuration = 0.3 view.addSubview(checkBox) return checkBox } func didTap(_ checkBox: BEMCheckBox) { updateSubmitButton() } func updateSubmitButton() { let canSubmit = termsCheckBox.on && privacyCheckBox.on submitButton.isEnabled = canSubmit submitButton.backgroundColor = canSubmit ? .systemBlue : .systemGray } @objc func submitTapped() { print("Form submitted!") print("Newsletter opted in: \(newsletterCheckBox.on)") } } ``` -------------------------------- ### Import BEMCheckBox Header Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Include the header file in your view controller to access the BEMCheckBox class. ```objective-c #import "BEMCheckBox.h" ``` -------------------------------- ### Implement BEMCheckBoxDelegate Methods Source: https://context7.com/boris-em/bemcheckbox/llms.txt Conform to the `BEMCheckBoxDelegate` protocol in your `ViewController` to handle checkbox events. Implement `didTap` for immediate feedback and `animationDidStop` for actions after animations complete. Requires importing UIKit and BEMCheckBox. ```swift import UIKit import BEMCheckBox class ViewController: UIViewController, BEMCheckBoxDelegate { var checkBox: BEMCheckBox! override func viewDidLoad() { super.viewDidLoad() checkBox = BEMCheckBox(frame: CGRect(x: 100, y: 100, width: 50, height: 50)) checkBox.delegate = self view.addSubview(checkBox) } // Called immediately after tap, before animation completes func didTap(_ checkBox: BEMCheckBox) { print("Checkbox tapped! New state: \(checkBox.on)") // Update UI immediately based on new state if checkBox.on { print("User checked the box") } else { print("User unchecked the box") } } // Called after animation finishes func animationDidStop(for checkBox: BEMCheckBox) { print("Animation completed for checkbox") // Perform actions that should wait for animation if checkBox.on { submitForm() } } func submitForm() { print("Form submitted") } } ``` -------------------------------- ### Interface Builder Checkbox Initialization Source: https://context7.com/boris-em/bemcheckbox/llms.txt Configure BEMCheckBox in Interface Builder by setting its custom class to 'BEMCheckBox' in the Identity Inspector and connecting an outlet. ```swift // In your storyboard: // 1. Drag a UIView onto your view controller // 2. Set the custom class to "BEMCheckBox" in the Identity Inspector // 3. Connect the outlet to your view controller import UIKit import BEMCheckBox class ViewController: UIViewController { @IBOutlet weak var checkBox: BEMCheckBox! override func viewDidLoad() { super.viewDidLoad() // Configure checkbox after loading from storyboard checkBox.onAnimationType = .bounce checkBox.offAnimationType = .bounce } } ``` -------------------------------- ### Configure BEMCheckbox Line Width and Hide Box Source: https://context7.com/boris-em/bemcheckbox/llms.txt Modify the `lineWidth` property to change the thickness of the checkbox border. Set `hideBox` to `true` to display only the check mark without the surrounding box. ```swift import BEMCheckBox // Set line width (default is 2.0) myCheckBox.lineWidth = 3.0 // Hide the box, showing only the check mark myCheckBox.hideBox = true // Example: Create a minimal check-mark-only indicator let checkMarkOnly = BEMCheckBox(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) checkMarkOnly.hideBox = true checkMarkOnly.onCheckColor = UIColor.systemGreen checkMarkOnly.lineWidth = 4.0 checkMarkOnly.onAnimationType = .bounce ``` -------------------------------- ### Programmatic Checkbox Initialization Source: https://context7.com/boris-em/bemcheckbox/llms.txt Create and add a BEMCheckBox to your view programmatically by initializing it with a specific frame. You can optionally set its initial state. ```swift import UIKit import BEMCheckBox class ViewController: UIViewController { var myCheckBox: BEMCheckBox! override func viewDidLoad() { super.viewDidLoad() // Create checkbox with frame myCheckBox = BEMCheckBox(frame: CGRect(x: 100, y: 100, width: 50, height: 50)) view.addSubview(myCheckBox) // Optional: Set initial state myCheckBox.on = true } } ``` -------------------------------- ### Setting Checkbox State with `setOn(_:animated:)` Source: https://context7.com/boris-em/bemcheckbox/llms.txt Set the checkbox state with optional animation using the `setOn` method, similar to `UISwitch`. This method allows for controlled state changes with or without visual animation. ```swift import BEMCheckBox // Set to checked with animation myCheckBox.setOn(true, animated: true) // Set to unchecked with animation myCheckBox.setOn(false, animated: true) // Set to checked without animation myCheckBox.setOn(true, animated: false) // Example: Animate checkbox based on user action func toggleCheckbox() { let newState = !myCheckBox.on myCheckBox.setOn(newState, animated: true) } ``` -------------------------------- ### Respond to Checkbox Value Changes with Target-Action Source: https://context7.com/boris-em/bemcheckbox/llms.txt Utilize the standard UIControl target-action pattern to respond to value changes in a BEMCheckBox. This allows you to execute custom logic when the checkbox's state is toggled. ```swift import UIKit import BEMCheckBox class ViewController: UIViewController { var checkBox: BEMCheckBox! override func viewDidLoad() { super.viewDidLoad() checkBox = BEMCheckBox(frame: CGRect(x: 100, y: 100, width: 50, height: 50)) view.addSubview(checkBox) // Add target-action for value changes checkBox.addTarget(self, action: #selector(checkBoxValueChanged(_:)), for: .valueChanged) } @objc func checkBoxValueChanged(_ sender: BEMCheckBox) { print("Checkbox value changed to: \(sender.on)") // Update related UI or data updateAcceptanceStatus(accepted: sender.on) } func updateAcceptanceStatus(accepted: Bool) { // Handle the state change print("Terms accepted: \(accepted)") } } ``` -------------------------------- ### Manage Checkbox Groups Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Configure radio button behavior for a collection of checkboxes. ```objective-c 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 ``` ```objective-c BEMCheckBox *selection = self.group.selectedCheckBox; ``` ```objective-c self.group.selectedCheckBox = self.checkBox1; ``` -------------------------------- ### BEMCheckBox State Management Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Methods and properties for controlling the checkbox state. ```APIDOC ## Property: on ### Description A boolean property to retrieve or set the checkbox state without animation. ### Usage `self.myCheckBox.on = YES;` ## Method: setOn:animated: ### Description Sets the state of the checkbox to On or Off, with an optional animation. ### Parameters - **on** (BOOL) - Required - The target state. - **animated** (BOOL) - Required - Whether to animate the transition. ### Usage `[self.myCheckBox setOn:YES animated:YES];` ``` -------------------------------- ### Customize BEMCheckbox Colors Source: https://context7.com/boris-em/bemcheckbox/llms.txt Adjust colors for the box outline, fill, and check mark for both ON and OFF states using properties like `onTintColor`, `onFillColor`, `onCheckColor`, `tintColor`, and `offFillColor`. Requires importing UIKit. ```swift import BEMCheckBox import UIKit // Configure colors for ON state myCheckBox.onTintColor = UIColor.systemBlue // Box outline when ON myCheckBox.onFillColor = UIColor.systemBlue // Box fill when ON myCheckBox.onCheckColor = UIColor.white // Check mark color // Configure colors for OFF state myCheckBox.tintColor = UIColor.lightGray // Box outline when OFF myCheckBox.offFillColor = UIColor.clear // Box fill when OFF // Example: Create a green success checkbox let successCheckBox = BEMCheckBox(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) successCheckBox.onTintColor = UIColor.systemGreen successCheckBox.onFillColor = UIColor.systemGreen successCheckBox.onCheckColor = UIColor.white successCheckBox.tintColor = UIColor.systemGray4 successCheckBox.lineWidth = 3.0 // Example: Create a red checkbox with no fill let outlineCheckBox = BEMCheckBox(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) outlineCheckBox.onTintColor = UIColor.systemRed outlineCheckBox.onFillColor = UIColor.clear outlineCheckBox.onCheckColor = UIColor.systemRed outlineCheckBox.onAnimationType = .stroke ``` -------------------------------- ### Configure BEMCheckbox Box Type Source: https://context7.com/boris-em/bemcheckbox/llms.txt Set the `boxType` property to `.circle` for a circular checkbox (default) or `.square` for a square one. You can also customize the corner radius for square boxes. ```swift import BEMCheckBox // Circle box (default) myCheckBox.boxType = .circle // Square box myCheckBox.boxType = .square // Square box with custom corner radius myCheckBox.boxType = .square myCheckBox.cornerRadius = 6.0 // Example: Create a square checkbox with rounded corners let squareCheckBox = BEMCheckBox(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) squareCheckBox.boxType = .square squareCheckBox.cornerRadius = 4.0 squareCheckBox.lineWidth = 2.0 ``` -------------------------------- ### Configuring Animation Types Source: https://context7.com/boris-em/bemcheckbox/llms.txt BEMCheckBox supports six animation types: stroke, fill, bounce, flat, oneStroke, and fade. Configure these using `onAnimationType` and `offAnimationType`. The `animationDuration` property controls the speed. ```swift import BEMCheckBox // Available animation types: // .stroke - Draws the box and check mark (default) // .fill - Fills from center, use with colored onFillColor // .bounce - Bouncy check mark effect // .flat - Morphs checkmark from a horizontal line // .oneStroke - Draws box and check in one continuous line // .fade - Fades opacity in/out // Configure stroke animation (default) myCheckBox.onAnimationType = .stroke myCheckBox.offAnimationType = .stroke // Configure bounce animation for playful UI myCheckBox.onAnimationType = .bounce myCheckBox.offAnimationType = .bounce // Configure fill animation with solid fill color myCheckBox.onAnimationType = .fill myCheckBox.offAnimationType = .fill myCheckBox.onFillColor = UIColor.systemBlue // Configure flat animation myCheckBox.onAnimationType = .flat myCheckBox.offAnimationType = .flat myCheckBox.onFillColor = UIColor.systemGreen // Set animation duration (default is 0.5 seconds) myCheckBox.animationDuration = 0.3 ``` -------------------------------- ### Set Checkbox State Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Update the checkbox state using the 'on' property or the animated setter method. ```objective-c self.myCheckBox.on = YES; ``` ```objective-c [self.myCheckBox setOn:YES animated:YES]; ``` -------------------------------- ### BEMCheckBox Grouping Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Functionality for grouping checkboxes to act as radio buttons. ```APIDOC ## Class: BEMCheckBoxGroup ### Description Manages a collection of BEMCheckBox objects to enforce radio button behavior where only one can be selected at a time. ### Properties - **selectedCheckBox** (BEMCheckBox) - The currently selected checkbox in the group. - **mustHaveSelection** (BOOL) - If set to YES, the group requires at least one selection at all times. ### Usage ```objective-c self.group = [BEMCheckBoxGroup groupWithCheckBoxes:@[self.checkBox1, self.checkBox2]]; self.group.mustHaveSelection = YES; self.group.selectedCheckBox = self.checkBox1; ``` ``` -------------------------------- ### Dynamically Manage Checkbox Group Membership Source: https://context7.com/boris-em/bemcheckbox/llms.txt Add and remove checkboxes from a BEMCheckBoxGroup dynamically. Note that a checkbox can only belong to one group at a time; adding it to a new group automatically removes it from its previous group. ```swift import BEMCheckBox // Create an empty group let group = BEMCheckBoxGroup() // Add checkboxes to group let checkBox1 = BEMCheckBox(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) let checkBox2 = BEMCheckBox(frame: CGRect(x: 0, y: 50, width: 40, height: 40)) group.addCheckBoxToGroup(checkBox1) group.addCheckBoxToGroup(checkBox2) // Check if checkbox is in group let isInGroup = group.contains(checkBox1) // Returns: true // Remove checkbox from group group.removeCheckBoxFromGroup(checkBox1) // Checkbox can only belong to one group at a time // Adding to a new group automatically removes from previous group let newGroup = BEMCheckBoxGroup() newGroup.addCheckBoxToGroup(checkBox2) // Removes from 'group' automatically ``` -------------------------------- ### Reload Checkbox Source: https://github.com/boris-em/bemcheckbox/blob/master/README.md Redraw the checkbox while maintaining its current state. ```objective-c [self.myCheckBox reload] ``` -------------------------------- ### Create Radio Button Behavior with BEMCheckBoxGroup Source: https://context7.com/boris-em/bemcheckbox/llms.txt Use BEMCheckBoxGroup to enforce single selection among a set of checkboxes, mimicking radio button functionality. You can optionally set a pre-selected checkbox and enforce that at least one option must always be selected. ```swift import UIKit import BEMCheckBox class RadioViewController: UIViewController { var option1: BEMCheckBox! var option2: BEMCheckBox! var option3: BEMCheckBox! var group: BEMCheckBoxGroup! override func viewDidLoad() { super.viewDidLoad() // Create checkboxes option1 = BEMCheckBox(frame: CGRect(x: 50, y: 100, width: 40, height: 40)) option2 = BEMCheckBox(frame: CGRect(x: 50, y: 160, width: 40, height: 40)) option3 = BEMCheckBox(frame: CGRect(x: 50, y: 220, width: 40, height: 40)) view.addSubview(option1) view.addSubview(option2) view.addSubview(option3) // Create group with checkboxes group = BEMCheckBoxGroup(checkBoxes: [option1, option2, option3]) // Optionally set pre-selected checkbox group.selectedCheckBox = option1 // Require that one option is always selected group.mustHaveSelection = true } // Get the currently selected checkbox func getSelection() -> BEMCheckBox? { return group.selectedCheckBox } // Programmatically change selection func selectOption2() { group.selectedCheckBox = option2 } // Clear selection (only works if mustHaveSelection is false) func clearSelection() { group.mustHaveSelection = false group.selectedCheckBox = nil } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.