0

ALL,

I am trying to learn Cocoa programming and am stumbled on the following:

It seems that every resource including SO says that in order to use labels with NSSlider one needs to create those labels as a child of the panel/dialog/Main Window where the actual NSSlider is created.

So that it goes like this:

dialog->NSSlider
  |
  |----> label

However it means that I will have to manage everything by hand.

Now what I have in mind is to make the labels as children of the NSSlider, so that it will be:

dialog->NSSlider
          |
          |------>label

Is it a good idea to do it like this? Is it in line with the Cocoa/Apple guidelines? Or I am completely off here ?

If it's a good idea I'd appreciate some code on how to make it work.

Thank you.

Igor
  • 5,620
  • 11
  • 51
  • 103

1 Answers1

0

Subclass NSControl and have it's initializer create & manage the NSSlider & NSTextField (as subviews). Override the setTarget & setAction methods to call thru to the NSSlider. Add a setLabel (or label properties) method to set the NSTextField's string value, etc.

geowar
  • 4,397
  • 1
  • 28
  • 24
  • I am more interested in proper positioning of the labels. When they are children of the dialog, everything is easy. But when they children of the slider... Is there a way to set a z-order or somehow position the labels so that they will be visible? Can you post some code? Thx. – Igor Jul 15 '15 at 10:46
  • When you subclass NSControl (MyLabeledSlider?) you can (auto-)layout the NSSlider & NSTextField in a nib (xib) (as subviews). – geowar Jul 17 '15 at 14:43
  • @geovar, What is nib(xib)? Can you post some simple Cocoa code to look at? The one that compatible with at least 10.7+. Thank you. – Igor Jul 18 '15 at 15:00
  • A nib file is a special type of resource file that you use to store the user interfaces of iOS and Mac apps. You use Xcode to design the visual parts of your app—such as windows and views—and sometimes to configure non visual objects, such as the controller objects that your app uses to manage its windows and views. Originally nibs were stored as binary data; an xib is a nib stored in XML format. – geowar Jul 20 '15 at 14:25
  • As you can see I am not using any RAD tool. That's why I'm asking for some code to use... Could you please post some Cocoa code which I can use? It would also be nice if you place some comments there as I am just tryng to learn Cocoa.... – Igor Jul 21 '15 at 15:05