点击tableViewHeader控制cell关闭展开以及label的代码自定义约束

ios-UITableView点击展开和收回.zip 点击一行展开或者收回(是否展开),内部列表点击收回。 立即下载

// Arrow label

        contentView.addSubview(arrowLabel)

        arrowLabel.textColor = UIColor.white

        arrowLabel.translatesAutoresizingMaskIntoConstraints = false

        arrowLabel.widthAnchor.constraint(equalToConstant: 12).isActive = true

        arrowLabel.topAnchor.constraint(equalTo: marginGuide.topAnchor).isActive = true

        arrowLabel.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor).isActive = true

        arrowLabel.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor).isActive = true

//

        // Call tapHeader when tapping on this header

        //

        addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(CollapsibleTableViewHeader.tapHeader(_:))))



完整代码:

import UIKit


protocol CollapsibleTableViewHeaderDelegate {

    func toggleSection(_ header: CollapsibleTableViewHeader, section: Int)

}


class CollapsibleTableViewHeader: UITableViewHeaderFooterView {

    

    var delegate: CollapsibleTableViewHeaderDelegate?

    var section: Int = 0

    

    let titleLabel = UILabel()

    let arrowLabel = UILabel()

    

    override init(reuseIdentifier: String?) {

        super.init(reuseIdentifier: reuseIdentifier)

        

        // Content View

        contentView.backgroundColor = UIColor(hex: 0x2E3944)

        

        let marginGuide = contentView.layoutMarginsGuide

        

        // Arrow label

        contentView.addSubview(arrowLabel)

        arrowLabel.textColor = UIColor.white

        arrowLabel.translatesAutoresizingMaskIntoConstraints = false

        arrowLabel.widthAnchor.constraint(equalToConstant: 12).isActive = true

        arrowLabel.topAnchor.constraint(equalTo: marginGuide.topAnchor).isActive = true

        arrowLabel.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor).isActive = true

        arrowLabel.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor).isActive = true

        

        // Title label

        contentView.addSubview(titleLabel)

        titleLabel.textColor = UIColor.white

        titleLabel.translatesAutoresizingMaskIntoConstraints = false

        titleLabel.topAnchor.constraint(equalTo: marginGuide.topAnchor).isActive = true

        titleLabel.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor).isActive = true

        titleLabel.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor).isActive = true

        titleLabel.leadingAnchor.constraint(equalTo: marginGuide.leadingAnchor).isActive = true

        

        //

        // Call tapHeader when tapping on this header

        //

        addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(CollapsibleTableViewHeader.tapHeader(_:))))

        

    }

    

    required init?(coder aDecoder: NSCoder) {

        fatalError("init(coder:) has not been implemented")

    }

    

    //

    // Trigger toggle section when tapping on the header

    //

    func tapHeader(_ gestureRecognizer: UITapGestureRecognizer) {

        guard let cell = gestureRecognizer.view as? CollapsibleTableViewHeader else {

            return

        }

        

        delegate?.toggleSection(self, section: cell.section)

    }

    

    func setCollapsed(_ collapsed: Bool) {

        //

        // Animate the arrow rotation (see Extensions.swf)

        //

        arrowLabel.rotate(collapsed ? 0.0 : .pi / 2)

    }

    

}

extension UIView {


    func rotate(_ toValue: CGFloat, duration: CFTimeInterval = 0.2) {

        let animation = CABasicAnimation(keyPath: "transform.rotation")

        

        animation.toValue = toValue

        animation.duration = duration

        animation.isRemovedOnCompletion = false

        animation.fillMode = kCAFillModeForwards

        

        self.layer.add(animation, forKey: nil)

    }


}




import UIKit


//

// MARK: - View Controller

//

class CollapsibleTableViewController: UITableViewController {

    

    var sections = sectionsData

    

    override func viewDidLoad() {

        super.viewDidLoad()

        

        // Auto resizing the height of the cell

        tableView.estimatedRowHeight = 44.0

        tableView.rowHeight = UITableViewAutomaticDimension

        

        self.title = "Apple Products"

    }

    

}


