actionsheetpicker-3.0

Overview

ActionsheetPicker is a customizable library for presenting a multi-level menu with multiple options to users. It provides an interactive and user-friendly way to select options in your application. The library is compatible with iOS and offers various customization options.


Usage

Installation

To install and use ActionsheetPicker in your iOS project, follow these steps:

CocoaPods

1. Open your terminal and navigate to the project directory.

2. If you haven’t already, initialize CocoaPods by running the command: pod init

3. Open the Podfile created in your project directory.

4. Add the following line to your Podfile:

pod 'ActionSheetPicker-3.0'

5. Run the command: pod install

6. From now on, use the .xcworkspace file to open your project.

Manual Installation

1. Download the latest ActionsheetPicker framework from the official GitHub repository.

2. Unzip the downloaded file and locate the ActionsheetPicker.framework file.

3. Drag and drop the ActionsheetPicker.framework file into your Xcode project.

4. Make sure the framework is added to the “Embedded Binaries” section of your project settings.


Customization

ActionsheetPicker provides various customization options to personalize the appearance and behavior of the multi-level menu. Below are the available customization options:

Appearance Customization

ActionsheetPicker allows you to customize the appearance of the menu using the following properties:

titleTextAttributes

Sets the text attributes for the menu title.

pickerTextAttributes

Sets the text attributes for the picker options.

Behavior Customization

ActionsheetPicker provides various behavior customization options:

onActionSheetDone

Executes a closure when the user selects the “Done” button on the menu.

onActionSheetCancel

Executes a closure when the user cancels the menu.


Example Usage

Below is an example of using ActionsheetPicker to create a multi-level menu:

Import

First, import the ActionsheetPicker library in your ViewController:

import ActionSheetPicker_3_0

Usage in Code

Use the following code sample to display the ActionsheetPicker menu:

Swift

// Initialize an ActionsheetPicker instance
let picker = ActionSheetStringPicker(title: "Select an option", rows: ["Option 1", "Option 2", "Option 3"], initialSelection: 0, doneBlock: { picker, selectedIndex, selectedValue in
    // Handle user selection
}, cancel: { picker in
    // Handle cancellation
}, origin: button) // Replace `button` with the UI element invoking the menu

// Customize the appearance and behavior of picker (optional)
picker.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
picker.showCancel = true

// Display the picker
picker.show()

Objective-C

// Initialize an ActionsheetPicker instance
ActionSheetStringPicker *picker = [[ActionSheetStringPicker alloc] initWithTitle:@"Select an option"
                                                                            rows:@[@"Option 1", @"Option 2", @"Option 3"]
                                                                initialSelection:0
                                                                       doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
                                                                           // Handle user selection
                                                                       }
                                                                     cancelBlock:^(ActionSheetStringPicker *picker) {
                                                                         // Handle cancellation
                                                                     }
                                                                          origin:button]; // Replace `button` with the UI element invoking the menu

// Customize the appearance and behavior of picker (optional)
picker.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor redColor]};
picker.showCancel = YES;

// Display the picker
[picker show];


Further Information

For more detailed documentation on ActionsheetPicker and its features, refer to the official GitHub repository and the official documentation provided by the library’s author.