objective c - NSPopButton with list of font families -
how can create nspopupbutton list of font families each item in own font shown in attached screenshot. want use bindings achieve this.
i able populate nspopupbutton binding nspopupbutton content value returned [[nsfontmanager sharedfontmanager] availablefontfamilies]
can't figure out how each individual row in own font?
i wasn't sure it, following appears work.
// fontpopup1 instance of nspopupmenu nsmenu *menu = [[nsmenu alloc] init]; nsarray *familynames = [[nsfontmanager sharedfontmanager] availablefontfamilies]; nsmutablearray *fontarray = [[nsmutablearray alloc] initwithobjects:nil]; (nsstring *family in familynames) { [fontarray addobject:family]; } (nsinteger i2 = 0; i2 < fontarray.count; i2++) { nsstring *family = [fontarray objectatindex:i2]; nsmutableattributedstring *attrstr =[[nsmutableattributedstring alloc]initwithstring:family]; cgfloat fontsize = [nsfont systemfontsize]; [attrstr addattribute:nsfontattributename value:[nsfont fontwithname:family size:fontsize] range:nsmakerange(0,family.length)]; nsmenuitem *menuitem = [[nsmenuitem alloc] init]; [menuitem setattributedtitle:attrstr]; [menu additem:menuitem]; } [fontpopup1 setmenu:menu];
Comments
Post a Comment