RichString
public protocol RichString
The RichString protocol defines the interface of this framework.
Note
All attributes are always applied on the entire range of the attributed string. This means that you normally create attributed strings for the text parts that have the desired attributes, and then concatenate them (using operator+(_:_:)
for example).
-
Applies the given font size. If no font was set on the attributed string yet,
Font.systemFont
will be assumed.Declaration
Swift
func fontSize(_ size: CGFloat) -> NSAttributedString
Parameters
size
The desired point size of the attributed string.
Return Value
A new attributed string that has the given font size attribute.
-
Applies the given font size. If no font was set on the attributed string yet,
Font.systemFont
will be assumed. -
Applies the given paragraph style.
Declaration
Swift
func paragraphStyle(_ paragraphStyle: NSParagraphStyle) -> NSAttributedString
Parameters
paragraphStyle
The paragraph style that is applied.
Return Value
A new attributed string that has the paragraph style applied.
-
Applies a paragraph style, configuring it with the given closure. If the attributed string already had a paragraph style attribute, the
configure
closure is called on that paragraph style; otherwise a newNSMutableParagraphStyle
is used.For example:
let result = "Hello World".paragraphStyle { $0.firstLineHeadIndent = 10 }
Declaration
Swift
func paragraphStyle(configure: (NSMutableParagraphStyle) -> Void) -> NSAttributedString
Parameters
configure
The closure that you can use to configure the paragraph style.
Return Value
A new attributed string that has the configured paragraph style applied.
-
Applies the given (foreground) color.
Declaration
Swift
func color(_ color: Color) -> NSAttributedString
Parameters
color
The foreground color that is applied.
Return Value
A new attributed string that has the given foreground color.
-
Applies the given background color.
Declaration
Swift
func backgroundColor(_ color: Color) -> NSAttributedString
Parameters
color
the background color that is applied
Return Value
a new attributed string that has the given background color.
-
Configures whether or not to use ligatures. Default is that they are used.
Declaration
Swift
func ligature(_ ligature: Bool) -> NSAttributedString
Parameters
ligature
Indicates whether or not ligatures should be used.
Return Value
A new attributed string that has the given ligature attribute.
-
Configures the amount with which to modify the default kerning. The default
0
means that no kerning change is applied.Declaration
Swift
func kern(_ kern: Float) -> NSAttributedString
Parameters
kern
The amount to modify the default kerning.
0
means kerning is disabled.Return Value
A new attributed string that has the given kerning applied.
-
Configures the strike through style.
Declaration
Swift
func strikeThrough(style: NSUnderlineStyle) -> NSAttributedString
Parameters
style
The
NSUnderlineStyle
to apply. Please note that depending on OS and version not all styles may actually work.Return Value
A new attributed string that has the given strike through style applied.
-
Configures the strike through color.
Declaration
Swift
func strikeThrough(color: Color) -> NSAttributedString
Parameters
color
The color to apply. Please note that only setting the color has no effect, the style must be configured as well.
Return Value
A new attributed string that has the given strike through color applied.
-
Configures both the strike through color and style.
Declaration
Swift
func strikeThrough(color: Color, style: NSUnderlineStyle) -> NSAttributedString
Parameters
color
The color to apply.
style
The
NSUnderlineStyle
to apply. Please note that depending on OS and version not all styles may actually work.Return Value
A new attributed string that has the given strike through color and style applied.
-
Configures the underline style.
Declaration
Swift
func underline(style: NSUnderlineStyle) -> NSAttributedString
Parameters
style
The
NSUnderlineStyle
to apply. Please note that depending on OS and version not all styles may actually work.Return Value
A new attributed string that has the given underline style applied.
-
Configures the underline color.
Declaration
Swift
func underline(color: Color) -> NSAttributedString
Parameters
color
The color to apply. Please note that only setting the color has no effect, the style must be configured as well.
Return Value
A new attributed string that has the given underline color applied.
-
Configures both the underline color and style.
Declaration
Swift
func underline(color: Color, style: NSUnderlineStyle) -> NSAttributedString
Parameters
color
The color to apply.
style
The
NSUnderlineStyle
to apply. Please note that depending on OS and version not all styles may actually work.Return Value
A new attributed string that has the given underline color and style applied.
-
Configures the stroke.
Declaration
Swift
func stroke(width: Float, color: Color) -> NSAttributedString
Parameters
width
The width of the stroke.
color
The color of the stroke.
Return Value
A new attributed string that has the given stroke attributes applied.
-
Configures the shadow by setting an
NSShadow
instance.Declaration
Swift
func shadow(_ shadow: NSShadow) -> NSAttributedString
Parameters
shadow
The
NSShadow
to apply.Return Value
A new attributed string that has the given shadow applied.
-
Configures the shadow using a closure that receives an
NSShadow
instance.For example:
let result = "Hello World".shadow { $0.shadowOffset = CGSize(width: 3, height: 3) $0.shadowBlurRadius = 2 $0.shadowColor = Color.gray }
Declaration
Swift
func shadow(configure: (NSShadow) -> Void) -> NSAttributedString
Parameters
configure
The closure that you use to configure the shadow; it is passed an
NSShadow
instance that you can change and is then applied.Return Value
A new attributed string that has the configured shadow applied.
-
Creates a new
NSTextAttachment
and passes it to theconfigure
closure.Declaration
Swift
func attachment(configure: (NSTextAttachment) -> Void) -> NSAttributedString
Parameters
configure
the closure that you can use to configure the
NSTextAttachment
instance.Return Value
A new attributed string that has the configured text attachment.
-
Adds the “letter pressed” text effect.
Declaration
Swift
func letterPressed() -> NSAttributedString
Return Value
A new attributed string that has the “letter pressed” text effect applied.
-
Creates hyperlink to the given URL with the receiver as text.
Declaration
Swift
func link(url: NSURL) -> NSAttributedString
Parameters
url
The URL to which the hyperlink points.
Return Value
A new attributed string that is the receiver converted to a hyperlink.
-
Creates hyperlink to the given URL with the receiver as text.
Declaration
Swift
func link(string: String) -> NSAttributedString
Parameters
string
The URL string to which the hyperlink points.
Return Value
A new attributed string that is the receiver converted to a hyperlink.
-
Configures the baseline offset.
Declaration
Swift
func baselineOffset(_ offset: Float) -> NSAttributedString
Parameters
offset
The number of points the text is offset from the baseline.
Return Value
A new attributed string that has the given baseline offset configured.
-
Configures the skew to be applied to glyphs.
Declaration
Swift
func obliqueness(_ obliqueness: Float) -> NSAttributedString
Parameters
obliqueness
The skew that is applied to glyphs;
0
means no skew.Return Value
A new attributed string that has the given obliqueness configured.
-
Configures the expansion to be applied to glyphs.
Declaration
Swift
func expansion(_ expansion: Float) -> NSAttributedString
Parameters
expansion
The log of the expansion factor to be applied to glyphs.
Return Value
A new attributed string that has the given expansion configured.
-
Applies the given font size. If no font was set on the attributed string yet,
Font.systemFont
will be assumed.Declaration
Swift
func fontSize(_ size: CGFloat) -> NSAttributedString?
Parameters
size
The desired point size of the attributed string.
Return Value
A new attributed string that has the given font size attribute.
-
Applies the given (foreground) color.
Declaration
Swift
func color(_ color: Color) -> NSAttributedString
Parameters
color
The foreground color that is applied.
Return Value
A new attributed string that has the given foreground color.
-
Applies the given background color.
Declaration
Swift
func backgroundColor(_ color: Color) -> NSAttributedString
Parameters
color
the background color that is applied
Return Value
a new attributed string that has the given background color.
-
Configures the strike through color.
Declaration
Swift
func strikeThrough(color: Color) -> NSAttributedString
Parameters
color
The color to apply. Please note that only setting the color has no effect, the style must be configured as well.
Return Value
A new attributed string that has the given strike through color applied.
-
Configures both the strike through color and style.
Declaration
Swift
func strikeThrough(color: Color, style: NSUnderlineStyle) -> NSAttributedString
Parameters
color
The color to apply.
style
The
NSUnderlineStyle
to apply. Please note that depending on OS and version not all styles may actually work.Return Value
A new attributed string that has the given strike through color and style applied.
-
Configures the underline color.
Declaration
Swift
func underline(color: Color) -> NSAttributedString
Parameters
color
The color to apply. Please note that only setting the color has no effect, the style must be configured as well.
Return Value
A new attributed string that has the given underline color applied.
-
Configures both the underline color and style.
Declaration
Swift
func underline(color: Color, style: NSUnderlineStyle) -> NSAttributedString
Parameters
color
The color to apply.
style
The
NSUnderlineStyle
to apply. Please note that depending on OS and version not all styles may actually work.Return Value
A new attributed string that has the given underline color and style applied.
-
Configures the stroke.
Declaration
Swift
func stroke(width: Float, color: Color) -> NSAttributedString
Parameters
width
The width of the stroke.
color
The color of the stroke.
Return Value
A new attributed string that has the given stroke attributes applied.
-
Configures the shadow by setting an
NSShadow
instance. -
Configures the shadow using a closure that receives an
NSShadow
instance.For example:
let result = "Hello World".shadow { $0.shadowOffset = CGSize(width: 3, height: 3) $0.shadowBlurRadius = 2 $0.shadowColor = Color.gray }
-
Creates a new
NSTextAttachment
and passes it to theconfigure
closure.