Skip to content

When there are multiple clickable texts in the string, the color cannot be set differently #419

@zuqiu123

Description

@zuqiu123
let htmlStr = "You can parse HTML with <strong>strong</strong>, <em>em</em>, and even <strong><em>nested strong and em</em></strong> tags."
let emStr = StringStyle(
    .link(URL("emStr://")),
    .color(UIColor.red),
    .underline(.single, nil)
)

let strongStr = StringStyle(
    .link(URL("strongStr://")),
    .color(UIColor.green),
    .underline(.single, nil)
)

let style = StringStyle(
    .font(.systemFont(ofSize: 30)),
    .color(.black),
    .xmlRules([
        .style("em", emStr),
        .style("strong", strongStr),
    ])
)
let attributedText = htmlStr.styled(with: style)

textView.linkTextAttributes = [
    NSAttributedString.Key.foregroundColor: UIColor.yellow
]
textView.attributedText = attributedText

Two links are set. If you do not set this sentence,

  textView.linkTextAttributes = [
            NSAttributedString.Key.foregroundColor: UIColor.yellow
        ]

image

they will all show blue. After setting, they will all turn yellow. How to set two different colors, and you can click the link,please help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions