UI基础之UITableViewController相关
1> 设置类型为Group
- (instancetype)initWithStyle:(UITableViewStyle)style
{
return [super initWithStyle:UITableViewStyleGrouped];
}
2> 设置每组cell之间的间距
// 每组头部高度
self.tableView.sectionHeaderHeight = ;
// 每组底部高度
self.tableView.sectionFooterHeight = ;
3> 设置cell的分隔线
// 去掉分隔线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
/*-- 设置cell分隔线为全屏 --*/
// 方案一
// 在iOS7之后,tableView会有自己的内边距
// 将内边距清空
self.tableView.separatorInset = UIEdgeInsetsZero;
// 在iOS8之后,系统会在每一个控件自动布局时添加默认的内边距
// 清空cell的内边距:考虑重复利用,所以在awakeFromNib中设置一次就可以了
- (void)awakeFromNib
{
self.layoutMargins = UIEdgeInsetsZero;
} // 方案二
// 了解tableView底层实现,通过设置cell的frame实现
// 取消cell分隔线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// 设置tableView的背景色
self.tableView.backgroundColor = [UIColor lightGrayColor]; // 在自定义cell中重写setFrame方法
- (void)setFrame:(CGRect)frame
{
frame.size.height -= ;
[super setFrame:frame];
}
4> 设置tableView的弹簧效果
// 取消弹簧效果
self.tableView.bounces = NO;
5> 设置cell选中时的背景颜色
UIView *backgroundV = [[UIView alloc] initWithFrame:cell.bounds];
backgroundV.backgroundColor = [UIColor whiteColor];
cell.selectedBackgroundView = backgroundV;
6> 设置带箭头的cell样式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
7> 设置cell文字的字体和颜色
cell.textLabel.font = [UIFont systemFontOfSize:15.0];
cell.textLabel.textColor = [UIColor darkGrayColor];
8> 设置cell中的富文本
NSMutableDictionary *attDict = [NSMutableDictionary dictionary];
attDict[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20.0];
attDict[NSForegroundColorAttributeName] = [UIColor whiteColor];
NSAttributedString *attText = [[NSAttributedString alloc] initWithString:@"安全退出" attributes:attDict];
cell.textLabel.attributedText = attText;
9> 设置cell文字居中
cell.textLabel.textAlignment = NSTextAlignmentCenter;
10> 当tableView为UITableViewStylePlain时,隐藏多余的cell
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
11> 设置tableView的headerView
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, )];
headerView.contentView.backgroundColor = [UIColor redColor];
self.tableView.tableHeaderView = headerView;
使用TableView时遇到的坑:
1> [TableView] Setting the background color on UITableViewHeaderFooterView has been deprecated. Please set a custom UIView with your desired background color to the backgroundView property instead.
翻译:不赞成在UITableViewHeaderFooterView上设置背景色。请改为将具有所需背景色的自定义UIView设置为backgroundview属性。
解决方案:使用xib时,添加一个View控件,设置View的背景色。


2>[Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
翻译:[警告]仅警告一次:检测到一种情况,其中约束模糊地建议TableView单元格的内容视图的高度为零。我们考虑的是无意的坍塌,而是使用标准高度。
解决方案:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ;
}
UI基础之UITableViewController相关的更多相关文章
- UI基础之UITextField相关
UITextField *textF = [[UITextField alloc] init]; 1.字体相关 textF.text = @"文本框文字"; textF.textC ...
- UI基础之UIButton相关
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 1.按钮透明效果 btn.alpha = 0.8; 2.按钮圆角处理 btn ...
- Android UI基础之五大布局
Android UI基础之五大布局 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Andro ...
- iOS开发UI基础—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素
[源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...
- 转发-UI基础教程 – 原生App切图的那些事儿
UI基础教程 – 原生App切图的那些事儿 转发:http://www.shejidaren.com/app-ui-cut-and-slice.html 移动APP切图是UI设计必须学会的一项技能,切 ...
- Android UI基础教程 目录
从csdn下载了这本英文版的书之后,又去京东搞了一个中文目录下来.对照着看. 话说,这本书绝对超值.有money的童鞋看完英文版记得去买中文版的~~ Android UI基础教程完整英文版 pdf+源 ...
- UI基础UIButton
UI基础UIButton 前面写了UIWindow.UIViewController,那些都是一些框架,框架需要填充上具体的view才能组成我们的应用,移动应用开发中UI占了很大一部分,最基础的UI实 ...
- UI基础UIWindow、UIView
UI基础UIWindow.UIView 在PC中,应用程序多是使用视窗的形式显示内容,手机应用也不例外,手机应用中要在屏幕上显示内容首先要创建一个窗口承载内容,iOS应用中使用UIWindow.UIV ...
随机推荐
- android 术语
Context : 是android 应用程序的 中央控制中心.所有应用程序特有的功能通过context 进行访问. Activity: 一个 Android 应用有若干个 task 任务组成,每个人 ...
- chrome调试hove等类似事件
前台开发过程中经常会用chrome调试代码.但是有的时候,hover或者js控制的属性显示不全 解决办法有两种: 1.根据chrome版本不一样(检查两个字)可能会有所差别 2.图中有标记
- 忘记BIOS超级管理员密码,怎么破解?
[请尊重原创版权,如需引用,请注明来源及地址] 本人就喜欢没事瞎折腾,动动手活动活动筋骨没坏处,前不久非常便宜的弄到一玩具 ThinkPad T400(公司处理品),外观还算不错,除了电源适配器是坏的 ...
- win10家庭版快速升级专业版
win10家庭普通版升级专业版方法: 1.点击“开始”,选择控制面板. 2.点击“系统与安全”,选择“Windows Anytime Upgrade”.(或者:单击「开始」按钮,在搜索框中,键入any ...
- 你不知道的this指向
javascript中,我们预想的this指向,有时候与预期不一样,直接上经典例子 window.name=2; var test={ 'name':1, 'getName':function(){ ...
- 自定义TextField清除按钮
当需要设置TextField的清除按钮的时候,系统的总是不满足需求,这就需要我们自定义了,代码如下: // // TextFieldDemoViewController.m // OCDemo // ...
- Git学习(四)——分支管理
一.创建与合并分支 1.创建分支 一开始的时候,master分支是一条线,Git用master指向最新的提交,再用HEAD指向master,就能确定当前分支,以及当前分支的提交点.每次提交 ,mast ...
- 游戏中的人工智能——初探AI
一.游戏中的人工智能 让游戏具有挑战性: 让游戏好玩的关键因素是为之找到合适的难度等级: 人工智能在游戏中的作用是通过提供富有挑战性的竞争对象来让游戏更好玩,而在游戏中行动逼真的非玩家角色(NPC), ...
- 神经网络(python源代码)
神经网络的逻辑应该都是熟知的了,在这里想说明一下交叉验证 交叉验证方法: 看图大概就能理解了,大致就是先将数据集分成K份,对这K份中每一份都取不一样的比例数据进行训练和测试.得出K个误差,将这K个误差 ...
- jQuery实现折叠下拉效果
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...