AttributedLabel

public struct AttributedLabel : Element, Hashable
  • The attributed text to render in the label.

    If you customize the line break mode using an NSParagraphStyle, the mode will be normalized based on the number of lines allowed. This is because some line break modes are incompatible with multi-line text rendering in TextKit, which is used to detect where links are in the text. Some modes also break line height adjustment in single-line labels, so these are also normalized.

    Specifically:

    • 1 line labels with a mode of byCharWrapping or byWordWrapping will be normalized to byClipping.
    • Multiline labels with a mode of byTruncatingHead or byTruncatingMiddle will be normalized to byTruncatingTail.

    Declaration

    Swift

    public var attributedText: NSAttributedString
  • Declaration

    Swift

    public var numberOfLines: Int
  • A shadow to display behind the label’s text. Defaults to no shadow.

    Note

    This shadow is applied using the backing view’s CALayer, and will affect the entire label. To apply a shadow to only a portion of text, you can instead set NSAttributedString.Key.shadow on the string, but note that those shadows may be clipped by the bounds of the backing view.

    Declaration

    Swift

    public var shadow: TextShadow?
  • An offset that will be applied to the rect used by drawText(in:).

    This can be used to adjust the positioning of text within each line’s frame, such as adjusting the way text is distributed within the line height.

    Declaration

    Swift

    public var textRectOffset: UIOffset
  • Determines if the label should be included when navigating the UI via accessibility.

    Declaration

    Swift

    public var isAccessibilityElement: Bool
  • A Boolean value that determines whether the label reduces the text’s font size to fit the title string into the label’s bounding rectangle.

    Normally, the label draws the text with the font you specify in the font property. If this property is true, and the text in the text property exceeds the label’s bounding rectangle, the label reduces the font size until the text fits or it has scaled the font down to the minimum font size. The default value for this property is false.

    If you change it to true, be sure that you also set an appropriate minimum font scale by modifying the minimumScaleFactor property.

    This autoshrinking behavior is only intended for use with a single-line label.

    Declaration

    Swift

    public var adjustsFontSizeToFitWidth: Bool
  • The minimum scale factor for the label’s text.

    If the adjustsFontSizeToFitWidth is true, use this property to specify the smallest multiplier for the current font size that yields an acceptable font size for the label’s text.

    If you specify a value of 0 for this property, the label doesn’t scale the text down. The default value of this property is 0.

    Declaration

    Swift

    public var minimumScaleFactor: CGFloat
  • A Boolean value that determines whether the label tightens text before truncating.

    When the value of this property is true, the label tightens intercharacter spacing of its text before allowing any truncation to occur. The label determines the maximum amount of tightening automatically based on the font, current line width, line break mode, and other relevant information.

    This autoshrinking behavior is only intended for use with a single-line label.

    The default value of this property is false.

    Declaration

    Swift

    public var allowsDefaultTighteningForTruncation: Bool
  • A set of accessibility traits that should be applied to the label, these will be merged with any existing traits.

    Declaration

    Swift

    public var accessibilityTraits: Set<AccessibilityElement.Trait>?
  • A localized string that represents the current value of the accessibility element.

    The value is a localized string that contains the current value of an element. For example, the value of a slider might be 9.5 or 35% and the value of a text field is the text it contains.

    Declaration

    Swift

    public var accessibilityValue: String?
  • A localized string that describes the result of performing an action on the element, when the result is non-obvious.

    Declaration

    Swift

    public var accessibilityHint: String?
  • A string that identifies the element.

    Declaration

    Swift

    public var accessibilityIdentifier: String?
  • An array containing one or more AccessibilityElement.CustomActions, defining additional supported actions. Assistive technologies, such as VoiceOver, will display your custom actions to the user at appropriate times.

    Declaration

    Swift

    public var accessibilityCustomActions: [AccessibilityElement.CustomAction]
  • A set of data types to detect and automatically link in the label.

    Declaration

    Swift

    public var linkDetectionTypes: Set<LinkDetectionType>
  • A set of attributes to apply to links in the string.

    Declaration

    Swift

    public var linkAttributes: [NSAttributedString.Key : AnyHashable]
  • A set of attributes to apply to links when they are touched.

    Declaration

    Swift

    public var activeLinkAttributes: [NSAttributedString.Key : AnyHashable]
  • Declaration

    Swift

    public init(attributedText: NSAttributedString, configure: (inout `Self`) -> Void = { _ in })

Element

Models

  • Types of data that can be detected and automatically turned into links.

    Corresponds to NSTextCheckingResult.CheckingType types.

    See more

    Declaration

    Swift

    public enum LinkDetectionType : Equatable, Hashable