Reputation: 714
I want to create a UILabel in which the text is like this(like angle not horizontally). Can anyone suggest, please?
Upvotes: 0
Views: 572
Reputation: 1274
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
Upvotes: 0
Reputation: 688
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))
Upvotes: 3