Swift: strikethroughStyle For Label (Middle Delete Line For Label)

strike label text swift
swift attributed string
change font size of attributed string swift

How to add strikethroughStyle for label. A middle delete line to a number in UILabel. Check the attach image for reference.

Use attributeString



NSDictionary * attribtues = @{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),
                              NSStrikethroughColorAttributeName:[UIColor redColor]};
NSAttributedString * attr = [[NSAttributedString alloc] initWithString:@"label" attributes:attribtues];
self.label.attributedText = attr;

attributed string swift 4 nsattributedstring tutorial convert string to attributed string objective c. How to add strikethroughStyle for label. A middle delete line to a  Note that sizeToFit will respect your initial label's minimum width. If you start with a label 100 wide and call sizeToFit on it, it will give you back a (possibly very tall) label with 100 (or a little less) width. You might want to set your label to the minimum width you want before resizing.

For Programatically Use Below Code

Prefer to Use Extension:

extension String {
    func strikeThrough() -> NSAttributedString {
        let attributeString =  NSMutableAttributedString(string: self)
        attributeString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSUnderlineStyle.styleSingle.rawValue, range: NSMakeRange(0,attributeString.length))
        return attributeString

And call this Function

myLabel.attributedText = "my string".strikeThrough()

And Result look like this.

[attributeString length])];. Swift let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "Your String here") attributeString. To add a UILabel to a UIToolBar you need to add a generic UIView object to your UIToolBar in IB by dragging a new UIView object over your UIToolBar. IB will automatically create a UIBarButtonItem that will be initialized with your custom UIView. Next add a UILabel to the UIView and edit the UILabel graphically to match your preferred style.

add middle delete line for UILabel in storyboard

  1. tap uilabel in storyboard, look at utilities. Select Attributed

  2. tap font icon, open font panel.

  3. Select the text you want to change

  4. Select middle line (ex: Single)

  5. completed.

The value of this attribute is an NSNumber object containing an integer. This value indicates whether the text has a line through it and corresponds to one of the  Leave your existing constraints (10pts space to the other view) alone, but add another constraint: make your labels' left edges 10pts away from their superview's left edge with a non-required priority (the default high priority will probably work well). Then, when you want them to move left, remove the left view altogether.

Updated function from @krunal answer for Swift4

extension String {
    func strikeThrough() -> NSAttributedString {
        let attributeString =  NSMutableAttributedString(string: self)
        attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0,attributeString.length))
        return attributeString

and to call the function is the same

yourLabel.attributedText = "yourString".strikeThrough()

Then the label's text is strikethrough on iOS 13 beta 6. label2.text = nil // If this line is active the strikethroughStyle will still be shown. If you want to remove the word potatoes from the sting altogether, you can use: string = string.replacingOccurrences(of: "potatoes", with: "", options: NSString.CompareOptions.literal, range: nil) If you want to use some other characters in your sting, use:

Update Note: Bill Morefield updated this tutorial for Swift 4.2, Xcode 10 beta 5, and iOS 12 beta 5. Locate the NotesListViewController and select the Title label in the prototype cell. Next, remove the following lines from viewDidLoad() : strikethroughStyle: 1] let scriptAttributes = [NSAttributedString. The final customization is the detail callout accessory. It’s a single line, which is enough for short location text, but some of the longer location values are truncated like this one: Now you need a multi-line label. Add the following code to ArtworkView‘s willSet:

Creating the custom label effects in your application it's not a big deal you can easily make it your own way here I am showing you a few  How to remove gridlines, labels, tickmarks, axis lines, and legends from Charts – VB.NET The Chart functionality built into Visual Studio 2012 is a great way to provide a user some visual insight into the data your program is providing.

01/08/20--01:30: preferredMaxLayoutWidth not working in Swift? 01/14/20--07:​58: Swift: strikethroughStyle For Label (Middle Delete Line For Label). Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts In the last four tutorials, you have learned a great deal about Chart.js. After reading the first four tutorials, you should now be able to customize the tooltips and labels , change the fonts, and create different chart types.

  • Do you mean "strikethrough"?
  • Can do that in storyboard ?
  • Do you have a static text label? I just drag a outlet,then setup in viewDidLoad?
  • You can't do it in storyborad you have to do it via code
  • not working in my label where response come from the api
  • response come from the api should set programmatically (Leo's answer)