Animate a change in part of an NSMutableAttributedString

前端 未结 3 2032
一生所求
一生所求 2021-01-13 04:27

I\'m making an iOS app that has a UITextView. When closing a parenthesis in that UITextView, I want to highlight to the user which opening parenthesis it pairs to. So far I\

3条回答
  •  醉梦人生
    2021-01-13 05:01

    There's a much easier way to do this, which you can see in this answer: Animate text change in UILabel.

    You just have to set the label.attributedText property instead:

    UIView.transition(
        with: label,
        duration: 0.15,
        options: .transitionCrossDissolve,
        animations: {
            label.attributedText = NSAttributedString(string: text, attributes: attributes)
        },
        completion: nil
    )
    

提交回复
热议问题