Search code examples
cocoaosx-elcapitannsprogressindicator

How to rotate NSProgressIndicator by 90 deg


I need to rotate NSProgressIndicator by 90 deg. enter image description here

When I use the following code:

[self.progressIndicator1 setWantsLayer:NO];
[self.progressIndicator1 setFrameCenterRotation:90];
[self.progressIndicator1 setMinValue:0];
[self.progressIndicator1 setMaxValue:100];
[self.progressIndicator1 setDoubleValue:50];
[self.progressIndicator1 displayIfNeeded];

[self.progressIndicator2 setWantsLayer:NO];
[self.progressIndicator2 setFrameCenterRotation:90];
[self.progressIndicator2 displayIfNeeded];

I get inappropriate result: enter image description here

This code works fine on OS X Yosemite, but not works on OS X El Capitan.

How I can fix it?


Solution

  • if your progress indicators are contained in a view then if you can allow the wantsLayer for that view your code will work.

    self.view.wantsLayer = YES;
    self.progressBar1.doubleValue = 60.0;
    self.progressBar2.doubleValue = 60.0;
    
    [self.progressBar1 setWantsLayer:NO];
    [self.progressBar1 setFrameCenterRotation:90];
    
    [self.progressBar2 setWantsLayer:NO];
    [self.progressBar2 setFrameCenterRotation:90];
    [self.progressBar2 displayIfNeeded];
    

    this worked for me on El Capitan.