我在 swift 中为“ViewController”类 ViewController 提供了以下代码: UIViewController ,UITableViewDelegate,UITableViewDataSource{
@IBOutlet weak var imgTableView:UITableView!
let imgList = ["1.png", "2.png", "3.png" , "4.png"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.imgList.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellID", forIndexPath: indexPath) as? ImgTableViewCell
cell?.coverImage.image = UIImage(named: imgList[0])
for intValue in 1..<4
{
let stackViewImages = UIImageView()
stackViewImages.image = UIImage(named: imgList[intValue])
cell?.imgStackView.addArrangedSubview(stackViewImages)
}
return cell!
}
}
+++++++++++++++++++++++++++
类 ImgTableViewCell: UITableViewCell {
@IBOutlet weak var coverImage:UIImageView!
@IBOutlet weak var imgStackView:UIStackView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
如何将标签添加到堆栈视图中的最后一张照片。我尝试创建一个新标签,并通过在 stackview 内的 imageview 上调用 addsubview 以编程方式将其添加到 stackview 中,但标签被放置在单元格的最顶部。