Creating a NSSlider User Based on the QuickTIme X Trim User Interface

http://f.cl.ly/items/350X3c0h0A0k3s3f1R1h/Screen%20Shot%202012-03-27%20at%202.53.41%20PM.png

I am working on an application that will allow the user to select a time range in a piece of audio for OS X. Most of the search I did was get an interface similar to the aforementioned trim interface, from QuickTime X unfortunately there were a lot of iOS related APIs .

My first instinct is that it is a highly customizable NSSlider . Is there a general direction I should take when trying to create this? NSSlider best route? Any pointers, hints or code would be greatly appreciated.

EDIT: There was a good comment about this, perhaps as a custom control. Any advice on this would be greatly appreciated!

+4
source share
1 answer

Create a custom control. Here is what I do for my custom controls:

Interface first:

 @interface AS_CustomControl : NSControl <NSCoding> { } @end 

Then implementation:

 @implementation AS_CustomControl -(id)initWithFrame:(NSRect)rect { if (self = [super initWithFrame:rect]) { [self initCustomControl]; } return self; } -(id)initWithCoder:(NSCoder*)coder { if (self = [super initWithCoder:coder]) { [self initCustomControl]; } return self; } -(void)initCustomControl { // put any custom initialization here // such as default variable state } -(void)dealloc { [super dealloc]; } -(void)encodeWithCoder:(NSCoder*)coder { [super encodeWithCoder:coder]; } +(Class)cellClass { return [NSActionCell class]; } @end 

The cellClass method ensures that your user control will trigger action messages when the user interacts with it.

Now this should be the case of drawing the waveform in drawRect: and redefining the messages mouseDown: mouseDragged: and mouseUp: to handle the range selection.

+1
source

Source: https://habr.com/ru/post/1403761/


All Articles