Re: Newbie NSView confusion
Re: Newbie NSView confusion
- Subject: Re: Newbie NSView confusion
- From: Sailor Quasar <email@hidden>
- Date: Sat, 4 Oct 2003 19:35:22 -0400
On Saturday, October 4, 2003, at 02:49 PM, Cameron Hayne wrote:
Which attribute am I forgetting to set, what
magical incantation do I have to invoke?
Perhaps if you create a nib file using IB and then look at it using
'nibtool
-a' you will see what attribute you are missing.
nibtool is an excellent tool for nib file inspection, but unfortunately
in this case it didn't tell me anything.
After some doodling, fiddling, and invocations to the Gods of
Programming, I finally found that I had two problems:
1) I had a two-pixel misalignment in my subview rectangles which was
throwing off the alignments of other subviews.
2) I was using [NSFont systemFontOfSize:[NSFont systemFontSize]] to set
the font of the subview. Turns out that, and this is NOT reflected in
nibtool's output, to mimic IB's behavior I have to instead use [NSFont
boldSystemFontOfSize:[NSFont systemFontSize]]. This seems a bit
counterintuitive to me, but what do I know...
On Saturday, October 4, 2003, at 07:02 PM, publiclook wrote:
<begin short rant>
This is one of those times when Carbon would have been simpler. In
Carbon the call to create such a text field would have required at
most two lines for CreateStaticTextControl() and would have worked on
the first shot. Here in Cocoa I'm playing with attributes of a
over-generalized text view subclass like mad and getting more or less
nowhere.
</end short rant>
<begin short rant reply>
It often seems simpler to do almost anything with a familiar framework
than with an unfamiliar framework particularly when the basic
paradigms are different between the two frameworks.
</end short rant reply>
I freely admit that =).
If all you want to do is draw un-editable '.' characters at arbitrary
positions within a view, adding sub-views is almost certainly overkill
whether the sub view is an NSTextView or and NSTextField. See the
various text drawing APIs at different levels of the frameworks. See
http://www.cocoaprogramming.net/Downloads.html for many examples of
how to draw formatted text in a custom view. Even if you want to use
sub-views for this purpose, it may be easier to set up a prototypical
view the way you want it in IB and then programatically copy the
prototype instance as many times as you want adding each copy as a
sub-view of your custom view. You seem to already know how to add
sub-views. You can copy an arbitrary graph of objects using code as
shown in the following:
copyOfSomeView = [NSUnarchiver
unarchiveObjectWithData:[NSArchiver
archivedDataWithRootObject:someView];
The copy will include all nested sub-views in someView etc.
This is an excellent point, but it's ultimately _more_ complicated than
the setup I have now. I started doing this particular custom view as a
convenience for not having to set up and align the same eight or nine
views in different nibs five times over. That and for the practice,
because yes I am aware that there are such things as an NSMatrix and
the group, make subview of custom view, copy/paste, and duplicate
commands in IB :). (Ok, and because the custom view provides methods
for getting and setting the value of several editable text fields at
once as a single conglomerate input/output). It's worth pointing out
that the view as implemented with subviews doesn't even have a
-drawRect method; it doesn't need it.
Of course, having done the view and been using an IB Palette for
testing it out (running the view in IB's test mode is sufficient to
test all the features I need except for the convenience methods, and
since I'm working with the internal layout for now...), I have found IB
Palettes to be maddeningly undocoumented and annoying. There seem to be
a host of things IB can do with classes it knows about but provides no
API or documentation for applying to custom classes, such as view size
constraints, the ability to descend into subviews, and providing an
Inspector for custom classes that aren't views.
-- Sailor Quasar, just another player in The World
"Come with me in the twilight of the summer night for awhile"
Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.