Files
MarkdownTextView/Example/ViewController.swift
Indragie Karunaratne cf4ca55feb Convert to Swift 2
2016-01-10 17:24:27 -07:00

39 lines
1.5 KiB
Swift

//
// ViewController.swift
// MarkdownTextView
//
// Created by Indragie on 4/27/15.
// Copyright (c) 2015 Indragie Karunaratne. All rights reserved.
//
import UIKit
import MarkdownTextView
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let attributes = MarkdownAttributes()
let textStorage = MarkdownTextStorage(attributes: attributes)
do {
textStorage.addHighlighter(try LinkHighlighter())
} catch let error {
fatalError("Error initializing LinkHighlighter: \(error)")
}
textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
if let codeBlockAttributes = attributes.codeBlockAttributes {
textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
}
let textView = MarkdownTextView(frame: CGRectZero, textStorage: textStorage)
textView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(textView)
let views = ["textView": textView]
var constraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-20-[textView]-20-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
constraints += NSLayoutConstraint.constraintsWithVisualFormat("H:|-20-[textView]-20-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(constraints)
}
}