Reputation: 4080
I am annotating a mutable attributed string with a strikethrough in objective-c. Using the following code.
[MAString addAttribute:NSStrikethroughStyleAttributeName
value:[NSNumber numberWithInt:1]
range:NSMakeRange(0, [text length])]
I am not clear what the value parameter controls and what its possible values are. Does it control thickness? If so, what are the possible values?
Upvotes: 0
Views: 807
Reputation: 2396
This answer is for lazy programmers
extension String {
/// Apply strike font on text
func strikeThrough(lineThickness:Int,lineColor:UIColor) -> NSAttributedString {
let attributeString = NSMutableAttributedString(string: self)
attributeString.addAttribute(
NSAttributedString.Key.strikethroughStyle,
value: lineThickness,
range: NSRange(location: 0, length: attributeString.length))
attributeString.addAttribute(
NSAttributedString.Key.strikethroughColor,
value: lineColor,
range: NSRange(location: 0, length: attributeString.length))
return attributeString
}
}
Usage
yourlabel.attributedText = "your text".strikeThrough(lineThickness: 3, lineColor: .red)
Upvotes: 0
Reputation: 16660
What about having a look to the documentation?
This value indicates whether the text has a line through it and corresponds to one of the constants described in NSUnderlineStyle. The default value for this attribute is styleNone.
And then:
https://developer.apple.com/reference/uikit/nsunderlinestyle
Upvotes: 4