4

Why is transform rotation not shown/previewed inside the storyboard? It works fine in the app . I have other attributes inside my @IBDesignable class that works fine.

How can I achieve this?

@IBDesignable
class CustomUILabel: UILabel {

    @IBInspectable var label_Rotation: Double = 0 {
        didSet {

            rotateLabel(label_Rotation)

        }
    }

    func rotateLabel(labelRotation: Double)  {
        self.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2 + labelRotation))
    }

}
Krunal
  • 77,632
  • 48
  • 245
  • 261
SNos
  • 3,430
  • 5
  • 42
  • 92

1 Answers1

3

This seems working with following result (may be it's what you expect):

Note: I've this in Swift 4

@IBDesignable
class CustomUILabel: UILabel {

    @IBInspectable var label_Rotation: Double = 0 {
        didSet {
            rotateLabel(labelRotation: label_Rotation)
            self.layoutIfNeeded()
        }
    }

    func rotateLabel(labelRotation: Double)  {
        self.transform = CGAffineTransform(rotationAngle: CGFloat((Double.pi * 2) + labelRotation))
    }
}

Result:

enter image description here

enter image description here

Krunal
  • 77,632
  • 48
  • 245
  • 261