之前已经:
let removeBadgeButton:UIButton = UIButton() removeBadgeButton.setBackgroundImage(UIImage(named: "remove_badge"), forState: UIControlState.Normal) removeBadgeButton.tag = indexPath.row removeBadgeButton.addTarget(self, action: Selector("removeSelectedPerson:"), forControlEvents: UIControlEvents.TouchUpInside) cell.contentView.addSubview(removeBadgeButton) |
了,但是感觉:
在当前的CollectionViewCell中添加的这个button,点击对应按钮所属于的区域内时,竟然没响应。。
猜测是不是button加了setBackgroundImage,效果不太好,影响按钮点击啊
所以去搜:
swift UIButton add image
参考:
ios – How to change UIButton image in Swift – Stack Overflow
ios – Create a button programmatically and set a background image – Stack Overflow
ios – How to change UIButton image after clicking in Swift? – Stack Overflow
好些没变化:
看来不是UIButton的事情,而是UICollectionViewCell中subview中button不方便点击到的事情
转载请注明:在路上 » [已解决]swift给UIButton添加图像