2022-03-14

//

//  ViewController.m

//  TRCardListView

//

//  Created by cry on 2017/6/13.

//  Copyright © 2017年 eGova. All rights reserved.

//

#import "ViewController.h"

#import "TRCardListView.h"

#import "MyCard.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    // UITableView

   

    TRCardListView *cardListView = [[TRCardListView alloc] initWithFrame:self.view.bounds];

    cardListView.trDelegate = self;

    cardListView.trDataSource = self;

    [cardListView registerForReuseWithClass:[MyCard class]];

    [self.view addSubview:cardListView];

}

- (NSInteger)tr_numberOfCardsInCardListView:(TRCardListView *)cardListView{

    return 24;

}

- (UIView *)tr_cardListView:(TRCardListView *)cardListView cardAtIndex:(NSInteger)index{

    MyCard *card = (MyCard *)[cardListView dequeueReusableCardAtIndex:index];

    card.label.text = [NSString stringWithFormat:@"第%ld页", index];

    return card;

}

- (void)tr_cardListView:(TRCardListView *)cardListView didSelectCardAtIndex:(NSInteger)index{

    NSLog(@"%ld", index);

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end  //

//  MyCard.h

//  TRCardListView

//

//  Created by cry on 2017/6/13.

//  Copyright © 2017年 eGova. All rights reserved.

//

#import

@interface MyCard : UIView

@property (nonatomic, strong) UILabel *label;//

//  MyCard.m

//  TRCardListView

//

//  Created by cry on 2017/6/13.

//  Copyright © 2017年 eGova. All rights reserved.

//

#import "MyCard.h"

@implementation MyCard

- (instancetype)initWithFrame:(CGRect)frame{

   

    if (self = [super initWithFrame:frame]) {

        self.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];

        self.layer.borderColor = [UIColor whiteColor].CGColor;

        self.layer.borderWidth = 1;

        /**************添加子视图到view上****************/

        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 1, frame.size.width, 63)];

        _label.backgroundColor = [UIColor lightGrayColor];

        _label.textColor = [UIColor whiteColor];

        _label.textAlignment = 1;

        [self addSubview:_label];

    }

    return self;

}

@end

你可能感兴趣的:(2022-03-14)