From b581b514310e70747a5fa8c25a2caf4af424b282 Mon Sep 17 00:00:00 2001 From: Christian Tietze Date: Sat, 18 Nov 2023 14:18:02 +0100 Subject: [PATCH] expand iOS sample app demonstration --- Projects/NeonExample-iOS/ViewController.swift | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Projects/NeonExample-iOS/ViewController.swift b/Projects/NeonExample-iOS/ViewController.swift index 33388d8..01ad91a 100644 --- a/Projects/NeonExample-iOS/ViewController.swift +++ b/Projects/NeonExample-iOS/ViewController.swift @@ -15,16 +15,22 @@ final class ViewController: UIViewController { .appendingPathComponent("queries/highlights.scm") let query = try! language.query(contentsOf: url!) - let attrProvider: TextViewSystemInterface.AttributeProvider = { token in - guard token.name.hasPrefix("keyword") else { return [:] } - - return [.foregroundColor: UIColor.red] + let regularFont = UIFont.monospacedSystemFont(ofSize: 16, weight: .regular) + let boldFont = UIFont.monospacedSystemFont(ofSize: 16, weight: .bold) + let italicFont = regularFont.fontDescriptor.withSymbolicTraits(.traitItalic).map { UIFont(descriptor: $0, size: 16) } ?? regularFont + + let provider: TextViewSystemInterface.AttributeProvider = { token in + return switch token.name { + case let keyword where keyword.hasPrefix("keyword"): [.foregroundColor: UIColor.red, .font: boldFont] + case "comment": [.foregroundColor: UIColor.green, .font: italicFont] + default: [.foregroundColor: UIColor.darkText, .font: regularFont] + } } return try! TextViewHighlighter(textView: textView, language: language, highlightQuery: query, - attributeProvider: attrProvider) + attributeProvider: provider) }() override func viewDidLoad() { @@ -33,7 +39,11 @@ final class ViewController: UIViewController { _ = highlighter.textView _ = textView.layoutManager - textView.text = "var something = String()" + textView.text = """ + // Example Code! + let value = "hello world" + print(value) + """ self.view.addSubview(textView) textView.translatesAutoresizingMaskIntoConstraints = false