[英]Xcode 8 autolayout constraints don't work in custom tableViewCell
[英]Constraints don't work when setting an UIImage inside a TableViewCell
當我在cellForRowAt
函數中設置UIImage
,它看起來像我正在設置的UIImage
與UIImageView
重疊。
編輯: clipsToBound
標記和contentMode
設置為.scaleAspectFit
在Storyboard
我照常在Storyboard
設置所有Constraints
:
但是,當我運行該應用程序時,它看起來比設置的Constraints
具有更高的優先級,這就是我得到的:
不久前,我在其他項目中做了類似的事情,對我來說效果很好:
這是用於設置單元格的代碼,盡管我敢肯定我只是在Storyboard
意外標記或未標記了一些東西:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return songArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: MainVCCell.CELL_ID, for: indexPath) as? MainVCCell else { return UITableViewCell() }
cell.showLoader()
cell.songNameLabel.text = songArray[indexPath.row].title
if songImageArray[songArray[indexPath.row].title] != nil {
cell.imageView?.image = songImageArray[songArray[indexPath.row].title]!!
cell.hideLoader()
}
cell.setupImageDesign()
return cell
}
如果需要任何其他信息,請讓我知道,謝謝。
將圖像視圖clipsToBounds
設置為true
。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: MainVCCell.CELL_ID, for: indexPath) as? MainVCCell else { return UITableViewCell() }
cell.showLoader()
cell.songNameLabel.text = songArray[indexPath.row].title
if songImageArray[songArray[indexPath.row].title] != nil {
cell.imageView?.image = songImageArray[songArray[indexPath.row].title]!!
cell.hideLoader()
}
cell.setupImageDesign()
return cell
}
cell.imageView?.image
是UITableViewCell中的默認cell.imageView?.image
。
您必須重命名自定義UIImageView出口
在情節clipsToBounds = true
更改UIImageView的contentMode
,還設置clipsToBounds = true
。
將ImageView的ContentMode更改為.scalToFill
並將Clipping屬性更改為clipToBounds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.