【发布时间】:2020-03-17 11:54:27
【问题描述】:
UIButton 点按时操作不起作用。我尝试了 Stack Overflow 上另一篇文章的其他建议,但没有任何效果。以下是我的代码:
let saveBtn = GActionBtn(type: .system)
lazy var footer: UIView = {
let v = UIView()
v.isUserInteractionEnabled = true
v.addSubview(saveBtn)
saveBtn.isUserInteractionEnabled = true
saveBtn.addTarget(self, action: #selector(handleSave), for: .touchUpInside)
saveBtn.backgroundColor = #colorLiteral(red: 0.4470588235, green: 0.6274509804, blue: 0.3960784314, alpha: 1)
saveBtn.layer.cornerRadius = 27.5
let attributeString = NSAttributedString(string: "Save".localized(), attributes: [NSAttributedString.Key.font: UIFont(name: "NunitoSans-Bold", size: 16), NSAttributedString.Key.foregroundColor: UIColor.white])
saveBtn.setAttributedTitle(attributeString, for: .normal)
NSLayoutConstraint.activate([
saveBtn.centerXAnchor.constraint(equalTo: v.centerXAnchor),
saveBtn.centerYAnchor.constraint(equalTo: v.centerYAnchor, constant: 54),
saveBtn.widthAnchor.constraint(equalToConstant: 312),
saveBtn.heightAnchor.constraint(equalToConstant: 52)
])
return v
}()
@objc private func handleSave() {
print("save")
}
private func setupTableView() {
tableView = UITableView(frame: .zero, style: .grouped)
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 80, right: 0)
tableView.separatorStyle = .none
tableView.keyboardDismissMode = .interactive
tableView.backgroundColor = .white
tableView.tableFooterView = footer
}
【问题讨论】:
-
你应该使用tableview的默认footerView函数。然后尝试使用您的按钮