I want to create a UILabel in which the text is like this(like angle not horizontally). Can anyone suggest, please?
UILabel text struck through angle
555 Views Asked by KhanShaheb At
2
There are 2 best solutions below
3

you can add extension like this:
extension UILabel {
func addSlantLine(slantLineColor: UIColor, slantLineWidth:CGFloat, startPoint: CGPoint, endPoint: CGPoint) {
let slantLinePath = UIBezierPath()
slantLinePath.move(to: startPoint)
slantLinePath.addLine(to: endPoint)
let slantLineLayer = CAShapeLayer()
slantLineLayer.path = slantLinePath.cgPath
slantLineLayer.lineWidth = slantLineWidth
slantLineLayer.strokeColor = slantLineColor.cgColor
layer.addSublayer(slantLineLayer)
}
}
use:
testLabel.addSlantLine(slantLineColor: UIColor.lightGray,
slantLineWidth: 2,
startPoint: CGPoint(x: 0, y: testLabel.frame.height - 2),
endPoint: CGPoint(x: testLabel.frame.width, y: 2))
All you need to do is just trim the label width to content size.
and then use as told by @fzh
Note: Trim after text update