我目前正在使用包含使用Swift的UICollectionView的自定义键盘。集合视图正在迭代一组图像(这很好用),并根据数组计数创建适当数量的单元格。
我正在尝试向单元格添加一个按钮,并且在创建单元格时,没有添加按钮。任何想法或帮助都非常感谢。
以下是代码:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(turkeyReuseIdentifier, forIndexPath: indexPath)
cell.backgroundColor = UIColor.purpleColor()
let shareButton: UIButton = UIButton(frame: CGRectMake(123, 123, 40, 40))
shareButton.setTitle("Button", forState: .Normal)
shareButton.backgroundColor = UIColor.greenColor()
shareButton.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside)
cell.addSubview(shareButton)
return cell
}