iOS中tableView组头部或尾部标题的设置
解决在tableView返回组标题直接返回字符串,带来的不便设置组标题样式的问题解决办法,设置尾部标题和此类似
// 返回组头部view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;
}
//返回每组头部view - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc]init];
headerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
UILabel *label = [[UILabel alloc]init];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
label.frame = CGRectMake(15, 0, 100, 20);
[headerView addSubview:label];
if (section == 0) {
label.text = @"第0组title";
}else{
label.text = @"第1组title";
}
return headerView;
}
封装 UITableViewHeaderFooterView 也像tableViewCell一样也可以循环利用 自定义 UITableViewHeaderFooterView
+ (instancetype)headerFooterViewWithTabelView:(UITableView *)tableView{
BSHeaderFooterView *headerFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerIdentifier];
if (headerFooterView == nil) {
headerFooterView = [[BSHeaderFooterView alloc]initWithReuseIdentifier:headerIdentifier];
}
return headerFooterView;
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
self.contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
UILabel *label = [[UILabel alloc]init];
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
label.frame = CGRectMake(13, 0, 100, 20);
[self addSubview:label];
self.label = label;
}
return self;
}
//接收外界传进来的字符串并赋值 - (void)setTitle:(NSString *)title{
_title = [title copy];
self.label.text = title;
}
//返回组头部view方法 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
BSHeaderFooterView *headerFooter = [BSHeaderFooterView headerFooterViewWithTabelView:tableView];
if (section == 0) {
headerFooter.title = @"第0组title";
}else{
headerFooter.title = @"第1组title";
}
return headerFooter;
}
iOS中tableView组头部或尾部标题的设置的更多相关文章
- 如何在HTML不同的页面中,共用头部与尾部?
一.asp语言和PHP语言 首先制作一个头部文件head.asp,或者一个底部文件foot.asp.如主页是index.asp,调用头部代码是在index.asp文件代码的开始位置(第一个标记后面,& ...
- IOS中TableView的用法
一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITable ...
- iOS中TableView小技巧
摘要: TableView是ios开发中经经常使用到的控件,这里统一记录一下开发中遇到的经常使用小技巧,不断探索更新.也希望大家能够告诉我很多其它经常使用的小技巧啦~一起进步 1.去除多余的列表线条 ...
- IOS中tableView每组的头部控件、通过tableView的代理方法控制某一行的cell能否达到高亮选中状态
一.tableView每组的头部控件 1.控件宽度默认就是tableView的宽度 2.控件高度由下面的代理方法决定 - (CGFloat)tableView:(UITableView *)table ...
- IOS中TableView的使用(1) -创建一个简单的tableView
创建一个简单的tableView: #import <UIKit/UIKit.h> /*tableView 一定要遵守这两个协议: UITableViewDataSource,UITabl ...
- ios中tableview的移动添加删除
// // MJViewController.m // UITableView-编辑模式 // // Created by mj on 13-4-11. // Copyright (c) 2013年 ...
- ios中tableview网封装(viewcontroller封装)常用的
下载地址 http://pan.baidu.com/share/link?shareid=3657500168&uk=923776187 使用框架 1:asIHttpRequest库 2;SB ...
- ios中tableview侧栏的折叠
#import "ViewController.h" #define Ksmall 40.0f #define Klarge 80.0f #define KNoOpen @&quo ...
- IOS中Label根据上个label的内容设置下个label的frame
#import "ViewController.h" @interface ViewController () @property(nonatomic,strong)UILabel ...
随机推荐
- Ubuntu下安装GTK环境
要生成C图形界面的程序,得安装GTK环境 安装GTK环境只要安装一个gnome-core-devel就可以了,里面集成了很多其他的包.除此之外还要转一些其他的 东西,如libglib2.0 ...
- 【IOS 开发】Object - C 语法 之 流程控制
1. if 条件语句 if 表达式 : 表达式是一个 整型 或者 布尔型, 0 或者 FALSE 为 FALSE, 大于 0 为 TRUE; 代码示例 : /********************* ...
- JAVA之旅(二十二)——Map概述,子类对象特点,共性方法,keySet,entrySet,Map小练习
JAVA之旅(二十二)--Map概述,子类对象特点,共性方法,keySet,entrySet,Map小练习 继续坚持下去吧,各位骚年们! 事实上,我们的数据结构,只剩下这个Map的知识点了,平时开发中 ...
- 【Unity Shaders】Using Textures for Effects——让sprite sheets动起来
本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源 ...
- Android 使用com.j256.ormlite
在web开发中经常采用的hibernate,在android也提供了一个ormlite 导入所需jar包后 /** * SQLiteHelperOrm.java * 版权所有(C) 2014 * 创建 ...
- 跨平台移动APP开发进阶(一)mui开发注意事项
mui开发注意事项 Mui HTML5开发框架 mui是一个高性能的HTML5开发框架,从UI到效率,都在极力追求原生体验:这个框架自身有一些规则,刚接触的同学不很熟悉,特总结本文:想了解mui更详细 ...
- (二十五)键盘的设置与TextField细节处理
设置Return Key类型为Send并且勾选下面的复选框即可实现没有内容时禁用keyboard,有内容自动启用. 文本框左边框与文本留有间距的方法: //文本框左侧留下间距 UIView *left ...
- (九)UIScrollView和PageControl的分页
涉及到内容的滚动与拖拽,使用UIScrllView. 对于滚动的多张图片,由于超出屏幕,应该使用代码添加代码. 添加的细节是:图片的宽高即为滚动视图的宽高,图片的y=0,x=图片的序号乘以图片的宽度. ...
- Cocos2D v2.0至v3.x简洁转换指南(二)
触摸处理 我们在稍后将完成Cocos2d 3.0中触摸处理的完整教程.而现在最重要的是知道如何去启用触摸处理在你的CCNode中: self.userInteractionEnabled = TRUE ...
- Java-Enumeration总结
纸上得来终觉浅,绝知此事要躬行 --陆游 问渠那得清如许,为有源头活水来 --朱熹 Enumeration(枚举)接口的作用和Iterator类似,只提供了遍历Vector和HashTabl ...