c_booth
c_booth

Reputation: 2225

Vertical UISlider in .xib for custom class?

I'm trying to create a reusable custom view class with a .xib file laying out a few buttons and a vertical slider. I know that I can programmatically rotate a UISlider in the class file with

slider.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 3.0 / 2.0))

and if my class is @IBDesignable I can see the vertical slider in the main StoryBoard, but is it possible to see the vertical slider in my .xib file layout?

Upvotes: 0

Views: 831

Answers (1)

Kumar Utsav
Kumar Utsav

Reputation: 2841

The precise answer is NO. But there is a workaround to this. Follow these steps.

 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).

Unfortunately, it will still appear as horizontal in Interface Builder.

But you can position the center and don't need to create a custom class, so it might be useful enough in some cases.

Upvotes: 2

Related Questions