天天看點

ios 橫向滾輪效果_iOS之tableView橫向滾動 | 學步園

- (void)viewDidLoad

{

[super viewDidLoad];

CGRect tableViewRect = CGRectMake(0.0, 0.0, 100.0, 320.0);

self.tableView = [[UITableView alloc] initWithFrame:tableViewRect style:UITableViewStylePlain];

_tableView.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2);

_tableView.delegate = self;

_tableView.dataSource = self;

//tableview逆時針旋轉90度。

_tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2);

// scrollbar 不顯示

_tableView.showsVerticalScrollIndicator = NO;

[self.view addSubview:_tableView];

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return  50;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString * str = @"hello";

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];

if (cell==nil) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];

cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);

}

cell.textLabel.text = @"hello";

return cell;

}

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 100;

}