I wonder if it's possible to show live fonts in a popupbutton control (NSPopupButton)? currently, I load a popupbutton with a list of fonts available in the following manner.
NSArray *familyNames = [[NSFontManager sharedFontManager] availableFontFamilies];
NSMutableArray *fontarray = [[NSMutableArray alloc] initWithObjects:nil];
[fontarray addObject:@"- Select one - "];
for (NSString *family in familyNames) {
[fontarray addObject:family];
}
[fontmenu1p addItemsWithTitles:fontarray];
Maybe, something like the following, using NSMutableAttributedString?
for (NSString *family in familyNames) {
NSDictionary *attr1 = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:family size:[NSFont systemFontSize]],NSFontAttributeName,[NSColor blackColor],NSForegroundColorAttributeName,nil];
NSMutableAttributedString *aString = [[NSMutableAttributedString alloc] initWithString:family];
[aString setAttributes:attr1 range:NSMakeRange(0,family.length-1)];
[fontarray addObject:aString];
}
[fontmenu1p addItemsWithTitles:fontarray];
I get an out of bounds error. I don't know if my approach is right. I don't even know if the popupbutton control supports styled text.
Thank you for your help.