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 //create the primary string
let mutableText = NSMutableAttributedString.mutableText(for: text ?? "No Text", let mutableText = NSMutableAttributedString.mutableText(for: text,
textStyle: textStyle, textStyle: textStyle,
useScaledFont: useScaledFont, useScaledFont: useScaledFont,
textColor: textColor, textColor: textColor,
alignment: titleLabel?.textAlignment ?? .center, alignment: titleLabel?.textAlignment ?? .center,
lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail) lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail)
if let attributes = textAttributes { if let attributes = textAttributes {
//loop through the models attributes //loop through the models attributes
for attribute in attributes { for attribute in attributes {
//add attribute on the string //add attribute on the string
attribute.setAttribute(on: mutableText) attribute.setAttribute(on: mutableText)
}
} }
//set the attributed text
setAttributedTitle(mutableText, for: .normal)
setAttributedTitle(mutableText, for: .highlighted)
} else {
setAttributedTitle(nil, for: .normal)
setAttributedTitle(nil, for: .highlighted)
titleLabel?.text = nil
} }
//set the attributed text
setAttributedTitle(mutableText, for: .normal)
setAttributedTitle(mutableText, for: .highlighted)
} }
} }