Description
AceDrawingView is a versatile and easy-to-use UIView subclass that provides drawing functionalities in your iOS applications. With AceDrawingView, users can draw, erase, and modify lines or paths using simple touch gestures.
Features
- Supports freehand drawing, erasing, and modifying lines or paths.
- Seamless integration with UIKit.
- Ability to customize various aspects including stroke color, stroke width, and background color.
- Undo and redo functionality for easy correction of mistakes.
- Supports exporting drawings as images in various formats.
Requirements
- iOS 9.0+
- Xcode 12.0+
- Swift 5+
Installation
To install AceDrawingView in your project, you have multiple options:
1. CocoaPods
Add the following line to your Podfile:
pod 'AceDrawingView'
Then, run the command:
pod install
2. Manual Installation
- Download the latest release from the AceDrawingView GitHub page.
- Open your project in Xcode.
- Drag and drop the AceDrawingView framework files into your project.
- Make sure to select “Copy items if needed” and add the framework to your project’s target.
Usage
Follow the steps below to integrate AceDrawingView into your application:
1. Import AceDrawingView
In the class where you intend to use AceDrawingView, import the framework:
import AceDrawingView
2. Create an AceDrawingView Instance
Create an instance of AceDrawingView either programmatically or in Interface Builder.
3. Customize Appearance
Customize various aspects of AceDrawingView’s appearance. Use the following properties to set the desired values:
strokeColor
: The color of the drawing stroke.strokeWidth
: The width of the drawing stroke.backgroundColor
: The background color of the drawing view.
4. Handle Drawing Actions
Handle drawing actions using the provided delegation methods:
aceDrawingViewDidBeginDrawing(_ drawingView: AceDrawingView)
: Called when the user starts drawing.aceDrawingViewDidEndDrawing(_ drawingView: AceDrawingView)
: Called when the user finishes drawing.aceDrawingViewDidBeginErasing(_ drawingView: AceDrawingView)
: Called when the user starts erasing.aceDrawingViewDidEndErasing(_ drawingView: AceDrawingView)
: Called when the user finishes erasing.
5. Export Drawings
To export drawings as images, use the following method:
func exportDrawing() -> UIImage?
This method returns the drawing as a UIImage object, which can then be saved or shared as needed.
6. Undo and Redo
AceDrawingView supports undo and redo functionality to easily correct mistakes. Use the following methods:
func undo()
: Undo the last drawing operation.func redo()
: Redo the last undone drawing operation.func canUndo() -> Bool
: Check if there is an operation available for undo.func canRedo() -> Bool
: Check if there is an operation available for redo.
Examples
Here are some examples demonstrating how to use AceDrawingView:
Example 1: Basic Usage
import UIKit
import AceDrawingView
class DrawingViewController: UIViewController, AceDrawingViewDelegate {
var drawingView: AceDrawingView!
override func viewDidLoad() {
super.viewDidLoad()
// Instantiate AceDrawingView
drawingView = AceDrawingView(frame: view.bounds)
view.addSubview(drawingView)
// Customize appearance
drawingView.strokeColor = .blue
drawingView.strokeWidth = 5.0
drawingView.backgroundColor = .white
// Set delegate
drawingView.delegate = self
}
// Delegate methods for drawing actions
func aceDrawingViewDidBeginDrawing(_ drawingView: AceDrawingView) {
// Handle drawing begin action
}
func aceDrawingViewDidEndDrawing(_ drawingView: AceDrawingView) {
// Handle drawing end action
}
func aceDrawingViewDidBeginErasing(_ drawingView: AceDrawingView) {
// Handle erasing begin action
}
func aceDrawingViewDidEndErasing(_ drawingView: AceDrawingView) {
// Handle erasing end action
}
// Other methods and actions...
}
Contributing
If you want to contribute to AceDrawingView, make sure to follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
License
AceDrawingView is released under the MIT license. See the LICENSE file for more details.
Support
If you have any questions, issues, or feature requests, please contact us at [support email]. We are always here to help you!