ACPolygonView
示例
要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install
。
需求
- iOS 8.0
安装
ACPolygonView 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod 'ACPolygonView'
用法示例
import UIKit
import ACPolygonView
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView! // display an image
@IBOutlet weak var polygonView: PolygonView! // has the same frame as imageView
override func viewDidLoad() {
super.viewDidLoad()
let firstPolyPoints = [
CGPoint(x: 25, y: 95),
CGPoint(x: 180, y: 15),
CGPoint(x: 340, y: 100),
CGPoint(x: 170, y: 200)
]
// If magnifiedView is set, a magnifier view will be displayed in
// the top-left corner of polygonView, displaying the content of imageView
self.polygonView.magnifiedView = self.imageView
self.addPolygon(points: firstPolyPoints)
}
/// Adds a polygon inside polygonView
/// - Parameter points: The initial points of the polygon.
func addPolygon(points: [CGPoint]) {
// Drawing configuration for the polygon layer
let polyConfig = PolygonLayerConfiguration()
polyConfig.fillColor = UIColor(red: 0.5, green: 1, blue: 0.0, alpha: 0.5)
polyConfig.selectedFillColor = UIColor.yellow.withAlphaComponent(0.5)
polyConfig.lineColor = .clear
polyConfig.selectedLineColor = .clear
// Drawing configuration for all the control point layers (polygon corners)
let pointsConfig = ControlPointLayerConfiguration()
pointsConfig.fillColor = .clear
pointsConfig.selectedFillColor = .clear
pointsConfig.lineColor = .white
pointsConfig.selectedLineColor = .red
// Add the polygon layer as a sublayer of polygonView
self.polygonView.addPolygon(initialPoints: points, polygonConfiguration: polyConfig, pointsConfiguration: pointsConfig)
}
}
作者
Andrei Ciobanu, [email protected]
许可
ACPolygonView 在 MIT 许可证下可用。更多信息请参阅 LICENSE 文件。