### LcActionSheet – Interactive Action Sheet for iOS
LcActionSheet is a powerful and customizable action sheet library for iOS. It provides an interactive way to present a set of options to the user, allowing them to choose from available actions in a visually appealing manner.
This documentation aims to guide you through every aspect of using LcActionSheet, from installation to customization and usage examples.
### Introduction
The LcActionSheet library simplifies the process of creating and displaying action sheets in iOS applications. It offers a flexible and user-friendly interface, allowing developers to present options to users with ease.
### Quick Start
To quickly get started with LcActionSheet, follow the steps below:
1. Install the LcActionSheet library using CocoaPods:
“`bash
pod ‘LcActionSheet’
“`
2. Import the LcActionSheet module in your Swift file:
“`swift
import LcActionSheet
“`
3. Create an instance of LcActionSheet and configure it with your desired options:
“`swift
let actionSheet = LcActionSheet(title: “Choose an option”)
actionSheet.addAction(LcAction(title: “Option 1”, style: .default, handler: {
// Handle Option 1 selection
}))
actionSheet.addAction(LcAction(title: “Option 2”, style: .default, handler: {
// Handle Option 2 selection
}))
// Add more actions if needed
“`
4. Display the action sheet to the user:
“`swift
actionSheet.present(in: self)
“`
Now, when the action sheet is presented, users can select the desired option, and the respective handler block will be called.
### Installation
LcActionSheet can be easily installed via CocoaPods. Follow the steps below to integrate it into your project:
1. Open your terminal and navigate to the project directory.
2. Initialize CocoaPods by running the following command:
“`bash
pod init
“`
3. Open the generated Podfile and add the following line:
“`ruby
pod ‘LcActionSheet’
“`
4. Save the Podfile, and run the following command to install LcActionSheet:
“`bash
pod install
“`
5. Close your Xcode project and open the newly created `.xcworkspace` file.
Now you are ready to import and use LcActionSheet in your project.
### Usage
To use LcActionSheet, you need to follow these steps:
1. Import the LcActionSheet module at the top of your Swift file:
“`swift
import LcActionSheet
“`
2. Create an instance of LcActionSheet with a title:
“`swift
let actionSheet = LcActionSheet(title: “Choose an option”)
“`
3. Add actions to the action sheet by creating instances of LcAction and adding them using the `addAction` method:
“`swift
actionSheet.addAction(LcAction(title: “Option 1”, style: .default, handler: {
// Handle Option 1 selection
}))
“`
4. Optionally, add more actions if needed.
5. Present the action sheet to the user:
“`swift
actionSheet.present(in: self)
“`
### Example: Simple Action Sheet
The following code demonstrates a simple implementation of LcActionSheet:
“`swift
import LcActionSheet
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let actionSheet = LcActionSheet(title: “Choose an option”)
actionSheet.addAction(LcAction(title: “Option 1”, style: .default, handler: {
// Handle Option 1 selection
}))
actionSheet.addAction(LcAction(title: “Option 2”, style: .default, handler: {
// Handle Option 2 selection
}))
actionSheet.present(in: self)
}
}
“`
### Available Methods
LcActionSheet provides the following methods to interact with and customize action sheets:
– `init(title: String?)`: Initializes an instance of LcActionSheet with an optional title.
– `addAction(_ action: LcAction)`: Adds an action to the action sheet.
– `removeAllActions()`: Removes all actions from the action sheet.
– `setCancelButton(_ action: LcAction?)`: Sets an action as the cancel button. If no cancel button is set, the action sheet will not display one.
– `setTitleColor(_ color: UIColor)`: Sets the title color of the action sheet.
– `setCancelButtonColor(_ color: UIColor)`: Sets the cancel button color.
– `setCancelButtonTitleColor(_ color: UIColor)`: Sets the cancel button title color.
– `setDestructiveButtonColor(_ color: UIColor)`: Sets the destructive button color.
– `setDestructiveButtonTitleColor(_ color: UIColor)`: Sets the destructive button title color.
– `setButtonColor(_ color: UIColor)`: Sets the default button color.
– `setButtonTitleColor(_ color: UIColor)`: Sets the default button title color.
– `present(in viewController: UIViewController)`: Presents the action sheet in the specified view controller.
### Example: Custom Action Sheet
You can customize the appearance of LcActionSheet by using the available methods. Here’s an example of creating a custom action sheet:
“`swift
let actionSheet = LcActionSheet(title: “Choose an option”)
// Customize colors
actionSheet.setTitleColor(.blue)
actionSheet.setButtonColor(.white)
actionSheet.setButtonTitleColor(.blue)
// Add custom actions
let customAction = LcAction(title: “Custom Action”, style: .default, handler: {
// Handle Custom Action selection
})
actionSheet.addAction(customAction)
// Set cancel button
let cancelAction = LcAction(title: “Cancel”, style: .cancel) {
// Handle cancel
}
actionSheet.setCancelButton(cancelAction)
// Finally, present the action sheet
actionSheet.present(in: self)
“`
### Available Properties
LcActionSheet provides the following properties that can be used to customize its appearance:
– `titleColor: UIColor`: The color of the action sheet’s title.
– `cancelButtonColor: UIColor`: The color of the cancel button.
– `cancelButtonTitleColor: UIColor`: The color of the cancel button’s title.
– `destructiveButtonColor: UIColor`: The color of the destructive button.
– `destructiveButtonTitleColor: UIColor`: The color of the destructive button’s title.
– `buttonColor: UIColor`: The color of the default buttons.
– `buttonTitleColor: UIColor`: The color of the default buttons’ titles.
### Styling
You can customize the appearance of LcActionSheet by using the available methods and properties. Here’s an example of styling the action sheet:
“`swift
let actionSheet = LcActionSheet(title: “Choose an option”)
// Customize colors
actionSheet.setTitleColor(.blue)
actionSheet.setButtonColor(.white)
actionSheet.setButtonTitleColor(.blue)
// Add custom actions
let customAction = LcAction(title: “Custom Action”, style: .default, handler: {
// Handle Custom Action selection
})
actionSheet.addAction(customAction)
// Set cancel button
let cancelAction = LcAction(title: “Cancel”, style: .cancel) {
// Handle cancel
}
actionSheet.setCancelButton(cancelAction)
// Finally, present the action sheet
actionSheet.present(in: self)
“`
### Example: Styling
Here’s an example of styling an LcActionSheet with different colors:
“`swift
import LcActionSheet
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let actionSheet = LcActionSheet(title: “Choose an option”)
// Set custom colors
actionSheet.setTitleColor(.systemPurple)
actionSheet.setCancelButtonColor(.systemRed)
actionSheet.setCancelButtonTitleColor(.white)
actionSheet.setDestructiveButtonColor(.systemOrange)
actionSheet.setDestructiveButtonTitleColor(.black)
actionSheet.setButtonColor(.systemBlue)
actionSheet.setButtonTitleColor(.white)
// Add actions
actionSheet.addAction(LcAction(title: “Option 1”, style: .default, handler: {
// Handle Option 1 selection
}))
actionSheet.addAction(LcAction(title: “Option 2”, style: .default, handler: {
// Handle Option 2 selection
}))
actionSheet.addAction(LcAction(title: “Cancel”, style: .cancel, handler: nil))
actionSheet.present(in: self)
}
}
“`
### License
LcActionSheet is available under the MIT license. See the [LICENSE](https://github.com/
That’s it! You now have a solid understanding of LcActionSheet and how to use it in your iOS applications. Feel free to explore additional options and customization possibilities offered by LcActionSheet to enhance the user experience.