.xib 中的垂直 UISlider 用于自定义 class?

Vertical UISlider in .xib for custom class?

我正在尝试创建一个可重复使用的自定义视图 class,其中的 .xib 文件布置了几个按钮和一个垂直滑块。我知道我可以使用

以编程方式旋转 class 文件中的 UISlider
slider.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 3.0 / 2.0))

如果我的 class 是@IBDesignable,我可以在主情节提要中看到垂直滑块,但是是否可以在我的 .xib 文件布局中看到垂直滑块?

准确答案是。但是有一个解决方法。按照以下步骤操作。

 1. Create a slider 

 2.Show the "Identity Inspector"

 3.Add a "User Defined Runtime Attribute"

 4.Set the key path to "layer.transform.rotation.z", the type as "String" ("Number" won't allow floating point values) (possible since Xcode 5) and the value to "-1.570795" (-π/2).

不幸的是,它在 Interface Builder 中仍将显示为水平。

但是您可以定位中心并且不需要创建自定义 class,因此在某些情况下它可能会很有用。