Created
February 26, 2012 12:15
-
-
Save TomLiu/1916376 to your computer and use it in GitHub Desktop.
Cocoa label with underline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(0, 0, 320, 25)]; | |
[label setEditable:NO]; | |
[label setBordered:NO]; | |
[label setFont:[NSFont systemFontOfSize:17.0]]; | |
[label setBackgroundColor:[NSColor clearColor]]; | |
[label setTextColor:[NSColor blackColor]; | |
[label.cell setLineBreakMode:NSLineBreakByTruncatingTail]; | |
[label setAutoresizingMask:NSViewMaxXMargin|NSViewMaxYMargin|NSViewWidthSizable]; | |
NSFont *font = [NSFont systemFontOfSize:14.0]; | |
NSNumber *underLineStyle = [NSNumber numberWithInt:NSUnderlineStyleSingle]; | |
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:underLineStyle,font,[NSColor redColor], nil] | |
forKeys:[NSArray arrayWithObjects:NSUnderlineStyleAttributeName,NSFontAttributeName,NSForegroundColorAttributeName, nil]]; | |
NSAttributedString *attrsString = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"Details and Edit", @"") attributes:attrsDictionary]; | |
[label setAttributedStringValue:attrsString]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment