简体   繁体   中英

Xcode UITableView Custom Cell xib Image Height

Please see this photo and help me, it is very important for me. thank you very much

在此处输入图片说明

I would implement heightforRowAtIndexPath for this, in short:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//first image height must be fetched for the ccurrent image using indexpath.row...

//Then use the height to set cell height:
    return imageHeight;
}

Need to customize the height of the custom cell and also need to resize the image views inside the custom cell according to your image

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

CGFloat cellHeight = image1height + image2height + <button height>;

return cellHeight;

}

Also need to assign the imageView rect in the custom cell according to the images dynamically.

This is my code

- (void)viewDidLoad {
    [super viewDidLoad];

    tableData = [NSArray arrayWithObjects:@"1.png", @"2.png", @"3.png", @"4.png", nil];

}


#pragma mark **** TableView ***
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *listTableIdentifier = @"CustomCell";
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:listTableIdentifier];


    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }


    cell.myImage1.image = [UIImage imageNamed:[tableData objectAtIndex:indexPath.row]];

    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 85;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM