updated label with overrides for textColor and font
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
23f3f8b6bf
commit
89a4c5d397
@ -131,32 +131,43 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
|||||||
|
|
||||||
/// Line break mode for the label, default is set to word wrapping.
|
/// Line break mode for the label, default is set to word wrapping.
|
||||||
open override var lineBreakMode: NSLineBreakMode { didSet { setNeedsUpdate() }}
|
open override var lineBreakMode: NSLineBreakMode { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
private var _text: String?
|
|
||||||
|
|
||||||
/// Text that will be used in the label.
|
/// Text that will be used in the label.
|
||||||
override public var text: String! {
|
override open var text: String! {
|
||||||
get { super.text }
|
get { super.text }
|
||||||
set {
|
set {
|
||||||
// When text is set, we may need to re-style it as attributedText
|
|
||||||
// with the correct paragraph style to achieve the desired line height.
|
|
||||||
textSetMode = .text
|
textSetMode = .text
|
||||||
attributes?.removeAll()
|
|
||||||
styleText(newValue)
|
styleText(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///AttributedText that will be used in the label.
|
///AttributedText that will be used in the label.
|
||||||
override public var attributedText: NSAttributedString? {
|
override open var attributedText: NSAttributedString? {
|
||||||
get { super.attributedText }
|
get { super.attributedText }
|
||||||
set {
|
set {
|
||||||
// When text is set, we may need to re-style it as attributedText
|
|
||||||
// with the correct paragraph style to achieve the desired line height.
|
|
||||||
textSetMode = .attributedText
|
textSetMode = .attributedText
|
||||||
styleAttributedText(newValue)
|
styleAttributedText(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override open var font: UIFont! {
|
||||||
|
didSet {
|
||||||
|
if let font, initialSetupPerformed {
|
||||||
|
textStyle = TextStyle.convert(font: font)
|
||||||
|
}
|
||||||
|
setNeedsUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override open var textColor: UIColor! {
|
||||||
|
didSet {
|
||||||
|
if let textColor, initialSetupPerformed {
|
||||||
|
textColorConfiguration = SurfaceColorConfiguration(textColor, textColor).eraseToAnyColorable()
|
||||||
|
}
|
||||||
|
setNeedsUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether the View is enabled or not.
|
/// Whether the View is enabled or not.
|
||||||
open override var isEnabled: Bool { didSet { setNeedsUpdate() } }
|
open override var isEnabled: Bool { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
@ -175,13 +186,13 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open func initialSetup() {
|
open func initialSetup() {
|
||||||
if !initialSetupPerformed {
|
if !initialSetupPerformed {
|
||||||
|
initialSetupPerformed = true
|
||||||
//register for ContentSizeChanges
|
//register for ContentSizeChanges
|
||||||
NotificationCenter
|
NotificationCenter
|
||||||
.Publisher(center: .default, name: UIContentSizeCategory.didChangeNotification)
|
.Publisher(center: .default, name: UIContentSizeCategory.didChangeNotification)
|
||||||
.sink { [weak self] notification in
|
.sink { [weak self] notification in
|
||||||
self?.setNeedsUpdate()
|
self?.setNeedsUpdate()
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
numberOfLines = 0
|
numberOfLines = 0
|
||||||
lineBreakMode = .byWordWrapping
|
lineBreakMode = .byWordWrapping
|
||||||
@ -307,7 +318,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var mutableText = NSMutableAttributedString(attributedString: newValue)
|
let mutableText = NSMutableAttributedString(attributedString: newValue)
|
||||||
|
|
||||||
applyAttributes(mutableText)
|
applyAttributes(mutableText)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user