- Inherits from:
- NSView : NSResponder : NSObject
- Conforms to:
- NSCoding
- (NSResponder)
- NSObject (NSObject)
Declared in:
- AppKit/NSBox.h
An NSBox object is a simple NSView that can do two things: It can draw a border around itself, and it can title itself. You can use an NSBox to group, visually, some number of other NSViews. These other NSViews are added to the NSBox through the typical subview-adding methods, such as addSubview: and replaceSubview:with:.
An NSBox contains a content area, a rectangle set within the NSBox's frame in which the NSBox's subviews are displayed. The size and location of the content area depends on the NSBox's border type, title location, the size of the font used to draw the title, and an additional measure that you can set through the setContentViewMargins: method. When you create an NSBox, an instance of NSView is created and added (as a subview of the NSBox object) to fill the NSBox's content area. If you replace this content view with an NSView of your own, your NSView will be resized to fit the content area. Similarly, as you resize an NSBox its content view is automatically resized to fill the content area.
The NSViews you add as subviews to an NSBox are actually added to the NSBox's content view-NSView's subview-adding methods are redefined by NSBox to ensure that a subview is correctly placed in the view hierarchy. However, you should note that the subviews method isn't redefined: It returns an NSArray containing a single object, the NSBox's content view.
- Getting and modifying the border and title
- - borderRect
- - borderType
- - setBorderType:
- - setTitle:
- - setTitleFont:
- - setTitlePosition:
- - setTitleWithMnemonic:
- - title
- - titleCell
- - titleFont
- - titlePosition
- - titleRect
- Setting and placing the content view
- - contentView
- - contentViewMargins
- - setContentView:
- - setContentViewMargins:
- Resizing the box
- - setFrameFromContentFrame:
- - sizeToFit
- (NSRect)borderRect
- (NSBorderType)borderType
NSView.h
. Currently,
the following border types are defined:NSNoBorder
NSLineBorder
NSBezelBorder
NSGrooveBorder
By
default, an NSBox's border type is NSGrooveBorder
.
- (id)contentView
- (NSSize)contentViewMargins
- (void)setBorderType:(NSBorderType)aType
NSView.h
. Currently,
the following border types are defined:NSNoBorder
NSLineBorder
NSBezelBorder
NSGrooveBorder
If the size of the new border is different from that of the old border, the content view is resized to absorb the difference and the box is marked for redisplay.
See Also: - setNeedsDisplay: (NSView)
- (void)setContentView:(NSView
*)aView
See Also: - setFrameFromContentFrame:, - sizeToFit, - setNeedsDisplay: (NSView)
- (void)setContentViewMargins:(NSSize)offsetSize
Unlike changing a box's other attributes, such as its title position or border type, changing the offsets doesn't automatically resize the content view. In general, you should send a sizeToFit message to the box after changing the size of its offsets. This causes the content view to remain unchanged while the box is sized to fit around it.
- (void)setFrameFromContentFrame:(NSRect)contentFrame
See Also: - setContentViewMargins:, - setFrame: (NSView), - setNeedsDisplay: (NSView)
- (void)setTitle:(NSString
*)aString
See Also: - titleRect, - setNeedsDisplayInRect: (NSView)
- (void)setTitleFont:(NSFont
*)aFont
See Also: - setNeedsDisplayInRect: (NSView)
- (void)setTitlePosition:(NSTitlePosition)aPosition
NSAtTop
.Value | Meaning |
NSNoTitle |
The box has no title |
NSAboveTop |
Title positioned above the box's top border |
NSAtTop |
Title positioned within the box's top border |
NSBelowTop |
Title positioned below the box's top border |
NSAboveBottom |
Title positioned above the box's bottom border |
NSAtBottom |
Title positioned within the box's bottom border |
NSBelowBottom |
Title positioned below the box's bottom border |
If the new title position changes the size of the box's border area, the content view is resized to absorb the difference, and the box is marked as needing redisplay.
See Also: - setNeedsDisplay: (NSView)
- (void)setTitleWithMnemonic:(NSString
*)aString
By default, an NSBox's title is "Title". The content view is not automatically resized, and the box is not marked for redisplay.
See Also: - setTitleWithMnemonic: (NSCell)
- (void)sizeToFit
You should invoke this method after:
The mechanism by which the content view is moved and resized depends on whether the object responds to its own sizeToFit message: If it does respond, then that message is sent and the content view is expected to be so modified. If the content view doesn't respond, the box moves and resizes the content view itself.
- (NSString *)title
- (id)titleCell
- (NSFont *)titleFont
- (NSTitlePosition)titlePosition
- (NSRect)titleRect
See Also: - setTitlePosition:, - setTitle:, - setTitleFont:, - setFrameFromContentFrame:, - sizeToFit