cocoa touch - Autosize Text in Label for PaintCode CGContext -


i'm using following draw text inside bezier path. how can adjust allow text autosize.

edit

i able update ios7 methods still nothing. can autosize text within uilabel fine, because cgcontext harder

        nsstring* textcontent = @"location";          nsmutableparagraphstyle* locationstyle = nsmutableparagraphstyle.defaultparagraphstyle.mutablecopy;         locationstyle.alignment = nstextalignmentcenter;          nsdictionary* locationfontattributes = @{nsfontattributename: [uifont fontwithname:myfont size: 19], nsforegroundcolorattributename: locationcolor, nsparagraphstyleattributename: locationstyle};         cgfloat locationtextheight = [textcontent boundingrectwithsize: cgsizemake(locationrect.size.width, infinity)  options: nsstringdrawinguseslinefragmentorigin attributes: locationfontattributes context: nil].size.height;         cgcontextsavegstate(context);         cgcontextcliptorect(context, locationrect);         [textcontent drawinrect: cgrectmake(cgrectgetminx(locationrect), cgrectgetminy(locationrect) + (cgrectgetheight(locationrect) - locationtextheight) / 2, cgrectgetwidth(locationrect), locationtextheight) withattributes: locationfontattributes];         cgcontextrestoregstate(context); 

try using method of nsattributedstring:

- (cgrect)boundingrectwithsize:(cgsize)size                        options:(nsstringdrawingoptions)options                        context:(nsstringdrawingcontext *)context; 

where context provide actualscalefactor.

the usage this:

nsattributedstring *string = ...; nsstringdrawingcontext *context = [nsstringdrawingcontext new]; context.minimumscalefactor = 0.5; // set minimum value.  cgrect bounds = [string boundingrectwithsize:maxsize                                      options:nsstringdrawinguseslinefragmentorigin                                      context:context]; cgfloat scale = context. actualscalefactor; // use scale multiply font sizes in string, fit. 

Popular posts from this blog