Name classes consistently

* Settings are called *SettingsTableViewController
* Key importers are called *ImportTableViewController
* Classes in UserInterface folder are split into Controllers or Views
This commit is contained in:
Danny Moesch 2020-02-12 23:28:04 +01:00 committed by Mingshen Sun
parent 20f18d0c8b
commit 3cdf77347a
14 changed files with 60 additions and 68 deletions

View file

@ -0,0 +1,46 @@
/*
UICodeHighlightingLabel.swift
pass
Created by Danny Moesch on 20.01.19.
Copyright © 2019 Bob Sun. All rights reserved.
*/
import UIKit
import passKit
class UICodeHighlightingLabel: UILocalizedLabel {
private static let CODE_ATTRIBUTES: [NSAttributedString.Key: Any] = [.font: UIFont(name: "Menlo-Regular", size: 12)!]
private static let ATTRIBUTED_NEWLINE = NSAttributedString(string: "\n")
override func awakeFromNib() {
super.awakeFromNib()
guard let text = text else {
return
}
attributedText = formatCode(in: text)
}
/// Format code sections in a multiline string block.
///
/// A line in the string is interpreted as a code section if it starts with two spaces.
///
/// - Parameter text: Multiline string block
/// - Returns: Same multiline string block with code sections formatted
private func formatCode(in text: String) -> NSMutableAttributedString {
let formattedText = text.splitByNewline()
.map { line -> NSAttributedString in
if line.starts(with: " ") {
return NSAttributedString(string: line, attributes: UICodeHighlightingLabel.CODE_ATTRIBUTES)
}
return NSAttributedString(string: line)
}.reduce(into: NSMutableAttributedString(string: "")) {
$0.append($1)
$0.append(UICodeHighlightingLabel.ATTRIBUTED_NEWLINE)
}
formattedText.deleteCharacters(in: NSRange(location: formattedText.length - 1, length: 1))
return formattedText
}
}

View file

@ -0,0 +1,18 @@
/*
UILocalizedLabel.swift
pass
Created by Danny Moesch on 20.01.19.
Copyright © 2019 Bob Sun. All rights reserved.
*/
import UIKit
import passKit
class UILocalizedLabel: UILabel {
override func awakeFromNib() {
super.awakeFromNib()
text = text?.localize()
}
}