iOS 竖向tableView上添加横向tableView
2013-07-09 14:03
323 查看
要点一:使用CGAffineTransform来270度旋转UITableView
要点二: 创建一个UITableViewCell的子类,在该类中将横向tableView添加到cell中
具体实现见代码:
效果如下图:
Cell.h文件
#import <UIKit/UIKit.h>
@interface Cell : UITableViewCell<UITableViewDataSource,UITableViewDelegate>
{
CGAffineTransform transform;
}
@end
Cell.m文件
#import "Cell.h"
@implementation Cell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UITableView * tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 60, 320) style:UITableViewStylePlain];
tableview.dataSource=self;
tableview.delegate=self;
transform=CGAffineTransformMakeRotation(M_PI/2*3);
tableview.transform=transform;
tableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
tableview.center=CGPointMake(160, 30);
tableview.backgroundColor=[UIColor lightGrayColor];
[self addSubview:tableview];
}
return self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 12;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
//-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
//{
// CGAffineTransform tran=CGAffineTransformMakeRotation(M_PI/2);
//
// cell.transform=tran;
//}
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identifier=@"cell";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
label.text=@"11111";
CGAffineTransform tran=CGAffineTransformMakeRotation(M_PI/2);
cell.transform=tran;
label.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:label];
[label release];
}
return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
ViewController.h文件
#import <UIKit/UIKit.h>
#import "Cell.h"
@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
@end
ViewController.m文件
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UITableView * table1=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
table1.delegate=self;
table1.dataSource=self;
[self.view addSubview:table1];
[table1 release];
// Do any additional setup after loading the view.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0f;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identifier=@"cell";
Cell * cell1=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell1==nil) {
cell1=[[Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
要点二: 创建一个UITableViewCell的子类,在该类中将横向tableView添加到cell中
具体实现见代码:
效果如下图:
Cell.h文件
#import <UIKit/UIKit.h>
@interface Cell : UITableViewCell<UITableViewDataSource,UITableViewDelegate>
{
CGAffineTransform transform;
}
@end
Cell.m文件
#import "Cell.h"
@implementation Cell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UITableView * tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 60, 320) style:UITableViewStylePlain];
tableview.dataSource=self;
tableview.delegate=self;
transform=CGAffineTransformMakeRotation(M_PI/2*3);
tableview.transform=transform;
tableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
tableview.center=CGPointMake(160, 30);
tableview.backgroundColor=[UIColor lightGrayColor];
[self addSubview:tableview];
}
return self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 12;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
//-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
//{
// CGAffineTransform tran=CGAffineTransformMakeRotation(M_PI/2);
//
// cell.transform=tran;
//}
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identifier=@"cell";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UILabel * label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
label.text=@"11111";
CGAffineTransform tran=CGAffineTransformMakeRotation(M_PI/2);
cell.transform=tran;
label.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:label];
[label release];
}
return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
ViewController.h文件
#import <UIKit/UIKit.h>
#import "Cell.h"
@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
@end
ViewController.m文件
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UITableView * table1=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
table1.delegate=self;
table1.dataSource=self;
[self.view addSubview:table1];
[table1 release];
// Do any additional setup after loading the view.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0f;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identifier=@"cell";
Cell * cell1=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell1==nil) {
cell1=[[Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- IOS tableview 横向滚动
- ios 如何让TableView加入横向滑动出现删除按钮的功能
- iOS -view横向变成竖向
- ios tableView那些事 (七) 给tableView添加响应事件
- ios知识点总结——UITableView的展开与收缩及横向Table
- 【iOS开发学习】关于在TableView里添加搜索的问题。
- 【iOS开发】添加系统自带的tableView左滑按钮
- iOS开发之在scrollview上添加点击并解决其子控件的点击无响应(如tableView)
- iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)
- ios tableview cell上面的view添加手势,两个手指同时点击cell上的view的冲突(手势冲突)
- iOS中为tableView的section添加弧形
- iOS UITableView(九) 给tableView添加索引
- iOS tableView删除,添加,排序方法实现
- IOS给tableview的cell添加长按手势执行两次(UILongPressGestureRecognizer)
- iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的问题
- iOS之tableView横向滚动
- ios tableView那些事 (七) 给tableView添加响应事件
- iOS 给整个tableview外框添加阴影
- ios tableView那些事 (七) 给tableView添加响应事件
- iOS 为自定义tableView添加button点击事件后获取其序号