How can I create a UILabel with strikethrough text?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
UILabel does not expose a direct "strikethrough" property. The standard way to draw a strike line is to assign an attributed string to attributedText and include the right text attributes for the range you want to style.
Once you think in terms of attributed text instead of plain text, the problem becomes straightforward. You can strike the whole label, only one substring, or rebuild the styling dynamically from model state.
Apply Strikethrough to the Entire Label
For the simplest case, create an NSAttributedString with .strikethroughStyle and assign it to the label:
This tells UIKit to render the label with a single strike line across the full text. The value comes from NSUnderlineStyle, even though the visual result is a strikethrough.
Style the Strike and the Text Together
Most real interfaces do more than just add a line. You usually want the struck text to look secondary, for example with a lighter color or a smaller font. These are just more attributes on the same string:
This approach is flexible because the strike line and the text color are controlled independently. That is useful for sale prices, disabled states, completed tasks, and archived items.
Strike Only Part of the Label
Many interfaces need mixed styling. A shopping screen may show the old price struck through but the new price highlighted. Use NSMutableAttributedString so you can assign attributes to specific ranges:
This is the pattern you want whenever different parts of the string carry different meaning.
Build a Reusable Helper
If your app applies this effect in several places, wrap the styling in a helper so view code stays clean:
For dynamic interfaces, it is often better to rebuild the attributed string from state than to try to mutate an existing one in place.
Update the Label From Model State
A common example is a to-do list where completed items should be crossed out:
This is simple, readable, and safe for reusable cells in table views or collection views.
Common Pitfalls
The most common mistake is setting label.text after label.attributedText. Plain text assignment replaces the attributed value, so the strike line disappears.
Another common issue is using an invalid NSRange when styling only part of a string. If the substring is not found or the range is calculated incorrectly, the label may show partial formatting or crash in debug builds.
People also set .strikethroughColor without .strikethroughStyle. The color attribute alone is not enough. UIKit needs a style value before it draws the line.
Finally, reusable cells need full reconfiguration. If one cell shows struck text and the next one should not, reset both attributedText and text intentionally instead of assuming old state will disappear on its own.
Summary
- Use
attributedText, nottext, to create strikethrough text in aUILabel. - Apply
.strikethroughStyleto the whole string or to a specific range. - Combine the strike line with font and color attributes for realistic UI styling.
- Use
NSMutableAttributedStringwhen only part of the label should be crossed out. - Reset reused labels carefully so old attributed state does not leak into new content.

