ios - Correct syntax for replacement of deprecated "sizeWithFont:constrainedToSize:lineBreakMode" -
ios - Correct syntax for replacement of deprecated "sizeWithFont:constrainedToSize:lineBreakMode" -
i have had 10 days of ios/objective-c training (and pretty much no other coding classes) , way out of league on this, inherited huge ios app @ work responsible upgrading ios6-centric ios 7-centric. i'm trying clean of warnings in xcode , cannot figure 1 out. i've searched days , read every reply here on so, none answers question (though have helped me closer, grateful).
i know "sizewithfont:constrainedtosize:linebreakmode:" deprecated , needs replaced "boundingrectwithsize:options:attributes:context:", life of me can't figure out how convert existing code old method new. if can 1 straightened out clear 35 other warnings in xcode, same deprecated method used in numerous other places.
the research i've done yields few examples of how new method used, appears used in different ways (cgrect , cgsize) , apple's documentation sends me in "one infinite loop". "options:", apple says utilize paragraph style options, yet different available deprecated style (half of deprecated, too). example, if don't specify style, utilize default paragraph style, don't know attributes or find them verify are. if specify style, has "this one" or "that one", if utilize 1 of have utilize "this other one", none of take effect unless line break mode "yet one", "yet one" style isn't 1 need use.
so, can't figure out how translate attributes have in old code code yield exact same results in non-deprecated method. think i'm pretty close, can't right utilize of "nslinebreakbyclipping" translate new method's syntax without getting hard error. error in line "width=expectedlabelsize1.width" , says "no fellow member named "width" in 'struct cgrect' ". if alter cgrect cgsize, in original code, different error on specific line initializing look incompatible type.
here original code:
int width = 0; if([surveytype isequaltostring:@"site survey"]){ //calculate expected width of survey label... cgsize maximumlabelsize = cgsizemake(165,16); cgsize expectedlabelsize1 = [surveyname sizewithfont:[uifont systemfontofsize:9.0] constrainedtosize:maximumlabelsize linebreakmode:nslinebreakbyclipping]; width=expectedlabelsize1.width; if(width > 165){ width=165; }
and here i've been able cobble instead:
//calculate expected width of survey label... cgsize maximumlabelsize = cgsizemake(165,16); cgrect expectedlabelsize1 = [surveyname boundingrectwithsize:maximumlabelsize options:(nsstringdrawinguseslinefragmentorigin | nsstringdrawingtruncateslastvisibleline | nslinebreakbywordwrapping) attributes:@{nsfontattributename: [uifont systemfontofsize:9.0]} context:nil]; width=expectedlabelsize1.width; if(width > 165){ width=165; }
i don't know i'm doing here, obviously, i'm hoping can show me how convert old method new , not lose of functionality or formatting in process. how can incorporate nslinebreakmodebyclipping attribute had if no longer appears available attribute or option?
thank you!!!
edit: apologize, realized left out code may help explain 1 of errors getting. left out first 2 lines above, variable "width" initialized integer. whole "label size calculation" code part of much larger "if" statement, part giving me fits deprecated method post pertains. anyway, since "width" not addressed in cgrect, next line after cgrect method (width=expectedlabelsize1.width) generates error above "width" not beingness fellow member of struct. that, now, don't know how add together "width" attribute cgrect struct. overall method (boundingrectwithsize:options:attributes:context:) have appears "clean", in doesn't generate errors on own, doesn't address "width" or nslinebreakmodebyclipping. that's i'm getting error (for missing "width" variable) , i'm getting lost on how incorporate nslinebreakmodebyclipping new method syntax.
it simpler utilize uilabel sizethatfits
eg.
cgsize maximumlabelsize = cgsizemake(cgfloat_max,16); cgsize expectedlabelsize1 = [surveyname sizethatfits:max]; width=expectedlabelsize1.width; if(width > 165){ width=165; }
also see http://doing-it-wrong.mikeweller.com/2012/07/youre-doing-it-wrong-2-sizing-labels.html
ios objective-c xcode deprecated
Comments
Post a Comment