Repository navigation
Expand file tree
/
Copy pathInputOutputModuleView.swift
More file actions
64 lines (50 loc) · 1.83 KB
/
Copy pathInputOutputModuleView.swift
File metadata and controls
64 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// InputOutputModuleView.swift
// RichTextView-Example
//
// Created by Ahmed Elkady on 2018-11-23.
// Copyright © 2018 Top Hat. All rights reserved.
//
import RichTextView
import UIKit
class InputOutputModuleView: UIView, RichTextViewDelegate {
// MARK: - Constants
let attributes = ["456": [NSAttributedString.Key.backgroundColor: UIColor.lightGray]]
// MARK: - IBOutlets
@IBOutlet var contentView: UIView!
@IBOutlet weak var inputLabel: UILabel!
@IBOutlet weak var outputRichTextView: RichTextView!
// MARK: - Init
init(text: String, frame: CGRect = .zero) {
super.init(frame: frame)
self.setupWithNib()
self.updateText(text)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupWithNib()
}
// MARK: - Private Helpers
private func setupWithNib() {
Bundle.main.loadNibNamed("InputOutputModuleView", owner: self, options: nil)
self.addSubview(self.contentView)
self.contentView.frame = self.bounds
self.contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
private func updateText(_ text: String) {
self.inputLabel.text = text
self.outputRichTextView.textViewDelegate = self
self.outputRichTextView.update(
input: text,
customAdditionalAttributes: self.attributes
)
}
// MARK: - RichTextViewDelegate
func didTapCustomLink(withID linkID: String) {
DispatchQueue.main.async {
let alertController = UIAlertController(title: "Custom Link", message: linkID, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Okay", style: .default))
UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true)
}
}
}