Obtains the auxiliary function that completely displays the maximum font of the specified text within the specified size range.
The function is defined as follows:
-(INT) getfontsizeforstring :( STD: string) strtext maxfontsize :( INT) maxfontsize forsize :( cgsize) size;
The strtext parameter is the text to be displayed, and maxfontsize is the initial font size. Size is the area range of the text to be displayed. The return value is the most appropriate font number. If the maxfontsize font size cannot fully display the specified text within the specified size range, the Helper function tests the font smaller than this one until it finds the font that can display all the text.
The default font of the auxiliary function isIn fact, the Helvetica font can be improved by specifying the font as a parameter. The font will not be modified, and it will become lazy.
Function implementation:
-(INT) getfontsizeforstring :( STD: string) strtext maxfontsize :( INT) maxfontsize forsize :( cgsize) size {int fontsize = maxfontsize; bool bcontinue = true; while (bcontinue & fontsize> 0) {cgsize showtipssize; uifont * newfont = [uifont fontwithname: @ "Helvetica" Size: fontsize]; nsstring * nstext = [nsstring comment: strtext. c_str () encoding: nsutf8stringencoding]; cgsize originsize; originsize. height = size. height; originsize. width = 10000; showtipssize = [nstext sizewithfont: newfont constrainedtosize: originsize linebreakmode: uilinebreakmodewordwrap]; If (showtipssize. width + 5 <= size. width) {bcontinue = false;} else {fontsize = fontSize-1;} return fontsize ;}