簡體   English   中英

在tableView上設置圖像單元格大小

[英]Set image on tableView Cell size

我有tableView Cell大小,需要在tableView cell上設置圖像。但是,未設置圖像定義cell大小(以下代碼存儲到tableView Cell size中,存儲了cellSize變量)。 我的代碼是...,

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

圖像中的上述代碼未在tableView Cell. properly設置圖像tableView Cell.

那么,如何在TableView Cell上設置圖像?

如果您試圖說您在每個單元格中設置的圖像沒有顯示在正確的位置,那么您可以嘗試執行以下操作:

首先創建一個原型單元,然后將UIImageView放置在所需單元中的正確位置,然后轉到UIImage的scale屬性,並記下坐標...

代替

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

這可以編寫如下代碼:

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

例如

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

試試這個代碼:

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