//

// MARK: - View Controller DataSource and Delegate

//

extension CollapsibleTableViewController {


    override func numberOfSections(in tableView: UITableView) -> Int {

        return sections.count

    }

    

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return sections[section].collapsed ? 0 : sections[section].items.count

    }

    

    // Cell

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell: CollapsibleTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as? CollapsibleTableViewCell ??

            CollapsibleTableViewCell(style: .default, reuseIdentifier: "cell")

        

        let item: Item = sections[indexPath.section].items[indexPath.row]

        

        cell.nameLabel.text = item.name

        cell.detailLabel.text = item.detail

        

        return cell

    }

    

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        return UITableViewAutomaticDimension

    }

    

    // Header

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header") as? CollapsibleTableViewHeader ?? CollapsibleTableViewHeader(reuseIdentifier: "header")

        

        header.titleLabel.text = sections[section].name

        header.arrowLabel.text = ">"

        header.setCollapsed(sections[section].collapsed)

        

        header.section = section

        header.delegate = self

        

        return header

    }

    

    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

        return 44.0

    }

    

    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {

        return 1.0

    }


}


//

// MARK: - Section Header Delegate

//

extension CollapsibleTableViewController: CollapsibleTableViewHeaderDelegate {

    

    func toggleSection(_ header: CollapsibleTableViewHeader, section: Int) {

        let collapsed = !sections[section].collapsed

        

        // Toggle collapse

        sections[section].collapsed = collapsed

        header.setCollapsed(collapsed)

        

        tableView.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)

    }

    

}



工程创新训练大赛智能网联车辆赛道LKA+自动驾驶9000+分数分案例 /获取主车在主车路径上的ST坐标。if (status == AVPStatus::eForwarding) // approaching the parking space接近阶段。if (status == AVPStatus::eForwarding) // approaching the parking space接近阶段。if (status == AVPStatus::eForwarding) // approaching the parking space接近阶段。 阅读详情

相关推荐

一文读懂YOLO V5 与 YOLO V4

一文读懂YOLO V5 与 YOLO V4 YOLO之父Joseph Redmon在今年年初宣布退出计算机视觉的研究的时候,很多人都以为目标检测神器YOLO系列就此终结。然而在4月23日,继任者YOLO V4却悄无声息地来了。Alexey Bochkovskiy发表了一篇名为YOLOV4: Optimal Speed and Accuracy of Object Detection的文章。YOLO V4是YOLO系列一个重大的更新,其在COCO数据集上的平均精度(AP)和帧率精度(FPS)分别提高了10%

williamhyin的博客 8788

QML <4> Tableview 自定义表格显示 delegate FontAwesome Canvas

QML <4> Tableview 自定义表格显示 delegate FontAwesome Canvas 前言 基于QML TableView 的自定义表格显示,表格实现类容参考网易云音乐如下图所示: 参考实现功能自定义表格实现如下: 一、表格列设置 表格列为固定列数,代码如下; TableViewColumn{role: "num_flag"; title: ""; width: 80; elideMode: Text.ElideRight;} TableViewColum

jiang173707的博客 4623

PCB工艺-SI9000使用教程

本文介绍了阻抗计算工具SI9000的使用方法,重点讲解了微带线与带状线的区别、共面阻抗概念及参考面选择。通过USB差分走线实例,详细说明了如何选择计算模型、填写参数并确定线宽线距。文章还提供了层叠设计资料和工厂常规阻抗表格作为参考,建议制板时标注需控阻抗的线路供板厂调整。最后简单提及了嘉立创阻抗计算工具作为备选方案。

weixin_50120208的博客 2024

【QML Model-View】TableView 使用

TableView 就是 Qt Quick 为表格式呈现数据提供的组件。想必兄台用过 Excel,可以藉此想象下 TableView 的效果。TableView 与 ListView 类似,相比之下多了滚动条、挑选、可调整尺寸的表头等特性。它的数据也通过 Model 来提供,你可以使用 ListModel、XmlListModel,也可以使用 C++ 中从 QAbstractltemModel、QAbstractTableModel 等继承而实现的 Model。

