Skip to content

Commit 26b1846

Browse files
author
Stefano Mondino
committed
fix styledText property in order to set attributed text when no style has been previously set
1 parent cd526ec commit 26b1846

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Sources/SwiftRichString/Extensions/UIKit+Extras.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ extension UILabel {
6767
}
6868
}
6969

70-
/// Use this to render automatically the texct with the currently set style instance or styleName.
70+
/// Use this to render automatically the text with the currently set style instance or styleName.
7171
public var styledText: String? {
7272
get {
7373
return attributedText?.string
7474
}
7575
set {
7676
guard let text = newValue else { return }
77-
self.attributedText = self.style?.set(to: text, range: nil)
77+
let style = self.style ?? Style()
78+
self.attributedText = style.set(to: text, range: nil)
7879
}
7980
}
8081

@@ -108,14 +109,15 @@ extension UITextField {
108109
}
109110
}
110111

111-
/// Use this to render automatically the texct with the currently set style instance or styleName.
112+
/// Use this to render automatically the text with the currently set style instance or styleName.
112113
public var styledText: String? {
113114
get {
114115
return attributedText?.string
115116
}
116117
set {
117118
guard let text = newValue else { return }
118-
self.attributedText = self.style?.set(to: text, range: nil)
119+
let style = self.style ?? Style()
120+
self.attributedText = style.set(to: text, range: nil)
119121
}
120122
}
121123

@@ -149,14 +151,15 @@ extension UITextView {
149151
}
150152
}
151153

152-
/// Use this to render automatically the texct with the currently set style instance or styleName.
154+
/// Use this to render automatically the text with the currently set style instance or styleName.
153155
public var styledText: String? {
154156
get {
155157
return attributedText?.string
156158
}
157159
set {
158160
guard let text = newValue else { return }
159-
self.attributedText = self.style?.set(to: text, range: nil)
161+
let style = self.style ?? Style()
162+
self.attributedText = style.set(to: text, range: nil)
160163
}
161164
}
162165

0 commit comments

Comments
 (0)