简体   繁体   English

UITableViewCell的accessoryView中有多个图像

[英]Multiple images in accessoryView of UITableViewCell

I am trying to display multiple images in a cell of same sizes 24x24. 我正在尝试在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. 基于@EugeneZhenyaGordin注释,我尝试将框架提供给子视图,并且可以正常工作。 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: 这是我的布局:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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