简体   繁体   English

在tableView上设置图像单元格大小

[英]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). 我有tableView Cell大小,需要在tableView cell上设置图像。但是,未设置图像定义cell大小(以下代码存储到tableView Cell size中,存储了cellSize变量)。 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. 图像中的上述代码未在tableView Cell. properly设置图像tableView Cell.

So, How to set image on TableView Cell ? 那么,如何在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 首先创建一个原型单元,然后将UIImageView放置在所需单元中的正确位置,然后转到UIImage的scale属性,并记下坐标...

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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