contentsize Example of iOS Dynamic Computing Uiscrollview (page is made up of label)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.