ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIBut
发布时间:2020-12-14 17:55:31 所属栏目:百科 来源:网络整理
导读:如何在tableview标题中创建条形按钮或UIButton,当我点击tableview标题按钮时,它应该转到另一个Viewcontroller.我怎样才能通过Progarm实现这一目标.请帮帮我们 解决方法 喜欢 func tableView(tableView: UITableView,viewForHeaderInSection section: Int) -
如何在tableview标题中创建条形按钮或UIButton,当我点击tableview标题按钮时,它应该转到另一个Viewcontroller.我怎样才能通过Progarm实现这一目标.请帮帮我们
解决方法
喜欢
func tableView(tableView: UITableView,viewForHeaderInSection section: Int) -> UIView? {
let frame: CGRect = tableView.frame
let DoneBut: UIButton = UIButton(frame: CGRectMake(100,200,50)) //frame.size.width - 60 DoneBut.setTitle("Done",forState: .Normal) DoneBut.backgroundColor = UIColor.redColor()
DoneBut.addTarget(self,action: #selector(ViewController.buttonTapped(_:)),forControlEvents: .TouchUpInside)
DoneBut.addTarget(self,action: Selector("buttonTapped:"),forControlEvents: .TouchUpInside)button.addTarget(self,forControlEvents: .TouchUpInside)
let headerView: UIView = UIView(frame: CGRectMake(0,frame.size.width,frame.size.height)) headerView.addSubview(DoneBut) return headerView }
func buttonTapped(sender: UIButton) { //Button Tapped and open your another ViewController } 更新的答案 func tableView(tableView:UITableView,viewForHeaderInSection section:Int) – > UIView的? let frame: CGRect = tableView.frame let DoneBut: UIButton = UIButton(frame: CGRectMake(frame.size.width - 200,150,50)) // DoneBut.setTitle("Done",forState: .Normal) DoneBut.backgroundColor = UIColor.redColor() DoneBut.addTarget(self,forControlEvents: .TouchUpInside) DoneBut.backgroundColor = UIColor.blueColor() let headerView: UIView = UIView(frame: CGRectMake(0,frame.size.height)) headerView.backgroundColor = UIColor.redColor() headerView.addSubview(DoneBut) return headerView } func tableView(tableView: UITableView,heightForHeaderInSection section: Int) -> CGFloat { return 50.0 } func buttonTapped(sender: UIButton) { //Button Tapped and open your another ViewController } 产量 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |