
in project have adjust uitextview , uiscrollview dynamically based on data trying perfect result not coming please me one.
see code growing textview based on data , don't know how grow uiscrollview based on data please me.
- (void)textviewdidchange:(uitextview *)textview { cgfloat fixedwidth = textview.frame.size.width; cgsize newsize = [textview sizethatfits:cgsizemake(fixedwidth, maxfloat)]; cgrect newframe = textview.frame; newframe.size = cgsizemake(fmaxf(newsize.width, fixedwidth), newsize.height); textview.frame = newframe; }
you can set size of textview frame
cgrect frame = textview.frame; frame.size.height = textview.contentsize.height; textview.frame=frame; or can try below code.
- (cgfloat)textviewheightforattributedtext:(nsattributedstring *)text andwidth:(cgfloat)width { uitextview *textview = [[uitextview alloc] init]; [textview setattributedtext:text]; cgsize size = [textview sizethatfits:cgsizemake(width, flt_max)]; return size.height; } or can try below code.
nsmutableparagraphstyle *paragraphstyle = [[nsmutableparagraphstyle alloc] init]; [paragraphstyle setlinebreakmode:nslinebreakbywordwrapping]; nsdictionary *attributes = @{ nsfontattributename: textview.font, nsparagraphstyleattributename : paragraphstyle }; cgrect size = [texttomeasure boundingrectwithsize:cgsizemake(cgrectgetwidth(frame), maxfloat) options:nsstringdrawinguseslinefragmentorigin attributes:attributes context:nil];
Comments
Post a Comment