Re: Button title irregularities
Re: Button title irregularities
- Subject: Re: Button title irregularities
- From: Aki Inoue <email@hidden>
- Date: Tue, 2 Dec 2008 16:31:37 -0800
You're using Helveitca 12.0 as your label font.
Use [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:
[yourButton controlSize]]] instead.
Aki
On 2008/12/02, at 13:39, Randall Meadows wrote:
I am porting an iPhone app to the Mac, and the client desires the
exact same look-and-feel on the Mac as they have on the iPhone. So
I am doing some custom drawing to achieve that. It's mostly going
OK, but I've found myself wasting far too much time on this one
little detail, and it's killing me...
I'm drawing a button with a custom background, and setting an
attributed title on it. There is no border, custom background image
for both normal and alternate states, and a title for both normal
and alternate states.
When I set an attributed title on it, using a custom font, custom
paragraph style (necessary to center the title), and a custom color,
the text of the title is shifted down 1 pixel when compared to the
standard button. Thinking that that 1 pixel difference was due to
the different font, I tried again, setting an attributed title that
*only* contain the custom color.
This time, the title was shifted UP 1 pixel from that of a standard
button (2 pixels higher than with the fully attributed title). I
tried playing around with the line spacing of the paragraph style,
but that made no difference.
You can see for yourself in this image: <http://www.not-pc.com/Buttons.png
>. (The custom background was not drawn and the border was added to
make it easier to see.) Here's the code I'm using to create the
button:
button = [NSButton new];
[button setButtonType:NSToggleButton];
[button setBezelStyle:NSRegularSquareBezelStyle/
*NSRoundRectBezelStyle*/];
//[button setBordered:NO];
NSDictionary *attrs;
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
[style setAlignment:NSCenterTextAlignment];
[style setLineSpacing:10];
attrs = [NSDictionary dictionaryWithObjectsAndKeys:
// labelFont, NSFontAttributeName,
[NSColor blackColor], NSForegroundColorAttributeName,
// style, NSParagraphStyleAttributeName,
nil];
[button setAttributedTitle:@"Show" attributes:attrs];
Is there anything standard I can do to "fix" this? Yeah, I know 1
pixel isn't that much of a difference, but that's like a 5% error,
and it's noticeable.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden