横向的TableVIew

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010069091/article/details/49154079
  1. @interface FirstViewController ()  
  2.   
  3. @end  
  4.   
  5. static NSString *MyCellID = @"thisIsMyCellId";  
  6.   
  7. @implementation FirstViewController  
  8.   
  9. - (void)viewDidLoad {  
  10.     [super viewDidLoad];  
  11.     // Do any additional setup after loading the view.  
  12.     self.view.backgroundColor = [UIColor whiteColor];  
  13.       
  14.     self.tableDataArray = @[[UIColor redColor], [UIColor yellowColor], [UIColor blueColor]];  
  15.       
  16.     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;  
  17.     self.tableView.scrollsToTop = NO;  
  18.     self.tableView.transform = CGAffineTransformMakeRotation(-M_PI_2);  
  19.     self.tableView.showsVerticalScrollIndicator = NO;  
  20.     self.tableView.pagingEnabled = YES;  
  21.     self.tableView.bounces = NO;  
  22.     [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MyCellID];  
  23.       
  24. }  
  25.   
  26. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
  27. {  
  28.     return self.tableDataArray.count;  
  29. }  
  30.   
  31. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
  32. {  
  33.     return tableView.frame.size.width;  
  34. }  
  35.   
  36. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  37. {  
  38.     UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyCellID forIndexPath:indexPath];  
  39.     cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2);  
  40.     cell.selectionStyle = UITableViewCellSelectionStyleNone;  
  41.       
  42.     UIColor *color = [self.tableDataArray objectAtIndex: indexPath.row];  
  43.     [cell.contentView setBackgroundColor: color];  
  44.     return cell;  
  45. }  
  46.   
  47. - (void)didReceiveMemoryWarning {  
  48.     [super didReceiveMemoryWarning];  
  49.     // Dispose of any resources that can be recreated.  
  50. }  
  51.   
  52. @end













#define COLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]


#import "TableViewController.h"


@interface TableViewController ()


@property NSMutableArray *tableDataArray;

@end




static NSString *MyCellID =@"thisIsMyCellId";


@implementation TableViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColorwhiteColor];

    


    self.tableDataArray = [NSMutableArrayarray];

    

    for (int i =0; i< 20; i++) {

        

        int  r  = arc4random()%255 ;

        int  g  = arc4random()%255 ;

        int  b  = arc4random()%255 ;


        [self.tableDataArray addObject: COLOR(r, g, b)];

        

    }

 

      //tableview逆时针旋转90度。

     self.tableView.transform = CGAffineTransformMakeRotation(-M_PI /2);

     // scrollbar 不显示

     self.tableView.showsVerticalScrollIndicator =NO;

    

}


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

{

    returnself.tableDataArray.count;

}




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

{

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"identifier"];


    if (cell == nil) {

         cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:@"identifier"];

        // cell顺时针旋转90

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

    }

    

    UIColor *color = [self.tableDataArrayobjectAtIndex: indexPath.row];

    [cell.contentView setBackgroundColor: color];

    return cell;

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



猜你喜欢

转载自blog.csdn.net/u010069091/article/details/49154079