JDrawView is a lightweight and flexible drawing view for iOS applications. It provides an easy-to-use interface for implementing drawing functionality in your iOS apps.
- Simple and intuitive drawing interface
- Customizable line color and width
- Support for adding horizontal and vertical dash lines
- Ability to clear the drawing
- Convert drawing to UIImage
- Copy drawing to clipboard
- iOS 13.0+
- Swift 5.0+
JDrawView is available through Swift Package Manager.
Swift Package Manager
dependencies: [
.package(url: "https://github.com/wlxo0401/JDrawView.git", .upToNextMajor(from: "1.0.4"))
]
- Import the module in your Swift file:
import JDrawView
- Create and add a JDrawView to your view hierarchy:
let drawView = JDrawView(frame: view.bounds)
view.addSubview(drawView)
- Customize the drawing:
// Set line color
drawView.setDrawColor(color: .red)
// Set line width
drawView.setDrawWidth(width: 5.0)
// Add dash lines
drawView.setHorizonDashLine(set: true)
drawView.setVerticalDashLine(set: true)
- Get the drawing as an image:
let image = drawView.asImage()
- Clear the drawing:
drawView.clearDrawing()
import UIKit
import JDrawView
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let drawView = JDrawView()
view.addSubview(drawView)
drawView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
drawView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 20),
drawView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20),
drawView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20),
drawView.heightAnchor.constraint(equalTo: drawView.widthAnchor),
])
drawView.setDrawColor(color: .blue)
drawView.setDrawWidth(width: 3.0)
}
}
Contributions are welcome! Please feel free to submit a Pull Request.