Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created November 2, 2019 05:26
Show Gist options
  • Save laevandus/fe382c146fab5f7e66aa1cba028cc51e to your computer and use it in GitHub Desktop.
Save laevandus/fe382c146fab5f7e66aa1cba028cc51e to your computer and use it in GitHub Desktop.
let textView = TokenTextView(frame: .zero)
textView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(textView)
NSLayoutConstraint.activate([
textView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16),
textView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16),
textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16),
textView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16)
])
let string = "The quick brown fox jumps over the lazy dog"
let attributedString = NSMutableAttributedString(string: string)
let value = "value"
attributedString.addAttribute(.token, value: value, range: NSRange(location: 4, length: 5))
textView.attributedText = attributedString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment