Search code examples
iosswiftcocoa-touchuilabelstrikethrough

UILabel text struck through angle


I want to create a UILabel in which the text is like this(like angle not horizontally). Can anyone suggest, please?

enter image description here


Solution

  • All you need to do is just trim the label width to content size.

    testLabel.text = "Tk 1,750"
    testLabel.frame.size.width = myLabel.intrinsicContentSize.width
    

    and then use as told by @fzh

    testLabel.addSlantLine(slantLineColor: UIColor.lightGray,
                       slantLineWidth: 2,
                       startPoint: CGPoint(x: 0, y: testLabel.frame.height - 2),
                       endPoint: CGPoint(x: testLabel.frame.width, y: 2))
    

    Note: Trim after text update