我只需要界面构建器的帮助。我试图只旋转我的应用程序的标签,但我无法找到任何旋转功能..
任何人都可以帮我旋转标签,我是否需要在xcode中旋转代码?
答案 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.