How to change the height of an NSProgressIndicator? - cocoa

By default, cocoa progress bars are slightly fat and I want something a little slimmer, like the progress bars seen in the Finder copy dialog. However, Interface Builder locks the NSProgressIndicator control height to 20 pixels and my programmatic attempts to slim down aren't working, as calls to
[progressBar setControlSize:NSMiniControlSize];
and
[progressBar setControlSize:NSSmallControlSize];
in awakeFromNib don't do anything, and the suggestive looking NSProgressIndicatorThickness seen in the header file doesn't seem to plug into any methods that I can see.
What's the trick?

Those calls should have worked. In Interface Builder, in the Geometry pane (the one whose icon is a ruler), there is an equivalent control size selector that offers "Regular" and "Small" sizes.

in IB
select your NSProgressIndicator control
in the utilities view select the View Effects inspector
press + in Content Filters
select Lanczos Scale Transform filter
set the appropriate scale value in the Scale row
set the Aspect Ratio too if you need to change the height only

Related

How do I make a WrappingTextField fill the entire Window?

I have a Window and a WrappingTextField.
I want the WrappingTextField to always fill the entire Window. Even when the user is resizing the Window, and when it is in full screen.
No matter which options or constraints I choose in Auto Layout, it only resizes with the Window horizontally, but its height remains the same, even if the height of the Window grows.
How do I make it fill the entire Window, and stay that way?
By WrappingTextField I'm assuming you mean an a standard NSTextField object with it's Layout set to Wraps within Interface Builder.
The resizing behaviour of an NSTextField is influenced by its Content Hugging Priority. By default Interface Builder sets this at 750 for the control's Vertical dimension, and this is probably what's preventing your text field from resizing the way you want it to. Give it a smaller value - like say 100 - and the problem should resolve.

Can't change height of NSTextField in Interface Builder

When I do something simple, like add a Wrapping Text Field in Interface builder (drag and drop method), I find that I'm unable to size the object as I would like using the mouse pointer.
For example, once I've placed this Wrapping Text Field into the upper left hand corner of my Document, I can't adjust the height of the object by dragging down on the bottom-middle sizing tool.
This happens all the time when sizing different objects in Interface Builder, it's really frustrating! The only workaround seems to be to open the Size Inspector and to manually adjust the height of the object by increasing the value.
What am I doing wrong? Is it because the object clamps to the top-left corner of the Document when I place it there? I'm not adding any constraints, merely dragging and dropping elements onto the Document in the xib.
I'm using Xcode Version 5.1.1 (5B1008) on OS X 10.9.2 (13C1021)
OK so after a bit of playing around in Interface Builder, I've noticed that I can switch off the "Use Auto Layout" feature in the File Inspector. Now when I switch to the Sizing Inspector I have an easy to use "Auto Sizing" feature that when I hover over the preview, shows me exactly how the NSTextField will size when re-sizing the parent document.
Also once I've switched off "Use Auto Layout", I can use the mouse pointer to adjust the NSTextField height and width in the Interface Builder.
I guess the "Use Auto Layout" is constraining the height of the NSTextField to the appropriate height it thinks it should be but I can't tell where it get's this value from.

Can't Edit NSWindow's Toolbar - Cocoa

So I'm using the method:
[someWindow setContentBorderThickness:24.0 forEdge:NSMaxYEdge];
But I can't seem to get the toolbar to increase in height. It simply stays the same as in default. Can anyone shed some light here?
An NSToolbar is automatically resized to accommodate the height of the tallest NSToolbarItem. The standard (large) toolbar items are all 32 px tall, so the toolbar has no need to make itself larger. If you do something like add a custom view toolbar item, then it will be resized to accommodate that item, as shown in the image below:
(To accomplish the result shown above, I clicked on the toolbar twice in IB to bring down the Allowed Toolbar Items sheet, then dragged an NSView custom view from the library palette onto that sheet).
P.S. I'd recommend using this capability with discretion.
You cannot specify an arbitrary height for NSToolbar. You can, however, specify a size mode. A toolbar with 24x24-pixel icons has a small size mode:
[toolbar setSizeMode: NSToolbarSizeModeSmall];
which is equivalent to Size: Small in Interface Builder’s Attributes Inspector.

How to implement browser toolbar in Cocoa?

It seems like the best approach is to use NSToolbar. However, it is not obvious to me how to make an NSTextField within an NSToolbar flexible in terms of width. Is this possible? The default behavior of the textfield is to remain a constant width, even if the toolbar is resized.
Make sure you set maxSize and minSize correctly on the toolbar item, and then set the autoresize mask on the text field itself. You control the sizing of a view in a toolbar just as if it was in a window, either make sure its width is flexible in IB if you're creating it there, or specify NSViewWidthSizable if you're creating it in code.

make NSRect selectable

Is there a simple way to create a selectable NSRect in Cocoa? In need a rectangle that can be selected and stays selected after a mouse click.
Thanks.
NSRect is just a struct with a position and size. It's not an object that can actually do anything or have any properties other than a width and height. It sounds like what you want is to create an NSView that can be selected. (Here's Apple's Guide on the subject.)
Though not as immediate as you would like, you may be interested in the management of tracking rectangles and tracking areas performed by NSView class.
This mechanism allows you to define specific areas of your custom view. Then, an event is generated whenever the cursor enters or leaves the area, or a mouse button is pressed in this area (-mouseEntered:, -mouseExited:, -mouseDown:, -mouseUp:, -mouseDragged:, ... of NSResponder class). This up to you to define what you want your application do in response to these events (set the rectangle as selected and display it accordingly).
For an example implementation of this, take a look at the Sketch example included with the Apple developer tools (look in /Developer/Examples/AppKit). Sketch allows the user to create new graphics (including rectangles, but also ovals, lines, and text), select them, move them around in the document, etc. In particular, you'll probably want to look at the SKTGraphic class, which represents a single graphic object in the document, and the SKTGraphicView class, which is an NSView subclass that perform the actual layout and drawing, handling mouse events for dragging views around, etc.

Resources