实现tableview横向滚动
效果图:
#import "WMTableViewController.h"
#import "WMBookRecommendCell.h"
#define TABLE_WIDTH 320
#define TABLE_HEIGHT 200
@interfaceWMTableViewController ()
@end
@implementation WMTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
returnself;
}
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
[selfinitTb];
}
-(void)initTb
{
mlistView=[[UITableViewalloc]init];
mlistView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
mlistView.frame=CGRectMake(0.0f, 100.0f,TABLE_WIDTH, TABLE_HEIGHT);
mlistView.backgroundColor = [UIColorclearColor];
mlistView.showsHorizontalScrollIndicator = NO;
mlistView.showsVerticalScrollIndicator = NO;
mlistView.delegate = self;
mlistView.dataSource = self;
mlistView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.viewaddSubview:mlistView];
}
#pragma mark-UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
returnTABLE_WIDTH/4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
staticNSString *CellIdentifier = @"CellIdentifier";
WMBookRecommendCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[WMBookRecommendCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
}
return cell;
}
#import "WMBookRecommendCell.h"
@implementation WMBookRecommendCell
@synthesize mguid,dict,titleLabel,bookBtn,bookBg,testBtn;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
[selfinitImageShowView];
}
returnself;
}
-(void)initImageShowView{
bookBtn=[UIButtonbuttonWithType:UIButtonTypeCustom];
bookBtn.frame=CGRectMake(34, 10,50,100);
bookBtn.backgroundColor=[UIColorblueColor];
bookBtn.exclusiveTouch=YES;
[bookBgsetImage:[UIImagep_w_picpathNamed:@"bookshadow_01"]];
[bookBtnaddTarget:selfaction:@selector(bookBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(34,10+100+10, 100, 20)];
titleLabel.backgroundColor=[UIColorclearColor];
titleLabel.text=@"标签";
titleLabel.textColor=[UIColorblackColor];
[self.contentViewaddSubview:bookBtn];
[self.contentViewaddSubview:titleLabel];
[self.contentViewsetExclusiveTouch:YES];
}
- (void)bookBtnClicked:(id)sender {
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[supersetSelected:selected animated:animated];
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
转载于:https://blog.51cto.com/ios2013yoyo/1269514