There has been some discussion recently in regards to whether or not one can 
use Voiceover with Interface builder.  I'm not sure that this list is the most 
appropriate place for discussing this, but I feel that there have been some 
inaccurate assertions made and I wanted to attempt to clear up a few points for 
the sate of those who are programmers on this list and are interested in 
learning about developing apps with XCode.

As the subject implies, I am using the tutorial found at 
https://developer.apple.com/library/mac/#referencelibrary/GettingStarted/RoadMapOSX/books/RM_YourFirstApp_Mac/Articles/GettingStarted.html#//apple_ref/doc/uid/TP40012262-TP40012101-CH2-SW8.
I realize the IOS is the hottest thing, but I think that this example is a 
little cleaner for the purpose of explaining this.  It works the same for the 
most part for an IOS app and I will point out the most important differences at 
the end.  I'm also only going to go over laying out the window and referencing 
the objects in the xib in your code.  The tutorial explains how to create a 
project etc.

Make sure that the xib is opened in the source area and that the utilities are 
visible with command-option-0.

First, add the controls to the windows content view:
1.  With the mainmenu.xib file opened in the source group, make sure the 
document outline is visible.  You should see a table with all of the objects in 
the xib.
2.  Find the window object in the table and expand it to expose the content 
view.
3.  Move vo to the library group, interact, and select the object library radio 
button.
4.  Find text field, with vo, rout the mouse to vo, and lock the mouse.
5.  Move vo to the windows content view in the outline, then release the mouse. 
 Now the content view should contain the textfield. (Note that this can be 
glitchy sometimes and you might have to try it again but not very often.)
6.  Repeat for the slider and button.

Designing the layout:

I'm going to arrange the controls in a column centered in the window and left 
justified with the button close to the bottom of the window.  

1.  Select the content view and go to the size inspector.  Git the width and 
height.  I have 480 by 360
2.  In the xib, select the text field and.  In the size inspector, make sure 
layout rectangle is selected and select the origin to be the top left corner.
3.  In the origin section, type 20 in the x field and 340 for the y value.  
Then stretch it across the window until the right side is 20 points from the 
right edge by selecting the origin in the top left corner and typing a value of 
440 in the width field.  Note that you could also resize the window to fit the 
text field, but this is more simple.
4.  Change the origin to the bottom left corner and get the y value.  I have 
318.
5.  Select the slider and in the size inspector, set the origin to top left, 
set the x origin to 20 and the y to 308.  That positions the slider 20 points 
from the left edge of the window and 10 points below the textfield.
6.  With the button selected, set the origin to bottom left, set x origin to 20 
and the y origin to 20.

You can build an run at this point, but you can also check your work with out 
even running the app by choosing "simulate document in the editor menu.  Cocoa 
simulator will open and you should be able to move vo up and down through the 
lined up controls.

Create actions and outlets:
1.  Select the AppDelegate object in the outline and open the assistant editor. 
 In the source pain, you should now see the appdelegate.h file opened next to 
the xib.
2.  Select the button in the xib file and in the connections inspector, find 
the sent actions list.
3.  The only item at this point in the list is selector.  Move vo to the 
unknown item directly to the right of it and drag from it to the area in the 
header file between the @interface and @end directives.
4.  When you release the mouse at this point, a connections dialog will come up 
where you will type the name of the action..  Type mute then press ok.  In the 
header file, you will now see the definition of the action.  - 
(IBAction)mute:(id)sender;
5.  Select the text field in the outline and in the connections inspector, find 
the referencing outlets list.
6.  drag from the unknown thing next to "new referencing outlet" to a blank 
area in the class declaration in the header file.  In the connection dialog 
type textField in the name.
7.  Repeat for the slider.

When you are done, you will see the following objective c property definitions:
@property (weak) IBOutlet NSTextField* textField;
@property (weak) IBOutlet NSSlider* slider;

And that is all there is to it.
One difference I want to point out between UIKit and AppKit is that the origin 
in UIKit is in the top left corner of the screen and the y values grow 
downward.  So to place a control in the top left corner of a view, the origin 
in the top left corner of a content view would be 20x20.

This is a lot harder to right about than it is to do.  I hope I explained it 
well enough that someone gets something out of it.  However, this wont help 
anyone who doesn't know how to program in Objective C.





--
                Barry Hadder
bhad...@gmail.com
https://twitter.com/BarryHadder
UnitMaster
Available in the Mac app store.




-- 
You received this message because you are subscribed to the Google Groups 
"MacVisionaries" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to macvisionaries+unsubscr...@googlegroups.com.
To post to this group, send email to macvisionaries@googlegroups.com.
Visit this group at http://groups.google.com/group/macvisionaries.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to