mastodon-ios/Mastodon/Extension/ActiveLabel.swift

54 lines
1.3 KiB
Swift
Raw Normal View History

2021-01-29 09:47:32 +01:00
//
// ActiveLabel.swift
// Mastodon
//
// Created by sxiaojian on 2021/1/29.
//
import UIKit
import Foundation
import ActiveLabel
import os.log
2021-01-29 09:47:32 +01:00
extension ActiveLabel {
enum Style {
case `default`
case timelineHeaderView
}
convenience init(style: Style) {
self.init()
switch style {
case .default:
font = .preferredFont(forTextStyle: .body)
2021-02-23 08:16:55 +01:00
textColor = Asset.Colors.Label.primary.color
2021-01-29 09:47:32 +01:00
case .timelineHeaderView:
font = .preferredFont(forTextStyle: .footnote)
textColor = .secondaryLabel
}
numberOfLines = 0
2021-02-23 08:16:55 +01:00
lineSpacing = 5
mentionColor = Asset.Colors.Label.highlight.color
hashtagColor = Asset.Colors.Label.highlight.color
URLColor = Asset.Colors.Label.highlight.color
2021-01-29 09:47:32 +01:00
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
}
extension ActiveLabel {
func config(content: String) {
activeEntities.removeAll()
if let parseResult = try? TootContent.parse(toot: content) {
text = parseResult.trimmed
activeEntities = parseResult.activeEntities
} else {
text = ""
}
2021-01-29 09:47:32 +01:00
}
}