1.设置假的间距,我们在tableviewcell的contentView上添加一个view,比如让其距离上下左右的距离都是10;这个方法是最容易想到的;

2.用UIContentView来代替tableview,然后通过下面这个函数来设置UICollectionViewCell的上下左右的间距;

<span style="font-size:18px;">//协议中的方法,用于返回单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(ScreenWidth-20,150);
}
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
//上、左、下、右的边距
return UIEdgeInsetsMake(10, 10, 10, 10);
}</span>

3.用控件tableview,比如有十条数据,那就给tableview分十组,每组只放一条数据,也就是一个cell,然后设置UICollectionViewCell的head view和foot view来设置cell的间距,但是这个方法只能设置上下间距,如果想设置距离屏幕左右的距离,可以设置uitableview距离左右的距离;uitableview的style为UITableViewStyleGrouped;不然headview会浮动;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 10;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.00001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headView = [[UIView alloc]init];
headView.backgroundColor = [UIColor redColor];
return headView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableSampleIdentifier = @"cellStr";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:TableSampleIdentifier];
}
return cell;
}

4.重新设置的UITableViewCellframe。

代码如下:

#import "MyViewCell.h"

@implementation MyViewCell

- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}

- (void)setFrame:(CGRect)frame{
frame.origin.x += 10;
frame.origin.y += 10;
frame.size.height -= 10;
frame.size.width -= 20;
[super setFrame:frame];
}

@end

ios 设置cell的间距的更多相关文章

  1. iOS设置cell选中时文字颜色的变化

    cell.titleStr.highlightedTextColor = EMCGreenColor;

  2. iOS设置tableViewCell之间的间距(去掉UItableview headerview黏性)

    经常在项目中遇到自定义cell的情况,而且要求cell之间有间距,但是系统没有提供改变cell间距的方法,怎么办? 方法1:自定义cell的时候加一个背景View,使其距离contentView的上下 ...

  3. IOS中设置cell的背景view和选中时的背景view 、设置cell最右边的指示器(比如箭头\文本标签)

    一.Cell的设置 1.设置cell的背景view和选中时的背景view UIImageView *bg = [[UIImageView alloc] init]; bg.image = [UIIma ...

  4. UITableView设置cell为不可选?

    本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术.本文将为读者讲解UITableView如何设置单 ...

  5. collectionView代理方法快速设置cell大小上下左右间隔

    #define JianGe 25 #define GeShu 4 #define ScreenWidth ([UIScreen mainScreen].bounds.size.width) #def ...

  6. iOS 在cell中使用倒计时的处理方法(新)

    一.前言 之前的文章iOS 在cell中使用倒计时的处理方法得到大量的支持, 在这先感谢大家的支持. 但是也收到不少人的回复表示不会用, 需要一一解答, 由于之前写的时候没有使用Markdown编辑, ...

  7. iOS 设置页面的代码编写

    突然觉得好久没有更新博客了,今天就想把自己的项目中的一些功能和常用的模块写出来给大家参考一下... 这是我的二个项目中的不同的设置界面,第一个设置的那个按钮是 用的开关switch ,当然这个就容易一 ...

  8. iOS设置app应用程序文件共享

    1.iOSapp应用程序文件共享 当我们用itnues连接到设备时,在应用程序栏目下面,文件共享下,点击 对应的程序,即可以在程序右边栏目里面看到应用程序共享的数据, 此时,我们可以通过右下角的 添加 ...

  9. IOS 设置定时器

    IOS 设置定时器  自动滚动视图 定时发送坐标信息 即时显示 时钟 NSTimer *timer; - (void)start {//1second 调用一次 timer = [NSTimer sc ...

随机推荐

  1. arm裸机程序启动流程

    arm裸机程序启动流程 1373 Linux系统的引导: 一个SOC拿过来,它是有内部BROM和SRAM的,这个BROM中会固化芯片厂商的最初引导代码,我们叫它RBL(ROM boot loader) ...

  2. Unix Timestamp

    class Foundation_API DateTime /// This class represents an instant in time, expressed /// in years, ...

  3. Java集合框架(1)

    Collection接口:它是Java集合框架的一个根接口,也是List.Set和Queue接口的父接口.同时它定义了可用于操作List.Set和Queue的方法—增删改查. Map接口:它提供了一种 ...

  4. Divide Two Integers-不用'/' '*' '%'操作实现整数的除法

    题目描述: 不用 '*' '/' 和 '%' 运算实现两个整数的除法 题目来源:http://oj.leetcode.com/problems/divide-two-integers/ 题目分析: 例 ...

  5. caffe template

    http://www.cnblogs.com/ggjucheng/archive/2011/12/18/2292090.html

  6. SQL 排序规则 CodeProject

    http://www.cnblogs.com/ifreesoft/p/4259626.html 开发ERP数据维护工具之一 修改SQL Server数据库排序规则 Change Collation   ...

  7. R 中数据导入

    R语言数据导入  数据导入 1.保存和加载R的数据(与R.data的交互:save()函数和load()函数) a <- 1:10 save(a, file = "data/dumDa ...

  8. ZOJ 3512 Financial Fraud (左偏树)

    题意:给定一个序列,求另一个不递减序列,使得Abs(bi - ai) 和最小. 析:首先是在每个相同的区间中,中位数是最优的,然后由于要合并,和维护中位数,所以我们选用左偏树来维护,当然也可以用划分树 ...

  9. HDU - 3899 JLUCPC(树形dp求距离和)

    JLUCPC Dr. Skywind and Dr. Walkoncloud are planning to hold the annual JLU Collegiate Programming Co ...

  10. 51nod1110(xjb)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1110 题意:中文题诶- 思路:可以将在 xi 位置,权值为 w ...