shy
shy

Reputation: 107

rotate label to landscape in Interface builder

I just need help with interface builder. I am trying to rotate only a label for my apps but I can't find the rotate function any where..

Can anyone help me to rotate a label, do I need code in xcode to rotate it?

Upvotes: 2

Views: 6601

Answers (2)

Diskprotek
Diskprotek

Reputation: 601

In Swift 4, add the following code to your View Controller:

@IBDesignable
class DesignableLabel: UILabel {
}

extension UIView {
    @IBInspectable
    var rotation: Int {
        get {
            return 0
        } set {
            let radians = ((CGFloat.pi) * CGFloat(newValue) / CGFloat(180.0))
            self.transform = CGAffineTransform(rotationAngle: radians)
        }
    }
}

Then in interface builder, change your label class type in the Identity Inspector to "DesignableLabel". Your label should then be rotatable in interface builder.

Upvotes: 8

David Neiss
David Neiss

Reputation: 8237

I don't think you can rotate it in IB. You need to appy a transform to the view to get it to rotate.

view.transform = CGAffineTransformMakeRotation(3.14/2);

Upvotes: 7

Related Questions