iOS Xib布局某些控件显示或隐藏<约束的修改>
对于这个问题使用Masonry是很好解决的。

注意:绿色的是label2,当indexpath.section % 2 == 0时,label2不存在。
关键代码如下:
if (indexPath.section % 2 == 0) {
[cell.label2 mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0);
}];
}
代码如下:
//
// ViewController.m
// XibTestDemo
//
// Created by 思 彭 on 2017/10/19.
// Copyright © 2017年 思 彭. All rights reserved.
// #import "ViewController.h"
#import "TableViewCell.h"
#import <Masonry.h> @interface ViewController ()<UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setUI];
} #pragma mark - 设置界面 - (void)setUI { self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.tableFooterView = [[UIView alloc]init];
// 注册cell
[self.tableView registerNib:[UINib nibWithNibName: NSStringFromClass([TableViewCell class]) bundle:nil] forCellReuseIdentifier:@"TableViewCell"];
// 行高
// self.tableView.rowHeight = UITableViewAutomaticDimension;
// self.tableView.estimatedRowHeight = 100;
[self.view addSubview: self.tableView];
self.tableView.estimatedRowHeight = ;
self.tableView.estimatedSectionHeaderHeight = ;
self.tableView.estimatedSectionFooterHeight = ;
} #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
if (indexPath.section % == ) {
[cell.label2 mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo();
}];
}
return cell;
} #pragma mark - UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.001f;
} - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section % == ) {
return ;
}
return ;
} @end
Demo地址: https://github.com/PengSiSi/XibDemo
iOS Xib布局某些控件显示或隐藏<约束的修改>的更多相关文章
- 利用来JS控制页面控件显示和隐藏有两种方法
利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一: 1 2 document.getEle ...
- Android Visibility控件显示和隐藏
Android控件显示和隐藏 visibility 可见(visible) XML文件:android:visibility="visible" Java代码:view.setVi ...
- Android控件显示和隐藏
Android控件都有visibility属性,该属性有三个可能值:visible.invisible.gone.可以通过预设或是Java程序控制这些控件的显示或隐藏. 一.在XML配置文件设置 可见 ...
- ios开发之--系统控件显示中文
虽然一直知道X-code肯定提供有语言本地化的设置地方,但是一直也做个记录,有些时候的汉化,还是需要使用代码去控制,键盘的右下角.navagiton的return使用代码修改,调用系统相机时,也是出现 ...
- 仿酷狗音乐播放器开发日志二十三 修复Option控件显示状态不全的bug(附源码)
转载请说明原出处,谢谢~~ 整个仿酷狗工程的开发将近尾声,现在还差选项设置窗体的部分,显然在设置窗体里用的最多的就是OptionUI控件,我在写好大致的布局后去测试效果,发现Option控件的显示效果 ...
- Xamarin iOS教程之页面控件
Xamarin iOS教程之页面控件 Xamarin iOS 页面控件 在iPhone手机的主界面中,经常会看到一排小白点,那就是页面控件,如图2.44所示.它是由小白点和滚动视图组成,可以用来控制翻 ...
- iOS学习之UIPickerView控件的关联选择
接上篇iOS学习之UIPickerView控件的简单使用 接着上篇的代码 http://download.csdn.net/detail/totogo2010/4391870 ,我们要实现的效果如下: ...
- QT5:第二章 布局排版控件
一.简介 在QT组件面板中有Layouts和Spacers两个组件面板 注意:布局排版控件不显示 1.Layouts(布局) Vertical Layout:垂直方向布局,组件自动在垂直方向上分布 H ...
- Java开发桌面程序学习(二)————fxml布局与控件学习
JavaFx项目 新建完项目,我们的项目有三个文件 Main.java 程序入口类,载入界面并显示 Controller.java 事件处理,与fxml绑定 Sample.fxml 界面 sample ...
随机推荐
- ubuntu下后台服务的管理
注册后台服务后都有脚本存在/lib/systemd/system路径下 如mysql为mysql.service 被service管理的进程被杀掉还是会重启的 应使用service XXX stop停 ...
- 分享一波目前写的最强的autohotkey 插件
支持各种软件快速切换,补全括号,代码等!!!!!!!! ;这种全局定义要写在所有代码的前面才能让所有代码起作用. SetCapsLockState , AlwaysOff SetNumlockStat ...
- Pycharm----设置背景颜色和字体的样式
编辑器默认显示的样式背景为白色,看着会刺眼,也不方便查找我们写的某些参数等,通过设定,可以对页面的样式进行选择更改,方便直观的在编辑器中查看自己所写的代码, 设置前: 设置后 操作方式:
- python 图像识别的小应用
前些天看见了几个有趣的python项目,在自己实际测试和理解后贴一下代码. https://www.shiyanlou.com/courses/589/labs/1964/document 算法主要逻 ...
- 1、概述&应用场景
1.概述&应用场景 Java反射机制是在运行状态中,对于任意一个类(Class)文件,都能够知道这个类的所有属性和方法: 对于任意一个对象,都能够调用它的任意一个方法和属性: 这种动态获取的信 ...
- Vue中v-if和v-show的使用场景
1. 官方文档 https://cn.vuejs.org/v2/guide/conditional.html#v-if-vs-v-show 2. v-if 和 v-show 的区别 2.1 官方解释 ...
- fmt
fmt.Println("hello world") fmt.Printf("%T",a)打印a 的类型 fmt.Printf("%v",a ...
- [POI] 大都市meg
http://www.lydsy.com/JudgeOnline/problem.php?id=1103 树剖边权转点权,vector存图卡一下午RE 气炸.. #include <iostre ...
- Codeforces Round #521 (Div.3)题解
A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...
- 【线性代数】6-6:相似矩阵(Similar Matrices)
title: [线性代数]6-6:相似矩阵(Similar Matrices) categories: Mathematic Linear Algebra keywords: Similar Matr ...