YTCarouselView 1.0.2

YTCarouselView 1.0.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2018年12月

523793维护。



  • 宋玉涛

YTCarouselView

轮播控制器允许您自由自定义每个旋转视图。

示例:

初始化

YTCarouselView *carouselView = [[YTCarouselView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 180)];
carouselView.delegate = (id<YTCarouselViewDelegate>)self;
[carouselView reloadData];
[self.view addSubview:carouselView];

委托

#pragma - mark - YTCarouselViewDelegate
- (NSUInteger)numberOfLoopImageView:(YTCarouselView *)loopImageView
{
    return 4;
}

- (UIView *)loopImageView:(YTCarouselView *)loopImageView viewForIndex:(NSUInteger)index
{
    int R = (arc4random() % 256) ;
    int G = (arc4random() % 256) ;
    int B = (arc4random() % 256) ;
    
    UIColor *color = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1];
    
    switch (index) {
        case 1:
        {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, loopImageView.bounds.size.width, loopImageView.bounds.size.height)];
            view.backgroundColor = color;
            UIButton *button = [UIButton buttonWithType:0];
            [button setBackgroundColor:[UIColor greenColor]];
            [button setTitle:@"Button" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [button setFrame:CGRectMake((loopImageView.bounds.size.width-60)/2, (loopImageView.bounds.size.height-40)/2, 60, 40)];
            [view addSubview:button];
            return view;
            break;
        }
        case 2:
        {
            NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img07.tooopen.com/images/20170818/tooopen_sy_220999936848.jpg"] options:NSDataReadingUncached error:nil];
            UIImage *image = [UIImage imageWithData:data];
            UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, loopImageView.bounds.size.width, loopImageView.bounds.size.height)];
            view.backgroundColor = color;
            [view setImage:image];
            return view;
            break;
        }
        default:
        {
            UILabel *view = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, loopImageView.bounds.size.width, loopImageView.bounds.size.height)];
            view.backgroundColor = color;
            view.text = [NSString stringWithString:[@(index) stringValue]];
            view.textAlignment = NSTextAlignmentCenter;
            return view;
        }
            
    }
}

- (void)didSelected:(YTCarouselView *)loopImageView forIndex:(NSUInteger)index
{
    NSLog(@"%ld", index);
}

演示

YTCarouselView