NSTextField vertical alignment
NSTextField vertical alignment
- Subject: NSTextField vertical alignment
- From: Ricky Sharp <email@hidden>
- Date: Thu, 29 Jul 2004 21:44:50 -0500
I'm programatically creating an NSTextField to be horizontally centered
within a window:
NSTextField* textField = [[NSTextField alloc] initWithFrame:someBounds];
// where someBounds has a height of 40.0
[self addSubview:textField];
[textField setEditable:NO];
[textField setSelectable:NO];
[textField setDrawsBackground:NO];
[textField setBezeled:NO];
[textField setBordered:NO];
[textField setAlignment:NSCenterTextAlignment];
[textField setStringValue:@"some message"];
NSMutableAttributedString* attributedString =
[[NSMutableAttributedString alloc]
initWithAttributedString:[textField attributedStringValue]];
[attributedString addAttribute:NSFontAttributeName
value:[NSFont boldSystemFontOfSize:24.0]
range:NSMakeRange (0, [attributedString length])]; // [ 1 ]
[textField setAttributedStringValue:attributedString];
When executed, the text has its top being cut off. It appears as if
the original baseline is being used (by default the font is 12 point).
However, if I place the following after [ 1 ] above:
[attributedString addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-12.0]
range:NSMakeRange (0, [attributedString length])];
then the text is vertically centered and not cut off.
Is one supposed to manually adjust the baseline after setting the font?
Note that this is not the best method of setting the font as there is a
setFont: on NSControl that I can use. When I use setFont:, the
baseline is modified appropriately.
Shall I file a bug on this?
___________________________________________________________
Ricky A. Sharp
mailto:email@hidden
Instant Interactive(tm)
http://www.instantinteractive.com
_______________________________________________
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.