removed default text and fix issue for empty strings

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-11-02 08:48:23 -05:00
parent caad16f4e9
commit 94bdb22fbd

View File

@ -158,26 +158,31 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
//clear the arrays holding actions //clear the arrays holding actions
accessibilityCustomActions = [] accessibilityCustomActions = []
if let text, !text.isEmpty {
//create the primary string
let mutableText = NSMutableAttributedString.mutableText(for: text,
textStyle: textStyle,
useScaledFont: useScaledFont,
textColor: textColor,
alignment: titleLabel?.textAlignment ?? .center,
lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail)
//create the primary string if let attributes = textAttributes {
let mutableText = NSMutableAttributedString.mutableText(for: text ?? "No Text", //loop through the models attributes
textStyle: textStyle, for attribute in attributes {
useScaledFont: useScaledFont, //add attribute on the string
textColor: textColor, attribute.setAttribute(on: mutableText)
alignment: titleLabel?.textAlignment ?? .center, }
lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail)
if let attributes = textAttributes {
//loop through the models attributes
for attribute in attributes {
//add attribute on the string
attribute.setAttribute(on: mutableText)
} }
}
//set the attributed text //set the attributed text
setAttributedTitle(mutableText, for: .normal) setAttributedTitle(mutableText, for: .normal)
setAttributedTitle(mutableText, for: .highlighted) setAttributedTitle(mutableText, for: .highlighted)
} else {
setAttributedTitle(nil, for: .normal)
setAttributedTitle(nil, for: .highlighted)
titleLabel?.text = nil
}
} }
} }