NSMutableAttributedString sets the font size

Every resource that I use for this is for iOS. I can't seem to work fine for Mac OSX. Any idea how to do this to set the font size? Currently, it correctly sets the alignment of color and center. Thanks

NSMutableAttributedString *libTitle = [[NSMutableAttributedString alloc] initWithString:@"Library"]; [libTitle addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0,[@"Library" length] ) ]; [libTitle setAlignment:NSCenterTextAlignment range:NSMakeRange(0, [@"Library" length])]; [libTitle addAttribute:NSFontSizeAttribute value:[NSFont systemFontOfSize:18.0] range:NSMakeRange(0, [@"Library" length])]; [self.libbtn setAttributedTitle:libTitle]; 
+6
source share
1 answer

Try setting the font attributes from the get method in the init method:

 NSFont *systemFont = [NSFont systemFontOfSize:18.0f]; NSDictionary * fontAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:systemFont, NSFontAttributeName, nil]; NSMutableAttributedString *libTitle = [[NSMutableAttributedString alloc] initWithString:@"Library" attributes:fontAttributes]; NSRange rangeOfTitle = NSMakeRange(0,[libTitle length]); [libTitle addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:rangeOfTitle]; [libTitle setAlignment:NSCenterTextAlignment range:rangeOfTitle]; [self.libbtn setAttributedTitle:libTitle]; 
+11
source

All Articles