I want to display a text at 45 degree with a background color.
Example

Thanks in advance
This element contains two sub-elements:
UIView;UILabel.First can be achieved by creating custom view with override draw method:
class TriangleView: UIView {
override func draw(_ rect: CGRect) {
let path = UIBezierPath()
path.move(to: .zero)
path.addLine(to: CGPoint(x: rect.maxX, y: 0))
path.addLine(to: CGPoint(x: 0, y: rect.maxY))
path.close()
UIColor.red.withAlphaComponent(0.5).setFill()
path.fill()
}
}
The second is simple transform rotation for -45 degree:
label.transform = CGAffineTransform(rotationAngle: -.pi / 4)
Result:

Next thing you should manage – precisely set UILabel bounds (label shouldn't go away from the screen) and lines count. Constraints and attributed inspector for UILabel element can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With