我在自己的UIButton中添加了一个适合其内容的subView,问题是我每次单击按钮时都听不到按钮的操作,我的猜测是因为我的UIButton在我添加的subView的下面,但是我不知道该怎么解决。
这是我在按钮中添加子视图的代码
func setButtonContent(myButtonView: UIButton, textLabel: String, textViewDescription: String) {
if let nibFile = Bundle.main.loadNibNamed("nibName", owner: self, options: nil)?.first as? FundTransferButton {
nibFile.frame.size.height = myButtonView.frame.size.height
nibFile.frame.size.width = myButtonView.frame.size.width
nibFile.label.text = textLabel
nibFile.textViewDescription.text = textViewDescription
myButtonView.addSubview(nibFile)
}
}
我只想创建一个包含自定义设计的自定义按钮。
您的紧迫问题可以通过以下方式解决:
您可以在UIButton的层下添加子视图层。