在swift 3中单击itselt时删除按钮

时间:2017-07-30 16:37:09

标签: ios swift3 uibutton

您好我已添加自定义UIButton。我想点击它自己删除此按钮。我这样做了。

    btnDelete.addTarget(self, action: #selector(deleteCoveringPerson(sender:)), for: .touchUpInside)
    btnDelete.setImage(UIImage.init(named: "close-dark"), for: .normal)
    btnCoveringPerson.addSubview(btnDelete)

这是我的删除按钮选择器

func deleteCoveringPerson(sender:UIButton)
{
    dm.strCoveringPersonNAme=""
    dm.strcoveringPersonCode="0"
    btnCoveringPerson.setTitle(lan.getConvertedLanguageString(word: "COVERINGPERSON"), for: .normal)
    btnDelete.removeFromSuperview()

}

我该怎么做?

1 个答案:

答案 0 :(得分:1)

对我来说这项工作很好

func deleteCoveringPerson(sender:UIButton)
{
    dm.strCoveringPersonNAme=""
    dm.strcoveringPersonCode="0"
    btnCoveringPerson.setTitle(lan.getConvertedLanguageString(word: "COVERINGPERSON"), for: .normal)
    sender.removeFromSuperview()
}

希望这有帮助