Latest 0.4.3
Homepage https://github.com/blackbeltlabs/TextAnnotation
License MIT
Platforms osx 10.13
Authors

CI Status
Version
License
Platform

A textbox component that behaves like typical drawing or annotation apps require – think Sketch, Skitch, CloudApp etc.

The module is designed to be used alongside other drawing modules which for example support pen, rectangle or arrow annotations.

This module is a work in progress – to contribute review the spec:

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

TextAnnotation is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'TextAnnotation'

Usage

Text annotation support can be added by adopting the TextAnnotationCanvas protocol.
The protocol adds default handling of click and drag events but needs to be notified by those.
The TextAnnotationDelegate protocol can be used to handle editing and move operations.
Newly created TextAnnotation instances get by default the controller assigned as delegate.

Example

class ViewController: NSViewController, TextAnnotationCanvas {
  override func viewDidLoad() {
    super.viewDidLoad()

    // Programmatically creating a text annotation
    let location = CGPoint(x: 100, y: 150)

    // Method supplied by the TextAnnotationCanvas protocol extension
    let textAnnotation = createTextAnnotation(text: "Some text", location: location)
    textAnnotation.addTo(canvas: self)
  }

  override func mouseDown(with event: NSEvent) {
    // TextAnnotationCanvas needs to handle mouse down events
    let didHandle = textAnnotationCanvasMouseDown(event: event)
  }
}

extension ViewController: TextAnnotationDelegate {
  func textAnnotationDidEdit(textAnnotation: TextAnnotation) {
    print(textAnnotation.text)
  }

  func textAnnotationDidMove(textAnnotation: TextAnnotation) {
    print(textAnnotation.frame)
  }
}

Interface Definition

TextAnnotation

public protocol TextAnnotation {
  var text: String { get set }
  var frame: CGRect { get set }
  var isSelected: Bool { get set }
  var isEditing: Bool { get set }
}

TextAnnotationCanvas

public protocol TextAnnotationCanvas {
  var view: NSView { get }

  func addTextAnnotation(_ textAnnotation: TextAnnotation)
  func textAnnotationCanvasMouseDown(event: NSEvent)
}

TextAnnotationDelegate

public protocol TextAnnotationDelegate {
  func textAnnotationDidEdit(_ textAnnotation: TextAnnotation)
  func textAnnotationDidMove(_ textAnnotation: TextAnnotation)
}

Author

Mirko Kiefer, [email protected]

License

TextAnnotation is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "TextAnnotation",
    "version": "0.4.3",
    "summary": "Swift text annotation component for macOS.",
    "description": "Text component that behaves like typical drawing or annotation apps require.",
    "homepage": "https://github.com/blackbeltlabs/TextAnnotation",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Mirko Kiefer": "[email protected]"
    },
    "source": {
        "git": "https://github.com/blackbeltlabs/TextAnnotation.git",
        "tag": "0.4.3"
    },
    "platforms": {
        "osx": "10.13"
    },
    "swift_versions": "4.2",
    "source_files": "TextAnnotation/Classes/**/*",
    "resources": "TextAnnotation/Assets/**/*",
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This