UITableView的横向使用

  UITableView只支持竖向显示,要实现横向的显示,需要设置tableView 和cell 的transform属性为CGAffineTransformMakeRotate(-M_PI/2)   

// 42.5是TableView的高度,320是UITableView的宽度 _tabTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 66, 42.5, 320)]; _tabTableView.dataSource = self; _tabTableView.delegate = self; _tabTableView.showsVerticalScrollIndicator = NO; _tabTableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 设置TableView显示的位置 _tabTableView.center = CGPointMake(320 / 2, 66); _tabTableView.transform = CGAffineTransformMakeRotation(-M_PI_2); [self.view addSubview:_tabTableView];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        TabTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tab"];
        if (cell == nil) {
            cell = [[TabTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tab"];
        }
        [cell setTitle:_tabArrays[indexPath.row]];
     //这里也要设置一下 cell.transform
= CGAffineTransformMakeRotation(M_PI_2); return cell; }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        return 65;//设置横向cell的高度
}

原文地址:https://www.cnblogs.com/hw140430/p/4355845.html