iOS development add pictures dynamically in cell solve recurring layer problems

Source: Internet
Author: User

1. Create the ScrollView when the cell initializes, then add ImageView to the ScrollView, and finally dynamically calculate the height of the scrollview while reusing the cell

All in all, initialize the Create control to be placed in the cell's init, assign the value to the outside of Init, or each cycle will be repeatedly created ImageView view

-(uitableviewcell *) TableView: (uitableview *) TableView Cellforrowatindexpath: (nsindexpath *) indexpath{

UITableViewCell *cell=[tableview dequeuereusablecellwithidentifier:@ "Cellid"];

if (cell==nil) {

cell=[[UITableViewCell alloc]initwithstyle: uitableviewcellstyledefault Reuseidentifier:@ "Cellid"];

scrolling View

self.   ScrollView=[[uiscrollview alloc]init];

self. ScrollView. Tag=9;

Create a picture for ScrollView

cgfloat scrollviewwidth=[uiscreen mainscreen]. Bounds. Size. Width-up;

        int Hang=[self. Imagesarray count]%3==< Span class= "S5" >0int) [self. Imagesarray count]/3:( Span class= "S6" >int) [self. Imagesarray count]/3+1

int imgwidth= (scrollviewwidth-)/3;

for (int i=0; i

for (int j=0; j<3; j + +) {

if (i*3+j==self. Imagesarray. Count) {

break;

}

                uiimageview< Span class= "S1" > *imgview=[[uiimageview alloc ]initwithframe:cgrectmake (j* (imgwidth+< Span class= "S5" >55

Imgview. image=[UIImage imagenamed: [self. Imagesarray objectatindex: i*3+j];

[self. ScrollView addsubview: Imgview];

}

}

[Cell. contentview addsubview:self. ScrollView];

}

else{

Self. ScrollView= (uiscrollview *) [cell. Contentview viewwithtag:9];

}

calculate uilabelcontent height based on number of words ( modified )

cgfloat labelwidth=[uiscreen mainscreen]. Bounds. Size. Width-up;

nsdictionary *attrs=@{nsfontattributename:self. Labelcontent. Font};

cgsize maxsize=cgsizemake(labelwidth, maxfloat);

cgsize size=[self. Labelcontent. Text boundingrectwithsize: maxSize options:nsstringdrawinguseslinefragmentorigin attributes: attrs context:nil]. Size;

self. Labelcontent. Frame=CGRectMake(all, size. Width, size. Height);

//scrollview as the picture grows

    cgfloat Scrollviewwidth=[uiscreen mainscreen]. Bounds. Size. Width-26;

    int Hang=[self< Span class= "S1". imagesarray count]%3==0int) [self. Imagesarray count]/3:( Span class= "S6" >int) [self. Imagesarray count]/3+1

int imgwidth= (scrollviewwidth-)/3;

self. ScrollView. BackgroundColor=[uicolor lightgraycolor];

    self. Scrollview. Frame=cgrectmake (13 89+size. Height+101) *5);

}

iOS development add pictures dynamically in cell solve recurring layer problems

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.