Bao Nguyen
Bao Nguyen

Reputation: 137

How to make NSSlider be vertical programmatically?

I write a Mac app and create some NSSlider programmatically. The default NSSlider's orientation is horizontal. How can I make NSSlider be vertical?

Upvotes: 1

Views: 650

Answers (1)

JorisH
JorisH

Reputation: 428

Objective C

I did it by using this:

self.yourSlider.frameRotation = 90.0;
CGRect frame = self.yourSlider.frame;
float tmp = frame.size.height;
frame.size.height = frame.size.width;
frame.size.width = tmp;
[self.yourSlider setFrame:frame];
[self.yourSlider setWantsLayer:TRUE];

Swift

And I guess the Swift version will be:

self.yourSlider.frameRotation = 90.0
var frame: CGRect = self.yourSlider.frame
var tmp: Float = frame.size.height
frame.size.height = frame.size.width
frame.size.width = tmp
self.yourSlider.frame = frame
self.yourSlider.setWantsLayer(TRUE)

Upvotes: 1

Related Questions