最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift给UIButton添加图像

Swift crifan 2880浏览 0评论

之前已经:

                    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添加图像

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.200 seconds, using 22.06MB memory