add image to uitableview cell

前端 未结 7 1254

I have a tableview, how can I add image to the left of this cells?

7条回答
  •  迷失自我
    2021-01-30 10:59

    Standard UITableViewCell already contains UIImageView that appears to the left to all your labels if its image is set. You can access it using imageView property:

    cell.imageView.image = someImage;
    

    If for some reason standard behavior does not suit your needs (note that you can customize properties of that standard image view) then you can add your own UIImageView to the cell as Aman suggested in his answer. But in that approach you'll have to manage cell's layout yourself (e.g. make sure that cell labels do not overlap image). And do not add subviews to the cell directly - add them to cell's contentView:

    // DO NOT!
    [cell addSubview:imv]; 
    // DO:
    [cell.contentView addSubview:imv];
    

提交回复
热议问题