NSMutableAttributedString不能在特定范围的tableviewcell中工作
我已经跟着这个问题,但没有解决我的问题。
我在ViewController中有一个tableview
, tableviewcell
有一个标签。 我想用NSStrikethroughStyleAttributeName
来设置。 如果我设置完整的string作为删除线它的作品, 但如果我设置为部分它不起作用。
下面的代码为成功的结果
let strOriginalPrice = "my price" let strdiscountedPrice = "discounted price" let strPrice = strOriginalPrice+" "+strdiscountedPrice let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length)) cell.lblPrice.attributedText = attributeString
下面的代码不工作
let attributedDiscunt: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) attributedDiscunt.addAttribute(NSStrikethroughStyleAttributeName, value:2, range: NSMakeRange(0, strOriginalPrice.characters.count-1)) cell.lblPrice.attributedText = attributedDiscunt
尝试这个,
let strOriginalPrice = "my price" let strdiscountedPrice = "discounted price" let strPrice = strOriginalPrice+" "+strdiscountedPrice // let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) // attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length)) let attributedDiscunt: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) attributedDiscunt.addAttribute(NSStrikethroughStyleAttributeName, value:2, range: NSMakeRange(0, strOriginalPrice.characters.count-1)) attributedDiscunt.addAttribute(NSBaselineOffsetAttributeName, value: 0, range: NSMakeRange(0, strOriginalPrice.characters.count-1)) cell.lblPrice.attributedText = attributedDiscunt
- NSTimer – 如何在Swift中延迟
- 如何让对象在callback中释放?
- UrbanThings @ SwiftSummit 2016
- ReplayKit:startRecording()完成处理程序从不input
- 什么是禁用UICollectionView / UICollectionViewLayout旋转或界限更改的交叉淡化的最佳方法?
- 在ios编程的iMessage发送图片+文本?
- 符号(s)找不到build筑i386关于opencv
- 无法在Xcode中进行debugging:debugging器中将无法使用此模块的debugging信息
- UISearchController的searchBar不会填满整个宽度