`
helmsman_xcode
  • 浏览: 25891 次
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

用UITableViewCell实现电子书平铺书架效果

阅读更多
原创文章,如需转载请注明:转载自:舵手程序 http://www.helmsmansoft.com/index.php/archives/70

现阶段网上讲解的实现这种效果的文章一般都是用UIVIew 去加载UIButton实现此功能,今天给大家说一下在UITableViewCell下怎样去实现这种效果

UITableViewCell默认是列表形态,默认状态下允许加载一张图片,如果想实现在UITableViewCell中显示多行图片,可以自定义UIView,把UIView加载到Cell上即可实现这种效果。这里主要说一下怎么去写Cell里的功能,其它功能不具体解释了。

具体见代码:
在theTableViewController.h中定义UIButton *buttonArray;
在theTableViewController.m文件内定义Cell中显示的图书本数

#define theNumberOfTatleTile 3 //每行显示3本
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //每行3本,返回的行数
{
if([self.listFileName count]%theNumberOfTatleTile == 0){ //listFileName 图书名字数组
return [self.listFileName count]/theNumberOfTatleTile;
}else{
return [self.listFileName count]/theNumberOfTatleTile+1;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *theKey = @"theKey";
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; //注意此处
{

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:theKey] autorelease];

UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
customLabel.backgroundColor = [UIColor redColor];
buttonArray = [[NSMutableArray alloc] init];
NSUInteger row = [indexPath row];
for(int i = 0 ; i < [self.listFileName count]/theNumberOfTatleTile;i++){
NSNumber *cellRow = [[NSNumber alloc] initWithInt:theNumberOfTatleTile];
[buttonArray addObject:cellRow];
}
for(int j = 0 ; j < [self.listFileName count]%theNumberOfTatleTile; j++){
NSString *str = [NSString stringWithFormat:@"%d",[self.listFileName count]%theNumberOfTatleTile];
[buttonArray addObject:str];
}

cell.imageView.image = NULL;
cell.textLabel.text = NULL;
cell.detailTextLabel.text = NULL;
NSString *a = [buttonArray objectAtIndex:row];
NSInteger b= [a integerValue];

for(int m = 0 ; m < b; m++){

button = [[UIButton alloc] initWithFrame:CGRectMake(70+m%theNumberOfTatleTile*240, 20, 150, 200)];
UILabel *label= [[UILabel alloc] initWithFrame:CGRectMake(0, 170, 150, 30)];
[button setBackgroundImage:[UIImage imageNamed:@"apple.png"] forState:UIControlStateNormal];
label.backgroundColor = [UIColor clearColor];
label.text = [listFileName objectAtIndex:theNumberOfTatleTile*row+m];
[button addSubview:label];

button.backgroundColor = [UIColor whiteColor];
button.reversesTitleShadowWhenHighlighted = YES;
[button setTag:theNumberOfTatleTile*row+m];
[button addTarget:self action:@selector(thePicButtonPress:) forControlEvents:UIControlEventTouchUpInside];
// button.userInteractionEnabled = YES;
// [button setTitleShadowColor:[UIColor clearColor] forState:UIControlEventTouchUpInside];
// [button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
//
[cell addSubview:button];
[button release];

}
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
cell.backgroundView = imgView;
cell.selectionStyle = UITableViewCellEditingStyleNone; //选中CELL后效果
return cell;

}
}

如果你喜欢本文,请去站点支持一下。分享给大家 舵手程序--http://www.helmsmansoft.com

转载本站文章请注明出处,转载自:舵手程序--http://www.helmsmansoft.com

本文链接地址: http://www.helmsmansoft.com/index.php/archives/70
0
0
分享到:
评论

相关推荐

    swift-UITableViewCell动画效果

    在本主题“swift-UITableViewCell动画效果”中,我们将深入探讨如何利用Swift和相关库来实现各种动画效果,提升用户体验。 首先,了解`UITableViewCell`的基本用法至关重要。它代表了UITableView中的每一行,并可以...

    使用xib 自定义uitableviewcell 实现了代理协议

    本教程将通过使用XIB(Interface Builder)来创建自定义的UITableViewCell,并实现UITableViewDataSource和UITableViewDelegate协议,以适应iOS 9.1及更高版本的应用。以下是对这个过程的详细讲解: 首先,我们需要...

    代码实现 UITableView与UITableViewCell

    这个标题“代码实现UITableView与UITableViewCell”指的是如何通过编程方式设置和管理UITableView及其单元格(UITableViewCell)。在描述中提到了一个链接,指向了CSDN博客上的一篇文章,该文章可能提供了更详细的...

    ios-UITableViewCell折叠效果.zip

    本项目“ios-UITableViewCell折叠效果.zip”主要关注如何实现UITableView中UITableViewCell的动态高度调整以及折叠拉伸效果,这是一项增强用户体验的重要技巧。下面我们将深入探讨这个主题。 首先,我们来理解`...

    自定义UITableViewCell。实现各种样式的表格输入界面ios源代码设计资料

    然而,这些样式可能无法满足所有应用的视觉和功能需求,因此我们需要自定义`UITableViewCell`来实现更复杂的效果。 自定义`UITableViewCell`主要包括以下几个方面: 1. **设计UI**:使用Interface Builder或代码...

    IOS代码笔记之仿电子书书架效果

    为了实现这种效果,我们将使用UITableView作为基础控件,并自定义UITableViewCell来展示每一本书的样子。 在给定的代码片段中,我们看到`RootViewController`是整个视图控制器,它遵循了UITableViewDataSource和...

    在UITableView中自定义UITableViewcell实现ibooks图书列表样式

    本篇将详细介绍如何在UITableView中自定义UITableViewCell来实现类似iBooks的图书列表样式。 首先,我们需要创建一个新的UITableViewCell子类。在Xcode中,可以通过File &gt; New &gt; File...,然后选择Cocoa Touch ...

    swift-DWURecyclingAlert-优化UITableViewCell实现快速滚动

    "swift-DWURecyclingAlert-优化UITableViewCell实现快速滚动"项目正是针对这一问题提供的一种解决方案。 首先,我们来理解一下UITableViewCell的回收机制。UITableView为了高效利用内存,采用了cell复用策略。当一...

    iOS、UITableViewCell、自定义

    但为了实现统一的视觉效果,我们通常需要设置所有Cell为等高。以下是三种常见的实现方法: 1. 使用 Estimated Row Height:在UITableView的estimatedRowHeight属性中设置一个预估高度,系统会尝试让所有Cell接近这...

    IOS源码——自定义UITableViewCell。实现各种样式的表格输入界面.7z

    4. Interface Builder集成:虽然源码可能包含代码实现,但iOS开发者也可以使用Interface Builder来设计和连接UITableViewCell的界面元素。通过XIB或Storyboard文件,可以直观地创建并布局单元格,然后在代码中加载...

    ios-布局实现动态UITableviewCell的高度调整以及动画效果.zip

    UITableViewCell的动态高度计算一直是一个交流讨论的话题,也已经有了很多实现的机制,但更多的是需要一些扩展类什么的,还有需要计算什么的,使用起来比较麻烦。因此这里推荐一种自动计算高度的方法,他是在我的...

    ios源码之超炫的电子书书架管理工具应用.rar

    5. **定制Cell和View**:为了达到“超炫”的效果,开发者可能使用了自定义UITableViewCell和UICollectionViewCell,添加动画效果、阴影、渐变色等视觉增强元素,提升用户体验。 6. **Image处理**:可能涉及到...

    UITableViewCell的四种不同的定制单元格方式

    如果不希望使用Interface Builder,可以完全用代码来创建和定制UITableViewCell。首先,创建一个新的Swift或Objective-C类,继承自UITableViewCell,并在其中初始化和布局UI元素。在`awakeFromNib`方法中设置默认...

    IOS源码应用Demo-UITableViewCell 视图扩展.zip

    这个" IOS源码应用Demo-UITableViewCell 视图扩展.zip "很可能是为了帮助开发者深入理解如何自定义UITableViewCell,以便实现更丰富的用户界面和交互效果。在毕业设计或论文中,这样的实践示例能帮助学生更好地阐述...

    IOS源码——自定义UITableViewCell。实现各种样式的表格输入界面.zip

    实现各种样式的表格输入界面.zip"显然包含了一个示例项目,教你如何自定义UITableViewCell来创建多样化的表格输入界面。在iOS开发中,自定义UITableViewCell能够帮助我们实现独特的用户界面,增强用户体验,并且可以...

    动态计算UITableViewCell高度详解

    实现动态计算UITableViewCell高度主要涉及以下几个步骤: 1. **启用自动布局(Auto Layout)**:在iOS开发中,我们通常使用Auto Layout来定义视图的约束,以便根据内容自动调整大小。在UITableViewCell中,确保所有...

    swift-UITableViewCell内各种滑动变化及动画效果

    总之,Swift中的`UITableViewCell`滑动变化和动画效果可以通过`SwipeCellKit`库轻松实现。这个库不仅提供了丰富的预设选项,还允许高度的自定义,确保你可以根据项目需求构建出独特且流畅的滑动体验。通过学习和实践...

    UITableViewCell的reuse(修正)

    要实现UITableViewCell的重用,我们需要遵循以下步骤: 1. **注册单元格类或 nib**:在初始化UITableView时,应先注册要使用的单元格类或XIB文件。这可以通过`registerClass: forCellReuseIdentifier:`或`...

Global site tag (gtag.js) - Google Analytics