diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index 879588d1..17439074 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -158,26 +158,31 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { //clear the arrays holding actions accessibilityCustomActions = [] - - //create the primary string - let mutableText = NSMutableAttributedString.mutableText(for: text ?? "No Text", - textStyle: textStyle, - useScaledFont: useScaledFont, - textColor: textColor, - 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) + 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) + + 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 + 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) } }