Skip to content

glennposadas/UILabelAttributedTextHelper

Repository files navigation

UILabelAttributedTextHelper

A quick helper for setting attributed texts to UILabel.

Screen Shot 2021-11-20 at 10 46 24 AM

Sample usage:

    label.setAttributedText(
        leadingText: "Hello!",
        leadingTextColor: .red,
        leadingTextFont: .boldSystemFont(ofSize: 20)
    )
    
    
    label2.setAttributedText(
        leadingText: "Hello",
        leadingTextColor: .blue,
        leadingTextFont: .boldSystemFont(ofSize: 20),
        trailingText: ", World!",
        trailingTextColor: .red,
        trailingTextFont: .italicSystemFont(ofSize: 20),
        textAlignment: .left,
        numberOfLines: 2,
        lineHeightMultiple: 1,
        lineSpacing: 1
    )
    
    label3.setAttributedText(
        completeString: "I believe that hard work beats talent. This is case sensitive. I learned the value of hard work by working hard",
        textColor: .label,
        font: .systemFont(ofSize: 20),
        highlightedText: "hard work",
        highlightedTextColor: .blue,
        highlightedTextFont: .boldSystemFont(ofSize: 25),
        textAlignment: .right,
        numberOfLines: 0,
        highlightAllOccurrence: false,
        lineHeightMultiple: 1,
        lineSpacing: 1
    )
    
    label4.setAttributedText(
        completeString: "I believe that hard work beats talent. This is case sensitive. I learned the value of hard work by working hard",
        textColor: .label,
        font: .systemFont(ofSize: 20),
        highlightedText: "hard work",
        highlightedTextColor: .blue,
        highlightedTextFont: .boldSystemFont(ofSize: 25),
        textAlignment: .center,
        numberOfLines: 0,
        highlightAllOccurrence: true,
        lineHeightMultiple: 1,
        lineSpacing: 1
    )

About

A quick helper for setting attributed texts to UILabel.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages