OC 如何设置UITableViewCell之间的间距
来源:互联网 发布:图灵奖难度 知乎 编辑:程序博客网 时间:2024/03/28 19:44
1.重新设置的UITableViewCellframe
<span style="font-size:18px;">#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]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end</span>
2.用控件tableview,比如有十条数据,那就给tableview分十组,每组只放一条数据,也就是一个cell,然后设置UICollectionViewCell的head view和foot view来设置cell的间距,但是这个方法只能设置上下间距,如果想设置距离屏幕左右的距离,可以设置uitableview距离左右的距离;uitableview的style为UITableViewStyleGrouped;不然headview会浮动;
<span style="font-size:18px;">- (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; }</span>
3.用UIContentView来代替tableview,然后通过下面这个函数来设置UICollectionViewCell的上下左右的间距
//协议中的方法,用于返回单元格的大小 - (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); }
4.设置假的间距,我们在tableviewcell的contentView上添加一个view,比如让其距离上下左右的距离都是10;这个方法是最容易想到的;
阅读全文
0 0
- OC 如何设置UITableViewCell之间的间距
- iOS-OC-设置UITableViewCell之间的间距
- iOS-OC-设置UITableViewCell之间的间距
- iOS-OC-设置UITableViewCell之间的间距(推荐第四种)
- 设置自定义UITableViewCell之间的间距
- 设置自定义UITableViewCell之间的间距
- 设置自定义UITableViewCell之间的间距
- 计算UITableViewCell之间的间距
- 计算UITableViewCell之间的间距(完美版)
- OC_实现UITableviewCell之间的间距
- ExtJs中table布局如何设置items之间的间距
- 设置tableViewCell之间的间距
- ASP.NET 2005 C#如何在TreeView中设置节点之间的间距,节点上下间距?
- beamer 中设置 item 之间的间距
- 设置RecyclerView项目之间的间距
- javaSwing 设置每个组件之间的间距
- 设置RecyclerView项目之间的间距
- 设置UITableView section之间的间距
- Vue留言板(用了bootstrap简洁大气)
- oom
- 动态规划经典问题
- 纯 java 实现 Http 资源读取工具,支持发送和接收数据,不依赖任何第三方 jar 包
- 实现GPS一辆或多辆小车在百度地图上显示驾驶路线
- OC 如何设置UITableViewCell之间的间距
- 访问者模式
- 聊聊成为大神路上的过程
- Linux 磁盘命令
- 入职10个月有感
- Codeforce A
- RESTClient插件
- 联合索引
- RSA加密解密