iOS 结构简单清晰的 设置页面
这个是也是看了人家的代码,觉得甚是简单清晰,也是比较容易扩展。拿来学习一下
效果展示:
重点有以下2处:
1 .建立groupModel
列清组元素:当前组list 集合, 是否有header 或者 footer 等属性元素
@interface HFSettingGroup : NSObject @property (nonatomic, strong) NSString *header; // 头部标题 @property (nonatomic, strong) NSString *footer; // 尾部标题 @property (nonatomic, strong) NSArray *items; // 中间的条目 @end
2 . 建立itemModel
列清list 每行的item 都有什么元素
通常有的 就是 icon, title,content 。根据具体问题具体分析处理
添加闭包属性 void (^operation)() 根据具体 didSelectRowAtIndexPath: 触发获取指定回调
如果UI个性化非常明显,应该根据该组的枚举类型定制个人性化
#import <Foundation/Foundation.h> typedef NS_ENUM(NSInteger, HFSettingItemStyle){ HFSettomgStyleNormal //普通类型 }; @interface HFSettingItem : NSObject @property (nonatomic, assign) HFSettingItemStyle style; //类型style @property (nonatomic, strong) NSString *icon; //左边图标 @property (nonatomic, strong) NSString *title; @property (nonatomic, strong) NSString *content; // 描述 //具体样式的设置 如果格式不复杂 可区分成枚举Type 归类UI形式 这里UI有点复杂 不用Type @property (nonatomic, strong) NSNumber *isRedPointHidden; //代表当前是否未读 @property (nonatomic, strong) NSNumber *isLineHidden; //是否展示底部线 @property (nonatomic, strong) NSNumber *isArrowHidden; //是否展示箭头 /** cell上相关的触发事件 */ @property (nonatomic, copy) void (^operation)() ; // 点击cell后要执行的操作 /** 创建通用 settingItem @param icon 左边图标 @param title title @param content content @return item */ + (id)itemWithIcon:(NSString *)icon title:(NSString *)title content:(NSString *)content; @end
3 .使用举例
- (void)addSectionItems { self.groupArrays = [NSMutableArray array]; __weak typeof(self) weakSelf = self; // 1.1.月经测试 HFSettingItem *test = [HFSettingItem itemWithIcon:nil title:@"月经测试" content:@"未测试"]; //cell点击事件 test.operation = ^{ //TODO: test NSLog(@"test"); }; // 1.2测试结果 HFSettingItem *result = [HFSettingItem itemWithIcon:nil title:@"测试结果" content:@"平和质"]; result.operation = ^{ //TODO: test NSLog(@"result"); TestViewController *vc = [TestViewController new]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; HFSettingGroup *group = [[HFSettingGroup alloc] init]; group.header = @"第一组"; group.items = @[test,result]; [self.groupArrays addObject:group]; // 2.1意见反馈 HFSettingItem *suggest = [HFSettingItem itemWithIcon:nil title:@"意见反馈" content:nil]; suggest.operation = ^{ NSLog(@"suggest"); TestViewController *vc = [TestViewController new]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; HFSettingGroup *group1 = [[HFSettingGroup alloc] init]; group1.items = @[suggest]; group1.header = @"第二组"; [self.groupArrays addObject:group1]; }
posted on 2017-08-09 18:17 ACM_Someone like you 阅读(633) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)