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.systemFontwill be assumed.Declaration
Swift
func fontSize(_ size: CGFloat) -> NSAttributedStringParameters
sizeThe 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.systemFontwill be assumed. -
Applies the given paragraph style.
Declaration
Swift
func paragraphStyle(_ paragraphStyle: NSParagraphStyle) -> NSAttributedStringParameters
paragraphStyleThe 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
configureclosure is called on that paragraph style; otherwise a newNSMutableParagraphStyleis used.For example:
let result = "Hello World".paragraphStyle { $0.firstLineHeadIndent = 10 }Declaration
Swift
func paragraphStyle(configure: (NSMutableParagraphStyle) -> Void) -> NSAttributedStringParameters
configureThe 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) -> NSAttributedStringParameters
colorThe 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) -> NSAttributedStringParameters
colorthe 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) -> NSAttributedStringParameters
ligatureIndicates 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
0means that no kerning change is applied.Declaration
Swift
func kern(_ kern: Float) -> NSAttributedStringParameters
kernThe amount to modify the default kerning.
0means 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) -> NSAttributedStringParameters
styleThe
NSUnderlineStyleto 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) -> NSAttributedStringParameters
colorThe 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) -> NSAttributedStringParameters
colorThe color to apply.
styleThe
NSUnderlineStyleto 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) -> NSAttributedStringParameters
styleThe
NSUnderlineStyleto 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) -> NSAttributedStringParameters
colorThe 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) -> NSAttributedStringParameters
colorThe color to apply.
styleThe
NSUnderlineStyleto 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) -> NSAttributedStringParameters
widthThe width of the stroke.
colorThe color of the stroke.
Return Value
A new attributed string that has the given stroke attributes applied.
-
Configures the shadow by setting an
NSShadowinstance.Declaration
Swift
func shadow(_ shadow: NSShadow) -> NSAttributedStringParameters
shadowThe
NSShadowto apply.Return Value
A new attributed string that has the given shadow applied.
-
Configures the shadow using a closure that receives an
NSShadowinstance.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) -> NSAttributedStringParameters
configureThe closure that you use to configure the shadow; it is passed an
NSShadowinstance that you can change and is then applied.Return Value
A new attributed string that has the configured shadow applied.
-
Creates a new
NSTextAttachmentand passes it to theconfigureclosure.Declaration
Swift
func attachment(configure: (NSTextAttachment) -> Void) -> NSAttributedStringParameters
configurethe closure that you can use to configure the
NSTextAttachmentinstance.Return Value
A new attributed string that has the configured text attachment.
-
Adds the “letter pressed” text effect.
Declaration
Swift
func letterPressed() -> NSAttributedStringReturn 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) -> NSAttributedStringParameters
urlThe 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) -> NSAttributedStringParameters
stringThe 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) -> NSAttributedStringParameters
offsetThe 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) -> NSAttributedStringParameters
obliquenessThe skew that is applied to glyphs;
0means 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) -> NSAttributedStringParameters
expansionThe 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.systemFontwill be assumed.Declaration
Swift
func fontSize(_ size: CGFloat) -> NSAttributedString?Parameters
sizeThe 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) -> NSAttributedStringParameters
colorThe 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) -> NSAttributedStringParameters
colorthe 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) -> NSAttributedStringParameters
colorThe 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) -> NSAttributedStringParameters
colorThe color to apply.
styleThe
NSUnderlineStyleto 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) -> NSAttributedStringParameters
colorThe 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) -> NSAttributedStringParameters
colorThe color to apply.
styleThe
NSUnderlineStyleto 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) -> NSAttributedStringParameters
widthThe width of the stroke.
colorThe color of the stroke.
Return Value
A new attributed string that has the given stroke attributes applied.
-
Configures the shadow by setting an
NSShadowinstance. -
Configures the shadow using a closure that receives an
NSShadowinstance.For example:
let result = "Hello World".shadow { $0.shadowOffset = CGSize(width: 3, height: 3) $0.shadowBlurRadius = 2 $0.shadowColor = Color.gray } -
Creates a new
NSTextAttachmentand passes it to theconfigureclosure.
View on GitHub
RichString Protocol Reference