Skip to content

Commit 8ab55a0

Browse files
authored
Merge pull request #65 from stefanomondino/develop
Set styled text when no style has been applied
2 parents 3096b02 + 26b1846 commit 8ab55a0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Sources/SwiftRichString/Extensions/UIKit+Extras.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ extension UILabel {
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)