swift - 一个删除线样式中的 Swift 多个标签
问题描述
我尝试对标签实施删除线样式。我将以下代码用于一个标签。但我想为这两个不同的标签画一条线,如图所示。(我stackview
用于这些标签)
提前致谢。
let attributedString2 = NSMutableAttributedString(string: self.productDetailView.productOldLastPriceLabel.text ?? "")
attributedString2.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 2, range: NSMakeRange(0, attributedString2.length))
self.productDetailView.productOldLastPriceLabel.attributedText = attributedString2
解决方案
使用以下代码管理具有不同字体大小的文本的删除线。您可以根据需要修改范围
let str1 = "16230"
let str2 = "63455333"
let dateText = NSMutableAttributedString.init(string: "\(str1)\(str2)")
dateText.setAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 34, weight: UIFont.Weight.bold),
NSAttributedString.Key.foregroundColor: UIColor.black, NSAttributedString.Key.strikethroughStyle: 2],
range: NSMakeRange(0, str1.count))
dateText.setAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 34, weight: UIFont.Weight.thin),
NSAttributedString.Key.foregroundColor: UIColor.black, NSAttributedString.Key.strikethroughStyle: 1],
range: NSMakeRange(str1.count,str2.count))
// set the attributed string to the UILabel object
deadline_lbl.attributedText = dateText
推荐阅读
- r - 如何从 R 中的箱线图中提取 y 轴标签?
- unity3d - Unity2d 每个对象都是不可见的
- javascript - 我应该只使用 CSS 2.1 功能还是现在可以使用 CSS 3 功能?
- jquery - 通过编程设置 Flatpickr defaultDate
- python - 在 Tkinter 中切换帧时出错
- jquery - Laravel 为每个与 jquery
- c# - ASP.NET MVC - 提交表单 DropDownListFor 错误
- ios - pod install post_install 步骤出现重复的 UUID 警告
- swift - MyScript Interactive Ink SDK 转换为数学返回?
- sql - 根据彼此间隔 5 分钟的时间戳连接两个表