简体   繁体   中英

Set image on tableView Cell size

I have tableView Cell size and need to set image on tableView cell ., but image not set of define the Cell size (following code into tableView Cell size stored cellSize variable). My Code is...,

CGRect cellSize = [tableView rectForRowAtIndexPath:indexPath];
                    cell.imageView.frame = cellSize;
                    cell.imageView.image = [UIImage imageNamed:@"logo_black.png"];

above code in image not set image properly in tableView Cell.

So, How to set image on TableView Cell ?

If you are trying to say that the image u are setting in each cell is not getting displayed at the right position then u can try doing the following:

first create a prototype cell and position the UIImageView at the right place in the cell u want and go to the scale properties of UIImage and note down the co-ordinates... then

instead of

CGRect cellSize = [tableView rectForRowAtIndexPath:indexPath];
                    cell.imageView.frame = cellSize;

this you can write the code as follows:

cell.imageView.frame = CGRectMake(x,y,width,height);

ex.

CGRectMake(0,0,20,20)
CGRect cellSize = cell.frame;
cell.imageView.frame = cellSize;

Try this code:

UIView *bgView = [[UIView allow ] init];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageName:@"imgName"]];
cell.selectedBackgroundView = bgView;

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