iOS小技能: tableView section间距失效的解决方案
前言
tableView 一些常用的细节技巧:
- iOS tableView设置style:UITableViewStyleGrouped 时,非第一个section的间距失效】的解决方案
- 修改 tableViewSectionHeader 字体及背景色
- 为UITableViewCell设置预估高度
- iOS 自定义UITableViewHeaderFooterView (替代titleForHeaderInSection)
https://blog.csdn.net/z929118967/article/details/105218766
I section相关
1.1 section的间距失效的解决方案
iOS tableView设置style:UITableViewStyleGrouped 时,非第一个section的间距失效
的解决方案: 必须全部实现FooterInSection
及FooterInSection
对应的四个代理方法才有效(四个必须同时实现)
具体的代码如下
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
switch (section) {
case ERPRelease_commoditiesViewSection4platProductCategories:
case ERPRelease_commoditiesViewSection4productCategoriesbasicInfo4Singlespecification:
case ERPRelease_commoditiesViewSection4brandInfo:
{
return kAdjustRatio(10);
}
break;
default:
break;
}
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *tmp = [UIView new];
tmp.backgroundColor = self.tableView.backgroundColor;
switch (section) {
case ERPRelease_commoditiesViewSection4platProductCategories:
case ERPRelease_commoditiesViewSection4productCategoriesbasicInfo4Singlespecification:
case ERPRelease_commoditiesViewSection4brandInfo:
{
return tmp;
}
break;
default:
break;
}
return nil;
}
- 效果图:
在这里插入图片描述
- 表格的初始化代码
- (UITableView *)tableView{
if (nil == _tableView) {
// UITableView *tmpView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];//初始化方法
UITableView *tmpView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];//初始化方法
_tableView = tmpView;
_tableView.bounces = NO;
tmpView.delegate = self;
tmpView.rowHeight = UITableViewAutomaticDimension;
tmpView.separatorStyle = UITableViewCellSeparatorStyleNone;
tmpView.dataSource = self;
[self addSubview:_tableView];
_tableView.contentInset = UIEdgeInsetsMake(0, 0, kAdjustRatio(0),0);
__weak __typeof__(self) weakSelf = self;
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(weakSelf);
make.left.equalTo(weakSelf).offset(kAdjustRatio(0));
make.bottom.equalTo(weakSelf);
make.right.equalTo(weakSelf).offset(-kAdjustRatio(0));
}];
[_tableView setBackgroundColor:k_view_backColor];
}
return _tableView;
}
1.2 修改 SectionHeader 字体及背景色
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
header.textLabel.textColor = rgb(51,51,51);
header.textLabel.font = kPingFangFont(15);
[header layoutIfNeeded];
header.clipsToBounds = YES;
header.contentView.backgroundColor
= self.tableView.backgroundColor;
}
1.3 自定义FooterView
- iOS 自定义UITableViewHeaderFooterView (替代titleForHeaderInSection)
II 为UITableViewCell设置预估高度
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
return kAdjustRatio(44);
}
III 自定义cell样式
3.1 显示Checkmark样式
- (void)setModels:( ERPProductCategoryTreeDto*)models{
_models =models;
if(models.selectedStyle == ProductCategorytTreeSelectedStyle4Checkmark){
if (models.isSelected ) {
self.tintColor = HWColor(243, 39, 52);
self.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
self.accessoryType = UITableViewCellAccessoryNone;
}
}
}
————————————————
版权声明:本文为CSDN博主「iOS逆向」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z929118967/article/details/106691892
3.2 案例:商品类目选择视图
[video(video-fWYLiH0s-1624340333311)(type-csdn)(url-https://live.csdn.net/v/embed/167208)(image-https://vedu.csdnimg.cn/82733fac22774a61b81ec2daccfa3844/snapshots/4f7e04a170db4e74b8b961709a176dd0-00002.jpg)(title-iOS 商品/经营类目选择视图)]
下载地址:https://download.csdn.net/download/u011018979/19775162
文章地址:https://kunnan.blog.csdn.net/article/details/106553175视频地址:https://live.csdn.net/v/167208商品经营类目选择视图的应用场景: 1、发布商品时选择商品类目 2、商户进件选择经营类目 3、购物类app下单界面的商品类目筛选
在发布商品的时候,选择类目界面的要求视图分为上下部分。
1、 上部分:展示已经选择的类目信息,并清晰的从上倒下罗列对应层级类目信息(悬浮),点击类目的时候,下部分的展示的类目信息切换为同级类目信息供选择。2、 下部分:展示可供选择的类目信息(支持滚动选中类目)
支持清空数据功能
相关文章
- iOS小技能:因境外IP无法访问导致 App 被拒的解决方案
- iOS逆向之深入解析如何计算+load方法的耗时「建议收藏」
- iOS 14 中如何对一个SwiftUI App 增加 AppDelegate?
- iOS组件化解决方案
- ios通过按钮点击异步加载图片代码详解手机开发
- iOS——– Objective-C多态:动态类型识别+动态绑定+动态加载详解手机开发
- iOS—-闪退,无报错原因,经典解决方案详解手机开发
- javascript ios 拍照照片翻转解决方案详解编程语言
- html5 IOS 软键盘弹出解决方案详解编程语言
- appLinux开发探索之路:从iOS APP开始(linux开发ios)
- 华为P40 Pro用户分享鸿蒙系统体验以为误入iOS
- 基于Linux环境下iOS应用开发实践(linux下开发ios)
- iOS 限免 App 精选:解谜游戏《Number Mazes》(¥18→0)
- 探秘iOS:它究竟是一种基于Linux的操作系统吗?(ios是linux系统吗)
- 涅槃团队掌门人高雪峰:一个iOS漏洞值多少钱
- iOS 15搜索体验大改进:涵盖网图、相册、锁屏访问等更多内容
- 深入理解iOS图文混排原理并自定义图文控件
- 升级苹果 iOS 14.7.1 正式版后,部分 iPhone 11/8/7/6s 用户抱怨出现信号“无服务”错误