fonts - objective c finding pixel width of a string -
i have uibutton of fixed width , want place text in it. since size of string unknown in advance, have resize font read string flat file. how can that? function similar following great:
uifont resizefontas:(uifont)initialfont andstringas:(nsstring*)string andwidthas:(int)width
thanks in advance
edit : code doesnt seem work:
// method creating button, background image , other properties - (uibutton *) getcallagentbuttonwithtitleas:(nsstring *)atitle andimageas:(uiimage*)bgimg atindex:(int)index{ uibutton *abutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; abutton.frame = cgrectmake(10, 2+index*50, 300, 48); abutton.titlelabel.frame = cgrectmake(abutton.titlelabel.frame.origin.x + 25.0, abutton.titlelabel.frame.origin.y, abutton.titlelabel.frame.size.width - 50.0, abutton.titlelabel.frame.size.height); abutton.titlelabel.adjustsfontsizetofitwidth = yes; [abutton settitle:atitle forstate:uicontrolstatenormal]; //abutton.titlelabel.font = [uifont boldsystemfontofsize:12]; [abutton settitlecolor:uicolorfromrgb(0xfdd428) forstate:uicontrolstatenormal]; [abutton setbackgroundimage:bgimg forstate:uicontrolstatenormal]; [abutton addtarget:self action:@selector(callagent:) forcontrolevents:uicontroleventtouchupinside]; // set tag index , use later obtain phoneno [abutton settag:index]; return abutton; }
you can tell button's label resize font itself.
mybutton.titlelabel.adjustsfontsizetofitwidth = yes; mybutton.titlelabel.minimumfontsize = 6.0; // pick own value here.
Comments
Post a Comment