m0_73482095的博客 1819

MATLAB2022a安装避坑指南:从下载到破解的完整流程(附常见错误解决方案)

本文提供MATLAB2022a在Windows系统下的完整安装教程与深度配置指南。内容涵盖从系统兼容性检查、安装媒介验证到分步安装、自定义产品选择及安装后优化设置的全流程。重点解析了安装过程中常见的权限、空间、许可证错误,并提供了系统性的故障诊断与解决方案,旨在帮助用户构建稳定高效的科研计算环境。

weixin_29057695的博客 439

1.用Python写了一个进销存管理的软件~需求分析&界面设计&数据库设计&技术路线选择~

前端也打算用Python来写,查了很多的python库,大家比较推荐的是wxpython和QPython,之前接触过一点点的QT,确实非常强大,但是库比较重量级,自己写的这个东西明显配不上QT,又详细调研了一下wxpython,就是它了!

pepper_lihui的专栏 4321

IOS UITableView单元点击事件

//选择表视图行时触发 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"ShowSelectedCity"]) { DetailViewController *detailViewControll

刘胡来 1625

【全局路径规划模块运动学算法】无人机Kinodynamic A*算法、Kinodynamic RRT*算法(附C++代码)

认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长!本文先对Kinodynamic A*算法做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章提示:以下是本篇文章正文内容啃这个Kinodynamic A_star算法,建议先啃一啃高飞fast_planner那篇论文,把理论打好,如果还是比较迷,就先看Dijksta、再看A_star、再看hybrid A_star 三个的流程,因为往上资料比较多,再看这个Kinodynamic A_star算法,流程已经很相像了。如果。

qq_35635374的博客 2600

(十一)TableView

TableView就是Qt Quick为了呈现出类似Excel表格样式数据而提供的组件,TableView和ListView类似,相比之下多了滚动条、挑选、可调整尺寸的表头等特性。它的数据也可以通过Model来提供,可以使用ListModel、XmlListModel,也可以使用C++中从QAbstractItemModel、QAbstractTableModel等继承而实现的Model。 实例 ...

bureau123的博客 817

Altium Designer系列: 软件系统参数配置保存

【Altium Designer实践】 软件系统参数配置保存 作者 CodeAllen ,转载请注明出处 目录设置中文菜单高亮模式设置文件关联pcb设置布线设置保存配置文件(复用) 设置中文菜单 DXP->Preferences 高亮模式设置 文件关联 pcb设置 布线设置 保存配置文件(复用) ......

CodeAllen嵌入式 2018

【AI编程】Claude Code 最强AI 编程利器项目实战详解

Claude Code 最强AI 编程利器项目实战详解

congge 7397

iOS开发中设置UITableView每组头试图与第一行cell之间的分割线

UITableView中每组头试图与第一行cell之间默认有一行分割线,且分割线是顶格显示,如果想要设置这条分割线不顶格显示,方法如下: cell.selectionStyle = UITableViewCellSelectionStyleNone;设置之后,整个tableview便不显示分割线了,此时需要自己设置分割线,包括cell的分割线和头试图的分割线 cell的分割线可以自定义UITa

3967

Qt C++ HTTP 调用通义千问大模型 X 学术论文润色工具(SCI 格式适配)

请求地址:`https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation`;| Windows | 打包时携带 `Qt6Network.dll`/`libcrypto-1_1-x64.dll` 等依赖;| Linux | 安装 `libssl-dev` 和 `libcurl4-openssl-dev`;| API 调用失败 | 检查 API-KEY 是否有效;

寒寒豆豆软件公司的博客 104

UItableview点击后的折叠效果的简单实现

项目有个需求。要求将主要信息列表展示,点击信息的时候,下方弹出来一个具体内容展示变化,差异等等。 之前做过这个,当时是网上找的一篇文章直接复制粘贴的,过了一段时间就给忘了,连思路都没有,今天花了一天时间,自己整理了一下,实现了这个效果,并做了一个优化,下面开始上代码首先说下思路,tableview进入的时候展示的是各个cell的section的headerview,cell默认给一个0的高度,这时

