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 ...
随机推荐
- Numpy API学习
Numpy 常用API学习(全) 一.介绍 NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库 ...
- python关于解决'\u'开头的字符串转中文的方法
转自: https://www.cnblogs.com/hahaxzy9500/p/7685955.html 字符串转中文: s = '\u5468\u661f\u9170' print(s) ##打 ...
- Ubuntu死机解决方法汇总
为什么不建议强制关机 如果长按电源按键强制关机,有可能损坏硬件或者丢失数据,甚至导致磁盘坏道! 其实, 大部分时候的死机是假死, 不是真死... 有时候鼠标还能动呢. 还有一个原因: 对于平时忠贞不二 ...
- spring lookup method 注入
lookup method注入是spring动态改变bean里方法的实现.方法执行返回的对象,使用spring内原有的这类对象替换,通过改变方法返回值来动态改变方法.内部实现为使用cgl ...
- Week08_day01 (Hive实现WordCount计数)
Hive实现WordCount计数 在没学习Hive之前,我们学习MapReduce去实现WordCount计数的时候,就要去编写80多行的java代码,现在我们学习了Hive,我们只需要一行Sql语 ...
- JavaScript005,语法
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 创建conda虚拟环境以及python的virtualenv虚拟环境
我觉得我,嗯...可能脑袋里面有水 首先说一个,就是我电脑安装了conda2和conda3,原来怎么查看conda版本都是2,所以就没有创建虚拟环境 系统变量里面的path要改,总共有3个: D:\A ...
- Windows服务 System.ServiceProcess.ServiceBase类
一.Windows服务 1.Windows服务应用程序是一种需要长期运行的应用程序,它适合服务器环境. 2.无用户界面,任何消息都会写进Windows事件日志. 3.随计算机启动而启动,不需要用户一定 ...
- c#截图功能
简化版: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- maven+struts2例子
本文在开发第一个maven示例的基础上进行扩展. 第一个maven示例目录结构如下: 扩展后目录为: 打开pom.xml 在WEB-INF文件夹下新建web.xml: <?xml version ...