1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 {5Uiscrollview *_scrollview;6 }7 //Data Source8@property (nonatomic,strong) Nsarray *DataArray;9 Ten @end One A @implementationViewcontroller - -- (void) Viewdidload { the [Super Viewdidload]; - -NSString *path = [[NSBundle mainbundle] Pathforresource:@"statuses"OfType:@"plist"]; -_dataarray =[Nsarray Arraywithcontentsoffile:path]; + -CGFloat height =0; + A_scrollview =[[Uiscrollview alloc] init]; at_scrollview.translatesautoresizingmaskintoconstraints =NO; - [Self.view Addsubview:_scrollview]; - -Nsarray *consscrhor = [Nslayoutconstraint constraintswithvisualformat:@"h:|-0-[_scrollview]-0-|"options:nslayoutformatalignmentmask metrics:nil views:nsdictionaryofvariablebindings (_scrollView)]; - [Self.view Addconstraints:consscrhor]; - inNsarray *consscrvor = [Nslayoutconstraint constraintswithvisualformat:@"v:|-0-[_scrollview]-0-|"options:nslayoutformatalignmentmask metrics:nil views:nsdictionaryofvariablebindings (_scrollView)]; - [Self.view Addconstraints:consscrvor]; to + for(Nsdictionary *dictinch_dataarray) { - //cgsize size = [dict[@ "text"] boundingrectwithsize:[uiscreen mainscreen].bounds.size options: Nsstringdrawinguseslinefragmentorigin Attributes:@{nsfontattributename:[uifont systemFontOfSize:16.0]} context: Nil].size; the //NSLog (@ "size:%@", nsstringfromcgsize (size)); * $UILabel *toollabel =[[UILabel alloc] init];Panax NotoginsengToollabel.text = dict[@"text"]; -Toollabel.numberoflines =0; theCgsize size =[Toollabel sizethatfits:cgsizemake ([UIScreen mainscreen].bounds.size.width, Maxfloat)]; +Toollabel.frame = CGRectMake (0, Height,375, size.height); A theToollabel.backgroundcolor =[Uicolor Orangecolor]; + [_scrollview Addsubview:toollabel]; - $height+=Size.Height; $ -UIView *spaceview = [[UIView alloc] Initwithframe:cgrectmake (0, Height,375, -)]; -Spaceview.backgroundcolor =[Uicolor Yellowcolor]; the [_scrollview Addsubview:spaceview]; -height+= -;Wuyi theNSLog (@"%@", dict[@"text"]); -NSLog (@"%@", nsstringfromcgsize (size)); Wu } - About_scrollview.contentsize = Cgsizemake (375, height); $ - } - -- (void) didreceivememorywarning { A [Super didreceivememorywarning]; + //Dispose of any resources the can be recreated. the } - $ @end
contentsize Example of iOS Dynamic Computing Uiscrollview (page is made up of label)