collection点击高亮...

本文介绍如何使用UICollectionView实现高亮显示当前项,并通过滑动CollectionView更新选中项及视觉反馈,包括设置高亮样式、响应点击和滑动事件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/ 记录indexPath
@property(nonatomic, assign)NSIndexPath *indexPath;


 // topCollectionView item的起始位置
- (void)topCollectionViewPlay{


    self.indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    // 红线
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(15, 47, 60, 3)];
    self.topView.backgroundColor = [UIColor redColor];
    [self.topCollectionView addSubview:self.topView];


}


// cell方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


   if(self.topCollectionView == collectionView) {
        FXHTopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"top" forIndexPath:indexPath];


        FXHPresentSayModel *presentSayModel = self.topArr[indexPath.row];
        cell.topLabel.text = presentSayModel.name;


        // 判断是否高亮
        if (self.indexPath == indexPath) {
            cell.topLabel.font = [UIFont systemFontOfSize:20];
            cell.topLabel.textColor = [UIColor redColor];
        }else{
            cell.topLabel.font = [UIFont systemFontOfSize:17];
            cell.topLabel.textColor = [UIColor blackColor];
        }
        return cell;


    }


// collectionview的点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{


if(self.topCollectionView == collectionView) {


        FXHTopCollectionViewCell *cell = (FXHTopCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        [self collectionView:self.topCollectionView didDeselectItemAtIndexPath:self.indexPath];
        cell.topLabel.font = [UIFont systemFontOfSize:20];
        cell.topLabel.textColor = [UIColor redColor];


        // 红线
        self.topView.frame = CGRectMake(70 * indexPath.row + 15, 47, 60, 3);
        self.indexPath = indexPath;


        // 点击item滑动collectionview
        self.backCollectionView.contentOffset = CGPointMake(self.view.frame.size.width * indexPath.row, 0);


    }


}


// 选中状态
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}


// 取消状态
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{


    FXHTopCollectionViewCell *cell = (FXHTopCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.topLabel.font = [UIFont systemFontOfSize:17];
    cell.topLabel.textColor = [UIColor blackColor];
}


// 滑动结束就执行的方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{


    NSInteger a = self.backCollectionView.contentOffset.x / WIDTH;
    NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:a inSection:0];


    if (self.backCollectionView == scrollView) {
        if (a > 2 && a < 17) {
            self.topCollectionView.contentOffset = CGPointMake(70 * (a - 2), 0);
        }else if (a < 1){
            self.topCollectionView.contentOffset = CGPointZero;
        }
    }
    // topview跟着backcollectionview滑动而滑动
    self.topView.frame = CGRectMake(70 * a + 15, 47, 60, 3);
    [self collectionView:self.topCollectionView shouldSelectItemAtIndexPath:newIndexPath];
    [self collectionView:self.topCollectionView didDeselectItemAtIndexPath:self.indexPath];
    [self collectionView:self.topCollectionView didSelectItemAtIndexPath:newIndexPath];
    self.indexPath = newIndexPath;


}
Visual Studio Code (VSCode)是一个强大的轻量级源代码编辑器,支持多种编程语言,包括C语言。为了能够在VSCode中顺利地编写、编译并调试C程序,你需要配置`launch.json`文件。 ### 步骤一:安装必要的扩展 首先需要确保已经安装了以下两个重要的插件: - **C/C++** 扩展包(由Microsoft提供),它包含了用于智能感知(IntelliSense),语法高亮等功能的支持。 - 安装了一个合适的编译器,例如GCC(GNU Compiler Collection) 或者 MinGW-w64(对于Windows用户). ### 步骤二:创建项目结构 接下来,在你的工作区根目录下建立一个新的文件夹来存放所有相关的源码文件,并按照需求组织好其他资源如头文件(.h), 源文件(.c/.cpp等) ### 步骤三:配置tasks.json来进行构建任务 打开命令面板(`Ctrl+Shift+P`)然后选择 `Tasks: Configure Task...`, 接着点击 "Create tasks.json file from template" 并选取适合您环境的任务模板(gcc build active file 或类似选项). 这将生成一个示例版本的 `.vscode/tasks.json`. 这个JSON文档是用来告诉 VSCode 怎样去编译您的 C 文件,默认情况下会尝试通过 GCC 来完成这项工作. ```json { // 其他属性... "label": "build hello", // 构建标签名 "command": "gcc", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], } ``` > `-g`: 包含debug信息 > `${file}` : 当前正在处理的 .c 文件路径 > `${fileDirname}/${fileBasenameNoExtension}` : 输出可执行文件的位置以及名称 ### 步骤四:设置 launch.json 调试器选项 同样地进入命令面板搜索“Add Configuration”,这会在`.vscode/` 目录下自动生成或更新现有的 `launch.json` 配置项。为方便起见这里直接给出一段典型的C语言启动配置例子: ```json { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", // 名称可以自行修改 "type": "cppdbg", // 使用 cppdbg 类型表示这是针对C/C++项目的调试配置 "request": "launch", // 请求类型是 “启动” "program": "${workspaceFolder}/a.out",// 程序入口点(即刚才我们用 gcc 编译出来的那个) "args": [], // 参数列表为空数组意味着不会传递额外参数给该应用程序 "stopAtEntry": false, // 是否在主函数的第一行暂停 "cwd": "${workspaceFolder}", // 工作空间所在位置 "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build hello", // 在开始之前先跑一遍上面提到过的 task 里的 'Build Hello World' "miDebuggerPath": "/usr/bin/gdb" // GDB 的完整路径取决于系统平台,请按需调整 } ] } ``` 以上就是关于如何在 Visual Studio Code 中对 C 项目进行简单的 Debugging 设置说明啦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值