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相关的更多相关文章

  1. UI基础之UITextField相关

    UITextField *textF = [[UITextField alloc] init]; 1.字体相关 textF.text = @"文本框文字"; textF.textC ...

  2. UI基础之UIButton相关

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 1.按钮透明效果 btn.alpha = 0.8; 2.按钮圆角处理 btn ...

  3. Android UI基础之五大布局

    Android  UI基础之五大布局 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Andro ...

  4. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  5. 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素

    [源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...

  6. 转发-UI基础教程 – 原生App切图的那些事儿

    UI基础教程 – 原生App切图的那些事儿 转发:http://www.shejidaren.com/app-ui-cut-and-slice.html 移动APP切图是UI设计必须学会的一项技能,切 ...

  7. Android UI基础教程 目录

    从csdn下载了这本英文版的书之后,又去京东搞了一个中文目录下来.对照着看. 话说,这本书绝对超值.有money的童鞋看完英文版记得去买中文版的~~ Android UI基础教程完整英文版 pdf+源 ...

  8. UI基础UIButton

    UI基础UIButton 前面写了UIWindow.UIViewController,那些都是一些框架,框架需要填充上具体的view才能组成我们的应用,移动应用开发中UI占了很大一部分,最基础的UI实 ...

  9. UI基础UIWindow、UIView

    UI基础UIWindow.UIView 在PC中,应用程序多是使用视窗的形式显示内容,手机应用也不例外,手机应用中要在屏幕上显示内容首先要创建一个窗口承载内容,iOS应用中使用UIWindow.UIV ...

随机推荐

  1. php上传大文件设置方法

    打开php.ini,首先找到 ;;;;;;;;;;;;;;;; ; file uploads ; ;;;;;;;;;;;;;;;; 区域,有影响文件上传的以下几个参数: file_uploads = ...

  2. 使用HTML5新支持的搭建WebRtc环境来作为视频通讯

    发现如果再重新设计这块的话,又会有不同的思路.对于可定位能力,我们可以全息日志采集,将每个用户在整个系统的走向异步的抓取下来,再同步到专门的日志分析系统,在这个系统中可以根据用户号码.订单号进行过滤分 ...

  3. redis make时 提示 zmalloc.h:50:31: error: jemalloc/jemalloc.h:

    redis安装需要环境必备 gcc 但是若未先安装好gcc,make失败后再次 make 会提示如下错误 zmalloc.h:50:31: error: jemalloc/jemalloc.h: 这时 ...

  4. ViewPager+Fragment实现页面的切换

    新知识,新摘要: 效果图:framgent导入包都是v4包下,谨慎导入错误! 首先设置viewPager布局: <?xml version="1.0" encoding=&q ...

  5. HashMap的两种实现方式

    本文主要简要分析了Java中和Redis中HashMap的实现,并且对比了两者的异同 1.Java的实现 下图表示了Java中一个HashMap的主要实现方式 因为大家对于Java中HashMap的实 ...

  6. design pattern

    1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor

  7. 对dijkstra算法的自我理解,c#例子

    dijkstra该算法主要应用在求解最短路径,从最近点开始,广度搜索. 假设有向图中有10个顶点,求其中某个顶点a到其它顶点的最短路径..满足贪心算法的2个标准.时间复杂度为O(N2) 此问题可以进行 ...

  8. SQLSERVER进程CPU使用率100%

    解决SQLSERVER2008 CPU使用率99%: 1.dbcc checkdb 重建索引 2.檢查有沒有死鎖 -- sp_lock SELECT request_session_id spid , ...

  9. Eclipse之Git提交项目

    一.使用eclipse自带插件提交项目 1.自带git插件进行配置我们的用户名和密码,即是自己github注册的用户. windows-perferences-Team-Git-configurati ...

  10. NGUI 屏幕自适应大屏与小屏(初始设定宽高为1280x720,能适应比其小或者更大的屏)

    具体细节可以参考另外一篇随笔! 以下提供的算法完成的事: 1.自适应1280x720分辨率以下的屏幕 2.自适应1280x720分辨率以上的屏幕 在我设定的要求内包括的分辨率大部分都测过了,背景图.全 ...