首页 > 解决方案 > Swift 动画删除线 uilabel

问题描述

我正在尝试通过动画制作罢工动画。我能找到的唯一帮助是这个UIFont: 如何为删除线设置动画并匹配字体样式?但它的 Objective-C 我正在尝试这样的结果https://dribbble.com/shots/3167358-Microinteractions-for-to-do-list-app。但无法弄清楚如何为删除线设置动画。

 guard let postsText = post?.post else { return }

        let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: postsText)
        attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 1, range: NSMakeRange(0, attributeString.length))
        postLabel.attributedText = attributeString

标签: swift

解决方案


我创建了一个使用贝塞尔路径创建此效果的库,为删除线设置动画。你可以在这里找到代码:

https://github.com/chrsp/StrikethroughLabel

作为记录,本课程展示了您如何做到这一点:

https://github.com/chrsp/StrikethroughLabel/blob/master/StrikethroughLabel/StrikethroughLabel.swift


推荐阅读