func tableVIEw(tableVIEw: UItableVIEw,vIEwForheaderInSection section: Int) -> UIVIEw? {
initially get the frame of your tablevIEw
let frame: CGRect = tableVIEw.frame
set the frame for UIbutton where is comes in VIEw
let DoneBut: UIbutton = UIbutton(frame: CGRectMake(100,200,50)) //frame.size.wIDth - 60DoneBut.setTitle("Done",forState: .normal)DoneBut.backgroundcolor = UIcolor.redcolor()
if you are using swift 2.2 call the selector as follows
DoneBut.addTarget(self,action: #selector(VIEwController.buttonTapped(_:)),forControlEvents: .touchUpInsIDe)
if you are using swift 2.1 call the selector as follows
DoneBut.addTarget(self,action: Selector("buttonTapped:"),forControlEvents: .touchUpInsIDe)button.addTarget(self,forControlEvents: .touchUpInsIDe)
create the UIVIEw reason vIEwforheader returns UIVIEw and add button to that subVIEw
let headerVIEw: UIVIEw = UIVIEw(frame: CGRectMake(0,frame.size.wIDth,frame.size.height))headerVIEw.addSubvIEw(DoneBut)return headerVIEw}
call method like
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}
产量
总结以上是内存溢出为你收集整理的ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIButton?全部内容,希望文章能够帮你解决ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIButton?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)