html - How to scroll UIlabel Text and set it width and Hight dynamically in objective c -
i new in ios , facing problem scroll label text.my code able scroll label text width not setting properly. code this
nsstring * htmlstring = @"<html><body>"; nsstring *htmlstring2=@"</body></html>"; newstring=[nsstring stringwithformat:@"%@%@%@",htmlstring,result,htmlstring2]; nslog(@"new string =%@",newstring); nsattributedstring * attrstr = [[nsattributedstring alloc] initwithdata:[newstring datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil]; nslog(@"string value = %@",result); // [mydatansmarray addobject:idarray]; shortnamearray=[[nsmutablearray alloc]init]; shortnamearray=[responsedict valueforkey:@"abc"]; if (ui_user_interface_idiom() == uiuserinterfaceidiompad) { lbl = [[uilabel alloc]initwithframe:cgrectmake(0,0,700, 1800)]; nsstring *thetext = @"a long string"; cgrect labelrect = cgrectmake(10, 50, 300, 50); lbl.adjustsfontsizetofitwidth = yes; [lbl setnumberoflines:0]; cgfloat fontsize = 30; while (fontsize > 0.0) { cgsize size = [thetext sizewithfont:[uifont fontwithname:@"verdana" size:fontsize] constrainedtosize:cgsizemake(labelrect.size.width, 10000) linebreakmode:nslinebreakbywordwrapping]; if (size.height <= labelrect.size.height) break; fontsize -= 1.0; } //set font size lbl.font = [uifont fontwithname:@"arial" size:fontsize]; } else { lbl = [[uilabel alloc]initwithframe:cgrectmake(0,0,350, 800)]; } nslog(@"result array =%@",shortnamearray); cgfloat y = 10; nsmutablearray* animals = [nsmutablearray new]; nsuinteger maxcount = headarray.count > shortnamearray.count ? headarray.count : shortnamearray.count; (int = 0; < maxcount; ++) { if ([headarray objectatindex:i]) { [animals addobject:[headarray objectatindex:i]]; } if ([shortnamearray objectatindex:i]) { [animals addobject:[shortnamearray objectatindex:i]]; } } nslog(@"array =%@",animals); for(int i=0;i<[shortnamearray count] && i<[headarray count];i++){ // y+=20; y+=10; nsstring *newarray =[animals objectatindex:i]; newarray=[animals componentsjoinedbystring:@""]; nsstring *newstring; [lbl setlinebreakmode:nslinebreakbywordwrapping]; lbl.textalignment = nstextalignmentcenter; nsstring * htmlstring = @"<html><body>"; nsstring *htmlstring2=@"</body></html>"; newstring=[nsstring stringwithformat:@"%@%@%@",htmlstring,newarray,htmlstring2]; nslog(@"new string =%@",newstring); nsattributedstring * attrstr = [[nsattributedstring alloc] initwithdata:[newstring datausingencoding:nsunicodestringencoding] options:@{ nsdocumenttypedocumentattribute: nshtmltextdocumenttype } documentattributes:nil error:nil]; lbl.attributedtext = attrstr; nsstring *thetext = @"a long string"; cgrect labelrect = cgrectmake(10, 50, 300, 50); lbl.adjustsfontsizetofitwidth = yes; [lbl setnumberoflines:0]; cgfloat fontsize = 15; while (fontsize > 0.0) { cgsize size = [thetext sizewithfont:[uifont fontwithname:@"verdana" size:fontsize] constrainedtosize:cgsizemake(labelrect.size.width, 10000) linebreakmode:nslinebreakbywordwrapping]; if (size.height <= labelrect.size.height) break; fontsize -= 1.0; } //set font size lbl.font = [uifont fontwithname:@"arial" size:fontsize]; } nstimer *timer = [nstimer timerwithtimeinterval:1 target:self selector:@selector(timer) userinfo:nil repeats:yes]; [[nsrunloop mainrunloop] addtimer:timer formode:nsrunloopcommonmodes]; //[_scrollview scrollrecttovisible:nsmakerange(0,0,0.0) animated:yes]; [scroll addsubview:lbl]; [uiview commitanimations]; scroll.contentsize=cgsizemake(scroll.frame.size.width+[shortnamearray count], lbl.frame.size.height);
i using code width not set dynamically. how set width in dynamically. in advance!
please use uitextview instead of uilabel. problem solve in minimum line of code.
Comments
Post a Comment