Search code examples
iosswiftuikituilabelrotatetransform

Rotating UILabel that is under an UIView


I'm trying to rotate an UILabel that is under a (created on storyboard) UIView but it's crashing the application due nil value when I try to CGAffineTransform(rotationAngle: ). Is it causing because I'm using storyboard?

enter image description here

    @IBDesignable
    class AnalogView: UIView {

        @IBOutlet var prevPitch:UILabel!
        @IBOutlet var currectPitch:UILabel!
        @IBOutlet var nextPitch:UILabel!

        fileprivate let thickHorizontalLayer = CAShapeLayer()
        fileprivate let thinHorizontalLayer = CAShapeLayer()

        fileprivate let roundThinLayer = CAShapeLayer(layer: self)
        fileprivate let roundThickLayer = CAShapeLayer(layer: self)

        @IBInspectable var thickYCoord: CGFloat = 50.0
        @IBInspectable var thinYCoord: CGFloat = 52.5



        @IBInspectable var counterColor: UIColor = UIColor.orange

        override init(frame: CGRect = .zero) {
            super.init(frame: frame)



            configure()
        }

        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)

        }

        private func configure() {


            prevPitch.transform = CGAffineTransform(rotationAngle: 3.14)

Solution

  • I've managed to solve this question by adding the labels with ViewController instead of the UIView. Used prevPitch.transform = CGAffineTransform(rotationAngle: 3.14) on ViewController and it worked.