zhangqq16781的博客 2680

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Swift UITableView相关功能(六)头视图的高度

我们上一节主要讲了tableView分区以及分区的头标题和尾标题 上一节地址:http://blog.youkuaiyun.com/lwjok2007/article/details/49246613 继续使用上节代码(代码下载方式见第五节末尾) 上节我们讲了设置分区头标题。其实分区头 还可以设置高度,还有自定义view等功能 接下来我们尝试设置一下头视图的高度 很简

5058

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

【iOS】UITableView中section的展开和收起

手机QQ大家都玩过。我们可以对好友进行分组,点击分组可以展开查看里面的成员,再次点击就可以收起分组。那么这个是怎么实现的?之前做项目的时候也使用过,最近有时间整理,就把之前是怎么操作的记录下来。在写之前也是百度了一下,发现网上的资源也不是很多,今天就附带截图和源码展现出来。如有需要完善的地方或是新的思路的,我们可以一起交流。 再看博客之前,请大家再去玩玩自己的手机QQ,明确一下自己的问题。带着目

小猿猪哥的博客 1万+

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

TableView 展开和折叠

最近有一个小伙伴问我关于tableview的展开和折叠问题,相信很多人都写过。 还是自己随便实现了一遍。 基本的思路就是,用一个Model类来计算和控制tableview的高度。 实现效果:cell内容五行或者不足五行的时候,没有折叠功能,内容超过五行的时候,可以折叠和展开。 首先可以根据需求把cell的状态获取到为三个 不可展开、折叠状态和展开状态。 在Model里面可以用

xmy0010的博客 2231

tableViewCell列表点击展开显示二级列表

之前在网上看到过这种的,都是封装的或者是用的第三方,这是自己写的,有兴趣大家也可以把他封装起来留着自己用; #import "ViewController.h" #define WIDTH [UIScreen mainScreen].bounds.size.width #define HEIGHT [UIScreen mainScreen].bounds.size.height

lucky_xiaofeng的博客 1917

UITableView的headerView展开缩放动画

UITableView的headerView展开缩放动画   效果   源码 https://github.com/YouXianMing/Animations // // HeaderViewTapAnimationController.m // Animations // // Created by FrankLiu on 15/11/30. // ...

weixin_34066347的博客 278

iOS实现UIImageView透明区域点击事件穿透

感觉题目改为:不规则图形点击事件的识别 gen

ralbatr的专栏 1万+

iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)

今天我们要来说的知识点是UITableView的tableHeaderView,小伙伴要区分清楚,不是协议里的header,而是总的header,需要用tableView.tableHeaderView来设置。 使用tableView.tableHeaderView时,如果使用不当,会造成header覆盖cell,cell内容出现在header上或者header和cell中间莫名多了系统head...

CodingFire的博客 8459

最简单的点击TabelViewHeaderView展开cell/类似QQ

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34309435的博客 135

用 TableView 的代理方法添加的header点击第一个不触发事件,但是点击第二个header触发了第二组第一行的点击事件

直接上添加 header 的代码吧:     func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{         let cellID = "headerCell"         var headerCell = tableView.dequeueReusableCel

danshannuo3719的博客 977

vue-vux使用 cell/cell-box 组件 点击展开其他内容的时候修改过的数据会复原解决思路之一

问题描述 vue-vux使用 cell/cell-box 组件,点击展开其他内容的时候修改过的数据会复原。 但其实,在数据库已经修改好了,这个时候使用APP者还以为还没修改过数据。 解决思路 解决思路之一 改变数据源,重新渲染数据的时候就不会复原。(更人性化) 解决思路之二 重新请求查询。 示例 &amp;amp;amp;lt;div v-for=&amp;amp;quot;item in this.dataList...

让优秀成为一种习惯 5115
上一篇: Swift - 使用网格(UICollectionView)的自定义布局实现复杂页面
下一篇: swift中masonry的使用
iOS_yanmy
博客等级 码龄10年 14粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值