Reputation: 1051
When I am setting the UIImage
in cellForRowAt
function it looks like the UIImage
I am setting overlaps the UIImageView
.
EDITED : clipsToBound
is marked and contentMode
is set to .scaleAspectFit
in the Storyboard
I am setting all the Constraints
in the Storyboard
as usual:
But when I run the app it looks something with a bigger priority overpowering the Constraints
I set and this is what I get :
A while ago I did a similar thing in other project which worked perfectly fine for me :
Here is the code for setting the cells, though I am pretty sure I just accidentally marked or unmarked something ing the 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
}
Please let me know if any additional information needed, Thank you in advance.
Upvotes: 0
Views: 562
Reputation: 230
Change the contentMode
of UIImageView in storyboard
and also set clipsToBounds = true
.
Upvotes: 0
Reputation: 3924
You have an issue with Constrain to margins
Please remove all the constraints and make sure unchecked this option before setting the constraints.
In Storyboard looks like this
Upvotes: 0
Reputation: 502
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
is default imageView from UITableViewCell.
You must rename your custom UIImageView outlet
Upvotes: 1
Reputation: 2470
Change ContentMode of ImageView to .scalToFill
and clipping property to clipToBounds
Upvotes: 0