简体   繁体   中英

Multiple images in accessoryView of UITableViewCell

I am trying to display multiple images in a cell of same sizes 24x24. I have put them in a loop like this:

cell!.accessoryView = UIView()
for url in arrURL {
    cell!.accessoryView?.addSubview(UIImageView(image: UIImage(named: "ic_play_circle_outline")))
}
cell!.accessoryView?.frame = CGRectMake(0, 0, 24 * CGFloat(arrURL.count), 24)

But unfortunately, it displays only one image and there exists empty space afterwards for remaining images. Here is the layout:

表单元

There is an empty space on right side of the play icon. Any idea why this happening?

Based on @EugeneZhenyaGordin comment, I have tried giving the frame to subviews and it works. Here is my sample code:

cell!.accessoryView = UIView()
var i = 0
for url in arrURL {
      let myView = UIImageView(image: UIImage(named: "ic_play_circle_outline"))
      myView.frame = CGRectMake(i>0 ? 24 * CGFloat(i) : 0, 0, 24, 24)
      cell!.accessoryView?.addSubview(myView)
      i+=1
}
cell!.accessoryView?.frame = CGRectMake(0, 0, 24 * CGFloat(arrURL.count), 24)

Here is my layout:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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