Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift开发笔记6 - 在表格单元格中添加按钮大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

1 通过重写tableview的单元格绘制方法来添加按钮 2 重写获取tableview的单元格高度方法 代码如下: //设置日期按钮共7*6个 override func tableView(tableView: UITableView, cellForRowATindexPath indexPath: NSIndexPath) -> UITableViewCell {

1 通过重写tableview的单元格绘制方法添加按钮

2 重写获取tableview的单元格高度方法


代码如下:

@H_607_23@ //设置日期按钮共7*6个 override func tableView(tableView: UITableView,cellForRowATindexPath indexPath: NSIndexPath) -> UITableViewCell { let cell=super.tableView(tableView,cellForRowATindexPath: indexPath) //判断是否为目标单元格 if indexPath.section == 1 && indexPath.row == 0{ //设置x,y位置和宽高 let button = UIButton(frame: CGRectMake(0,50,120,30)) //设置按钮文字 button.settitle("1",forState: UIControlState.Normal) //设置字体颜色 button.settitleColor(UIColor.lightGrayColor(),forState: UIControlState.Normal) //设置点击事件 button.addTarget(self,action: "onClick",forControlEvents: UIControlEvents.TouchUpInsidE) //加到单元格中 cell .contentView.addSubview(button) } return cell } //因为按钮插入后会引起cell高度的变化,所以要重新设置 override func tableView(tableView: UITableView,heightForRowATindexPath indexPath: NSIndexPath) -> CGFloat { if indexPath.section == 1 && indexPath.row == 0{ return 24*7 }else{ return super.tableView(tableView,heightForRowATindexPath: indexPath) } } ///点击日期按钮的动作 func onClick(){ ///弹出选中日期的打卡记录 UIAlertView(title: "打卡情况",message: "上班:正常;下班:正常",delegate: nil,cancelButtontitle: "确定",otherButtontitles: "取消").show() }

大佬总结

以上是大佬教程为你收集整理的swift开发笔记6 - 在表格单元格中添加按钮全部内容,希望文章能够帮你解决swift开发笔记6 - 在表格单元格中添加按钮所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。