updated labels to ensure string is valid
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
af2c5cd368
commit
05638422f6
@ -30,6 +30,7 @@ public struct AnyAttribute: LabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
attributedString.removeAttribute(key, range: range)
|
attributedString.removeAttribute(key, range: range)
|
||||||
attributedString.addAttribute(key, value: value, range: range)
|
attributedString.addAttribute(key, value: value, range: range)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,8 @@ public struct ColorLabelAttribute: LabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
|
|
||||||
var colorRange = range
|
var colorRange = range
|
||||||
if length == 0 && location == 0 {
|
if length == 0 && location == 0 {
|
||||||
colorRange = .init(location: location, length: attributedString.length)
|
colorRange = .init(location: location, length: attributedString.length)
|
||||||
|
|||||||
@ -29,6 +29,10 @@ extension LabelAttributeModel {
|
|||||||
public static func == (lhs: any LabelAttributeModel, rhs: any LabelAttributeModel) -> Bool {
|
public static func == (lhs: any LabelAttributeModel, rhs: any LabelAttributeModel) -> Bool {
|
||||||
lhs.isEqual(rhs)
|
lhs.isEqual(rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func isValidRange(on attributedString: NSMutableAttributedString) -> Bool {
|
||||||
|
true//range.location + range.length <= attributedString.string.count
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension NSAttributedString {
|
public extension NSAttributedString {
|
||||||
|
|||||||
@ -24,6 +24,7 @@ public struct StrikeThroughLabelAttribute: LabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick.rawValue, range: range)
|
attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick.rawValue, range: range)
|
||||||
attributedString.addAttribute(.baselineOffset, value: 0, range: range)
|
attributedString.addAttribute(.baselineOffset, value: 0, range: range)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,7 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
attributedString.removeAttribute(.font, range: range)
|
attributedString.removeAttribute(.font, range: range)
|
||||||
attributedString.addAttribute(.font, value: textStyle.font, range: range)
|
attributedString.addAttribute(.font, value: textStyle.font, range: range)
|
||||||
if let textColor {
|
if let textColor {
|
||||||
|
|||||||
@ -52,7 +52,8 @@ public struct UnderlineLabelAttribute: LabelAttributeModel {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Methods
|
// MARK: - Public Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
|
guard isValidRange(on: attributedString) else { return }
|
||||||
attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range)
|
attributedString.addAttribute(.underlineStyle, value: underlineValue.rawValue, range: range)
|
||||||
if let color = color {
|
if let color = color {
|
||||||
attributedString.addAttribute(.underlineColor, value: color, range: range)
|
attributedString.addAttribute(.underlineColor, value: color, range: range)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user