在Interface builder中将label旋转到横向

时间:2011-04-25 04:14:26

标签: xcode interface-builder label rotation landscape

我只需要界面构建器的帮助。我试图只旋转我的应用程序的标签,但我无法找到任何旋转功能..

任何人都可以帮我旋转标签,我是否需要在xcode中旋转代码?

2 个答案:

答案 0 :(得分:6)

我认为你不能在IB中旋转它。您需要将变换应​​用于视图以使其旋转。

view.transform = CGAffineTransformMakeRotation(3.14/2);

答案 1 :(得分:2)

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.