mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-26 05:00:48 +00:00

git-subtree-dir: submodules/Display git-subtree-mainline: 9bc996374ffdad37aef175427db72731c9551dcf git-subtree-split: 7bd11013ea936e3d49d937550d599f5816d32560
59 lines
1.6 KiB
Swift
59 lines
1.6 KiB
Swift
import UIKit
|
|
import AsyncDisplayKit
|
|
|
|
public class NavigationTitleNode: ASDisplayNode {
|
|
private let label: ASTextNode
|
|
|
|
private var _text: NSString = ""
|
|
public var text: NSString {
|
|
get {
|
|
return self._text
|
|
}
|
|
set(value) {
|
|
self._text = value
|
|
self.setText(value)
|
|
}
|
|
}
|
|
|
|
public var color: UIColor = UIColor.black {
|
|
didSet {
|
|
self.setText(self._text)
|
|
}
|
|
}
|
|
|
|
public init(text: NSString) {
|
|
self.label = ASTextNode()
|
|
self.label.maximumNumberOfLines = 1
|
|
self.label.truncationMode = .byTruncatingTail
|
|
self.label.displaysAsynchronously = false
|
|
|
|
super.init()
|
|
|
|
self.addSubnode(self.label)
|
|
|
|
self.setText(text)
|
|
}
|
|
|
|
public required init(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
private func setText(_ text: NSString) {
|
|
var titleAttributes = [NSAttributedStringKey : AnyObject]()
|
|
titleAttributes[NSAttributedStringKey.font] = UIFont.boldSystemFont(ofSize: 17.0)
|
|
titleAttributes[NSAttributedStringKey.foregroundColor] = self.color
|
|
let titleString = NSAttributedString(string: text as String, attributes: titleAttributes)
|
|
self.label.attributedText = titleString
|
|
self.invalidateCalculatedLayout()
|
|
}
|
|
|
|
public override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize {
|
|
self.label.measure(constrainedSize)
|
|
return self.label.calculatedSize
|
|
}
|
|
|
|
public override func layout() {
|
|
self.label.frame = self.bounds
|
|
}
|
|
}
|